decorate the page when used inside the nav liquid tag + use the all method of the page repository when returning multiple pages (in order to use the default page order)
did
committed Feb 16, 2015
commit 52025f9c3f20fca8f9029b985cd89c0f2b7637ce
Showing 10
changed files with
100 additions
and 66 deletions
locomotive/steam/liquid/tags/nav.rb b/lib/locomotive/steam/liquid/tags/nav.rb
+9
-1
| @@ | @@ -16,7 +16,7 @@ module Locomotive |
| Syntax = /(#{::Liquid::VariableSignature}+)/o | |
| - | attr_accessor :current_page, :services, :page_repository |
| + | attr_accessor :current_site, :current_page, :current_locale, :services, :page_repository |
| def initialize(tag_name, markup, options) | |
| markup =~ Syntax | |
| @@ | @@ -179,6 +179,7 @@ module Locomotive |
| # @return [ String ] The HTML output | |
| # | |
| def render_entry_link(page, css, depth) | |
| + | page = decorate_page(page) |
| url = self.entry_url(page) | |
| label = self.entry_label(page) | |
| css = self.entry_css(page, css) | |
| @@ | @@ -238,8 +239,10 @@ module Locomotive |
| # Avoid to call context.registers to get the current page. | |
| # | |
| def set_vars_from_context(context) | |
| + | self.current_site = context.registers[:site] |
| self.current_page = context.registers[:page] | |
| self.services = context.registers[:services] | |
| + | self.current_locale = context.registers[:locale] |
| self.page_repository = self.services.repositories.page | |
| end | |
| @@ | @@ -273,6 +276,11 @@ module Locomotive |
| %{<#{tag_name}#{options.join(' ')}>#{yield}</#{tag_name}>} | |
| end | |
| + | def decorate_page(page) |
| + | klass = Locomotive::Steam::Decorators::I18nDecorator |
| + | klass.new(page, page.localized_attributes, current_locale, current_site.default_locale) |
| + | end |
| + | |
| def bootstrap? | |
| @_options[:bootstrap].to_bool | |
| end | |
locomotive/steam/repositories/filesystem/models/page.rb b/lib/locomotive/steam/repositories/filesystem/models/page.rb
+4
-4
| @@ | @@ -13,11 +13,11 @@ module Locomotive |
| def initialize(attributes) | |
| super({ | |
| handle: nil, | |
| - | listed: true, |
| - | published: false, |
| + | listed: false, |
| + | published: true, |
| fullpath: {}, | |
| content_type: nil, | |
| - | position: 100, |
| + | position: 99, |
| template: {}, | |
| editable_elements: {} | |
| }.merge(attributes)) | |
| @@ | @@ -31,7 +31,7 @@ module Locomotive |
| end | |
| def depth_and_position | |
| - | depth * 200 + position |
| + | depth * 100 + position |
| end | |
| def index? | |
locomotive/steam/repositories/filesystem/page.rb b/lib/locomotive/steam/repositories/filesystem/page.rb
+3
-3
| @@ | @@ -25,7 +25,7 @@ module Locomotive |
| end | |
| def matching_fullpath(list) | |
| - | query { where('fullpath.in' => list) }.all |
| + | all('fullpath.in' => list) |
| end | |
| # Engine: ??? | |
| @@ | @@ -63,7 +63,7 @@ module Locomotive |
| segments = localized_attribute(page, :fullpath).split('/') | |
| paths = 0.upto(segments.size - 1).map { |i| segments[0..i].join('/') } | |
| - | query { where('fullpath.in' => ['index'] + paths) }.all |
| + | all('fullpath.in' => ['index'] + paths) |
| end | |
| # Engine: page.children | |
| @@ | @@ -76,7 +76,7 @@ module Locomotive |
| conditions[:fullpath] = /^#{localized_attribute(page, :fullpath)}\// | |
| end | |
| - | query { where(conditions) }.all |
| + | all(conditions) |
| end | |
| # Engine: page.editable_elements | |
spec/fixtures/default/app/views/pages/about_us.liquid.haml
+2
-1
| @@ | @@ -3,6 +3,7 @@ title: About Us |
| listed: true | |
| position: 1 | |
| handle: about-us | |
| + | published: true |
| editable_elements: | |
| 'banner/page_image': "/samples/photo_2.jpg" | |
| 'banner/pitch': "<h2>About us</h2><p>Lorem ipsum...</p>" | |
| @@ | @@ -18,4 +19,4 @@ editable_elements: |
| {% endeditable_long_text %} | |
| - | {% endblock %} |
| \ No newline at end of file | |
| + | {% endblock %} |
spec/fixtures/default/app/views/pages/filtered.liquid.haml
+1
-1
| @@ | @@ -7,4 +7,4 @@ title: Various uses of the with_scope tag |
| {% with_scope date.gte: begin, date.lte: end, city: /Kansas/, state.ne: 'Illinois', tags: 'awesome', tags.nin: 'bad', price.in: prices %} | |
| events={{ contents.events.count }}. | |
| - | {% endwith_scope %} |
| \ No newline at end of file | |
| + | {% endwith_scope %} |
spec/integration/server/assets_spec.rb
+26
-12
| @@ | @@ -8,21 +8,35 @@ describe Locomotive::Steam::Server do |
| run_server | |
| end | |
| - | it 'renders an image' do |
| - | get '/images/nav_on.png' |
| - | expect(last_response.status).to eq(200) |
| - | end |
| + | describe 'Static assets' do |
| + | |
| + | it 'renders an image' do |
| + | get '/images/nav_on.png' |
| + | expect(last_response.status).to eq(200) |
| + | end |
| - | it 'renders a stylesheet' do |
| - | get '/stylesheets/application.css' |
| - | expect(last_response.status).to eq(200) |
| - | expect(last_response.body).to match('body{background:#f0eee3') |
| end | |
| - | it 'renders a SCSS asset' do |
| - | get '/stylesheets/other/style.css' |
| - | expect(last_response.status).to eq(200) |
| - | expect(last_response.body).to match('body{background:red}') |
| + | describe 'Dynamic assets (SCSS + Coffeescript)' do |
| + | |
| + | it 'renders a stylesheet' do |
| + | get '/stylesheets/application.css' |
| + | expect(last_response.status).to eq(200) |
| + | expect(last_response.body).to include('body{background:#f0eee3') |
| + | end |
| + | |
| + | it 'renders a SCSS asset' do |
| + | get '/stylesheets/other/style.css' |
| + | expect(last_response.status).to eq(200) |
| + | expect(last_response.body).to include('body{background:red}') |
| + | end |
| + | |
| + | it 'renders a Coffeescript asset' do |
| + | get '/javascripts/application.js' |
| + | expect(last_response.status).to eq(200) |
| + | expect(last_response.body).to include('alert("hello world")') |
| + | end |
| + | |
| end | |
| end | |
spec/integration/server/basic_spec.rb
+0
-34
| @@ | @@ -90,40 +90,6 @@ describe Locomotive::Steam::Server do |
| # last_response.body.should =~ /<li>A song template<\/li>/ | |
| # end | |
| - | # describe 'nav', pending: true do |
| - | |
| - | # subject { get '/all'; last_response.body } |
| - | |
| - | # it { should_not match(/<nav id="nav">/) } |
| - | |
| - | # it { should match(/<li id="about-us-link" class="link first"><a href="\/about-us">About Us<\/a><\/li>/) } |
| - | |
| - | # it { should match(/<li id="music-link" class="link"><a href="\/music">Music<\/a><\/li>/) } |
| - | |
| - | # it { should match(/<li id="store-link" class="link"><a href="\/store">Store<\/a><\/li>/) } |
| - | |
| - | # it { should match(/<li id="contact-link" class="link last"><a href="\/contact">Contact Us<\/a><\/li>/) } |
| - | |
| - | # it { should_not match(/<li id="events-link" class="link"><a href="\/events">Events<\/a><\/li>/) } |
| - | |
| - | # describe 'with wrapper' do |
| - | |
| - | # subject { get '/tags/nav'; last_response.body } |
| - | |
| - | # it { should match(/<nav id="nav">/) } |
| - | |
| - | # end |
| - | |
| - | # describe 'very deep' do |
| - | |
| - | # subject { get '/tags/nav_in_deep'; last_response.body } |
| - | |
| - | # it { should match(/<li id=\"john-doe-link\" class=\"link first last\">/) } |
| - | |
| - | # end |
| - | |
| - | # end |
| - | |
| # describe 'contents with_scope', pending: true do | |
| # subject { get '/grunge_bands'; last_response.body } | |
spec/integration/server/nav_spec.rb
+44
-0
| @@ | @@ -0,0 +1,44 @@ |
| + | require File.dirname(__FILE__) + '/../integration_helper' |
| + | |
| + | describe Locomotive::Steam::Server do |
| + | |
| + | include Rack::Test::Methods |
| + | |
| + | def app |
| + | run_server |
| + | end |
| + | |
| + | describe 'nav' do |
| + | |
| + | subject { get '/all'; last_response.body } |
| + | |
| + | it { is_expected.not_to include('<nav id="nav">') } |
| + | |
| + | it { is_expected.to include('<li id="about-us-link" class="link first"><a href="/about-us">About Us</a></li>') } |
| + | |
| + | it { is_expected.to include('<li id="music-link" class="link"><a href="/music">Music</a></li>') } |
| + | |
| + | it { is_expected.to include('<li id="store-link" class="link"><a href="/store">Store</a></li>') } |
| + | |
| + | it { is_expected.to include('<li id="contact-link" class="link last"><a href="/contact">Contact Us</a></li>') } |
| + | |
| + | it { is_expected.not_to include('<li id="events-link" class="link"><a href="/events">Events</a></li>') } |
| + | |
| + | describe 'with wrapper' do |
| + | |
| + | subject { get '/tags/nav'; last_response.body } |
| + | |
| + | it { is_expected.to include('<nav id="nav">') } |
| + | |
| + | end |
| + | |
| + | describe 'very deep' do |
| + | |
| + | subject { get '/tags/nav-in-deep'; last_response.body } |
| + | |
| + | it { is_expected.to include('<li id="john-doe-link" class="link first last">') } |
| + | |
| + | end |
| + | |
| + | end |
| + | end |
spec/unit/liquid/tags/nav_spec.rb
+7
-7
| @@ | @@ -5,17 +5,17 @@ describe 'Locomotive::Steam::Liquid::Tags::Nav' do |
| let(:index) { instance_double('IndexPage', fullpath: 'index', published: true) } | |
| let(:depth_1) do | |
| [ | |
| - | instance_double('Child1', title: 'Child #1', slug: 'child-1', fullpath: 'child-1', published?: true, listed?: true, templatized?: false, to_liquid: { 'title' => 'Child #1' }), |
| - | instance_double('Child2', title: 'Child #2', slug: 'child-2', fullpath: 'child-2', published?: true, listed?: true, templatized?: false, to_liquid: { 'title' => 'Child #2' }) |
| + | instance_double('Child1', title: 'Child #1', slug: 'child-1', fullpath: 'child-1', published?: true, listed?: true, templatized?: false, localized_attributes: [], to_liquid: { 'title' => 'Child #1' }), |
| + | instance_double('Child2', title: 'Child #2', slug: 'child-2', fullpath: 'child-2', published?: true, listed?: true, templatized?: false, localized_attributes: [], to_liquid: { 'title' => 'Child #2' }) |
| ] | |
| end | |
| let(:depth_2) do | |
| [ | |
| - | instance_double('Child2_1', title: 'Child #2.1', slug: 'child-2-1', fullpath: 'child-2/child-2-1', published?: true, listed?: true, templatized?: false), |
| - | instance_double('Child2_2', title: 'Child #2.2', slug: 'child-2-2', fullpath: 'child-2/child-2-2', published?: true, listed?: true, templatized?: false), |
| - | instance_double('UnpublishedChild2_3', title: 'Child #2.3', slug: 'child-2-3', fullpath: 'child-2/child-2-3', published?: false, listed?: true, templatized?: false), |
| - | instance_double('TemplatizedChild2_4', title: 'Child #2.4', slug: 'child-2-4', fullpath: 'child-2/child-2-4', published?: true, listed?: true, templatized?: true), |
| - | instance_double('UnlistedChild2_4', title: 'Child #2.5', slug: 'child-2-5', fullpath: 'child-2/child-2-5', published?: true, listed?: false, templatized?: false) |
| + | instance_double('Child2_1', title: 'Child #2.1', slug: 'child-2-1', fullpath: 'child-2/child-2-1', published?: true, listed?: true, templatized?: false, localized_attributes: []), |
| + | instance_double('Child2_2', title: 'Child #2.2', slug: 'child-2-2', fullpath: 'child-2/child-2-2', published?: true, listed?: true, templatized?: false, localized_attributes: []), |
| + | instance_double('UnpublishedChild2_3', title: 'Child #2.3', slug: 'child-2-3', fullpath: 'child-2/child-2-3', published?: false, listed?: true, templatized?: false, localized_attributes: []), |
| + | instance_double('TemplatizedChild2_4', title: 'Child #2.4', slug: 'child-2-4', fullpath: 'child-2/child-2-4', published?: true, listed?: true, templatized?: true, localized_attributes: []), |
| + | instance_double('UnlistedChild2_4', title: 'Child #2.5', slug: 'child-2-5', fullpath: 'child-2/child-2-5', published?: true, listed?: false, templatized?: false, localized_attributes: []) |
| ] | |
| end | |
spec/unit/repositories/filesystem/page_spec.rb
+4
-3
| @@ | @@ -27,7 +27,8 @@ describe Locomotive::Steam::Repositories::Filesystem::Page do |
| let(:pages) do | |
| [ | |
| - | { title: { en: 'About us' }, slug: { en: 'about-us' }, _fullpath: 'about-us', template_path: { en: 'about-us.liquid' } }, |
| + | { title: { en: 'Contact' }, slug: { en: 'contact' }, _fullpath: 'contact', template_path: { en: 'contact.liquid' } }, |
| + | { title: { en: 'About us' }, position: 2, slug: { en: 'about-us' }, _fullpath: 'about-us', template_path: { en: 'about-us.liquid' } }, |
| { title: { en: 'Jane Doe' }, slug: { en: 'jane-doe' }, _fullpath: 'team/jane-doe', template_path: { en: 'team/jane-doe.liquid' } }, | |
| { title: { en: 'John Doe' }, position: 1, slug: { en: 'john-doe' }, _fullpath: 'team/john-doe', template_path: { en: 'team/john-doe.liquid' } }, | |
| { title: { en: 'Home' }, slug: { en: 'index' }, _fullpath: 'index', template_path: { en: 'index.liquid' } } | |
| @@ | @@ -38,13 +39,13 @@ describe Locomotive::Steam::Repositories::Filesystem::Page do |
| subject { repository.all(conditions) } | |
| - | it { expect(subject.size).to eq 4 } |
| + | it { expect(subject.size).to eq 5 } |
| describe 'default order' do | |
| subject { repository.all(conditions).map { |p| p.title.values.first } } | |
| - | it { is_expected.to eq ['Home', 'About us', 'John Doe', 'Jane Doe'] } |
| + | it { is_expected.to eq ['Home', 'About us', 'Contact', 'John Doe', 'Jane Doe'] } |
| end | |