WIP page rendering in stacks
arnaud sellenet
committed Jun 16, 2014
commit 50411af56fda6f30712b59b4c4f0e2ca7a2f9a09
Showing 4
changed files with
50 additions
and 24 deletions
locomotive/steam/liquid/drops/base.rb b/lib/locomotive/steam/liquid/drops/base.rb
+1
-1
| @@ | @@ -43,4 +43,4 @@ module Locomotive |
| end | |
| end | |
| end | |
| - | end |
| \ No newline at end of file | |
| + | end |
locomotive/steam/middlewares/page.rb b/lib/locomotive/steam/middlewares/page.rb
+14
-10
| @@ | @@ -9,7 +9,7 @@ module Locomotive::Steam |
| def _call(env) | |
| super | |
| - | self.set_page!(env) |
| + | set_page!(env) |
| app.call(env) | |
| end | |
| @@ | @@ -17,24 +17,28 @@ module Locomotive::Steam |
| protected | |
| def set_page!(env) | |
| - | page = self.fetch_page env['steam.locale'] |
| + | page = fetch_page env['steam.locale'] |
| if page | |
| - | self.log "Found page \"#{page.title}\" [#{page.fullpath}]" |
| + | log "Found page \"#{page.title}\" [#{page.fullpath}]" |
| end | |
| env['steam.page'] = page | |
| end | |
| def fetch_page locale | |
| - | matchers = self.path_combinations(self.path) |
| - | Locomotive::Models[:pages].current_locale = locale |
| - | pages = Locomotive::Models[:pages].matching_paths(matchers) |
| - | |
| - | if pages.size > 1 |
| - | self.log "Found multiple pages: #{pages.collect(&:title).join(', ')}" |
| + | decorated(locale) do |
| + | Locomotive::Models[:pages].current_locale = locale |
| + | Locomotive::Models[:pages].matching_paths(path_combinations(path)).tap do |pages| |
| + | if pages.size > 1 |
| + | self.log "Found multiple pages: #{pages.all.collect(&:title).join(', ')}" |
| + | end |
| + | end.first |
| end | |
| + | end |
| - | pages.first |
| + | def decorated(locale) |
| + | entity = yield |
| + | Locomotive::Decorators::I18nDecorator.new(entity, locale) unless entity.nil? |
| end | |
| def path_combinations(path) | |
locomotive/steam/middlewares/renderer.rb b/lib/locomotive/steam/middlewares/renderer.rb
+14
-13
| @@ | @@ -6,19 +6,19 @@ module Locomotive::Steam |
| def _call(env) | |
| super | |
| - | if self.page |
| - | if self.page.redirect? |
| - | self.redirect_to(self.page.redirect_url, self.page.redirect_type) |
| + | if page |
| + | if page.redirect? |
| + | redirect_to(page.redirect_url, page.redirect_type) |
| else | |
| - | type = self.page.response_type || 'text/html' |
| - | html = self.render_page |
| + | type = page.response_type || 'text/html' |
| + | html = render_page |
| - | self.log 'Rendered liquid page template' |
| + | log 'Rendered liquid page template' |
| [200, { 'Content-Type' => type }, [html]] | |
| end | |
| else | |
| - | [404, { 'Content-Type' => 'text/html' }, [self.render_404]] |
| + | [404, { 'Content-Type' => 'text/html' }, [render_404]] |
| end | |
| end | |
| @@ | @@ -26,13 +26,13 @@ module Locomotive::Steam |
| def render_page | |
| context = self.locomotive_context | |
| - | begin |
| - | |
| + | # begin |
| + | # binding.pry |
| render(page, context) | |
| - | rescue Exception => e |
| + | # rescue Exception => e |
| - | raise RendererException.new(e, self.page.title, self.page.template, context) |
| - | end |
| + | # raise RendererException.new(e, self.page.title, self.page.template, context) |
| + | # end |
| end | |
| def render(page, context) | |
| @@ | @@ -50,7 +50,8 @@ module Locomotive::Steam |
| } | |
| begin | |
| - | ::Liquid::Template.parse(page.source, options) |
| + | binding.pry |
| + | ::Liquid::Template.parse(page.source(I18n.locale), options) |
| rescue ::Liquid::SyntaxError | |
| # do it again on the raw source instead so that the error line matches | |
| # the source file. | |
spec/unit/loaders/site_loader_spec.rb
+21
-0
| @@ | @@ -0,0 +1,21 @@ |
| + | require 'spec_helper' |
| + | |
| + | describe Locomotive::Steam::Loader::Yml::SiteLoader, focused: true do |
| + | |
| + | let(:path) { default_fixture_site_path } |
| + | let(:loader) { Locomotive::Steam::Loader::Yml::SiteLoader.new path, mapper } |
| + | |
| + | before { loader.load! } |
| + | |
| + | subject { Locomotive::Models[:sites].all.first } |
| + | |
| + | it { should be_kind_of Locomotive::Steam::Entities::Site } |
| + | its(:name) { should eql 'Sample website' } |
| + | its(:domains) { should eql ['example.org', 'sample.example.com', '0.0.0.0'] } |
| + | context 'localized fields' do |
| + | it do |
| + | subject.seo_title[:en].should eq 'A simple LocomotiveCMS website' |
| + | subject.seo_title[:fr].should eq 'Un simple LocomotiveCMS site web' |
| + | end |
| + | end |
| + | end |