Nav Tag spec round 2 - decorated
arnaud sellenet
committed Jun 17, 2014
commit e84939821fcbfb5e11e74c686b44d5b600e9f692
Showing 2
changed files with
24 additions
and 16 deletions
locomotive/steam/liquid/tags/nav.rb b/lib/locomotive/steam/liquid/tags/nav.rb
+7
-7
| @@ | @@ -94,7 +94,7 @@ module Locomotive |
| if !page.listed? || page.templatized? || !page.published? | |
| false | |
| elsif @_options[:exclude] | |
| - | (page.fullpath[:en] =~ @_options[:exclude]).nil? |
| + | (page.fullpath =~ @_options[:exclude]).nil? |
| else | |
| true | |
| end | |
| @@ | @@ -107,7 +107,7 @@ module Locomotive |
| # @return [ Boolean ] | |
| # | |
| def page_selected?(page) | |
| - | self.current_page.fullpath[:en] =~ /^#{page.fullpath[:en]}(\/.*)?$/ |
| + | self.current_page.fullpath =~ /^#{page.fullpath}(\/.*)?$/ |
| end | |
| # Determine if the children of a page have to be rendered or not. | |
| @@ | @@ -132,7 +132,7 @@ module Locomotive |
| # | |
| def entry_label(page) | |
| icon = @_options[:icon] ? '<span></span>' : '' | |
| - | title = @_options[:liquid_render] ? @_options[:liquid_render].render('page' => page) : page.title[::I18n.locale] |
| + | title = @_options[:liquid_render] ? @_options[:liquid_render].render('page' => page) : page.title |
| if icon.blank? | |
| title | |
| @@ | @@ -151,9 +151,9 @@ module Locomotive |
| # | |
| def entry_url(page) | |
| if ::I18n.locale.to_s == self.site.default_locale.to_s | |
| - | "/#{page.fullpath[::I18n.locale]}" |
| + | "/#{page.fullpath}" |
| else | |
| - | "/#{::I18n.locale}/#{page.fullpath[::I18n.locale]}" |
| + | "/#{::I18n.locale}/#{page.fullpath}" |
| end | |
| end | |
| @@ | @@ -193,7 +193,7 @@ module Locomotive |
| options = %{ class="dropdown-toggle" data-toggle="dropdown"} | |
| end | |
| - | self.render_tag(:li, id: "#{page.slug[::I18n.locale].to_s.dasherize}-link", css: css) do |
| + | self.render_tag(:li, id: "#{page.slug.dasherize}-link", css: css) do |
| children_output = depth.succ <= @_options[:depth].to_i ? self.render_entry_children(page, depth.succ) : '' | |
| %{<a href="#{url}"#{options}>#{label}</a>} + children_output | |
| end | |
| @@ | @@ -211,7 +211,7 @@ module Locomotive |
| css = self.bootstrap? ? 'dropdown-menu' : '' | |
| unless entries.empty? | |
| - | self.render_tag(:ul, id: "#{@_options[:id]}-#{page.slug[::I18n.locale].dasherize}", css: css) do |
| + | self.render_tag(:ul, id: "#{@_options[:id]}-#{page.slug.dasherize}", css: css) do |
| self.build_entries_output(entries, depth) | |
| end | |
| else | |
spec/unit/liquid/tags/nav_spec.rb
+17
-9
| @@ | @@ -5,22 +5,22 @@ describe Locomotive::Steam::Liquid::Tags::Nav do |
| subject { Locomotive::Steam::Liquid::Tags::Nav } | |
| let(:entity_class) { Locomotive::Steam::Entities::Page } | |
| let(:site_class) { Locomotive::Steam::Entities::Site } | |
| - | let(:home) { entity_class.new fullpath: { en: 'index' }} |
| + | let(:home) { new_page fullpath: { en: 'index' }} |
| let(:site) { site_class.new locales: %w(en fr) } | |
| before do | |
| home_children = [ | |
| - | entity_class.new(title: { en: 'Child #1' }, fullpath: { en: 'child_1' }, slug: { en: 'child_1' }, published: true, listed: true), |
| - | entity_class.new(title: { en: 'Child #2' }, fullpath: { en: 'child_2' }, slug: { en: 'child_2' }, published: true, listed: true) |
| + | new_page(title: { en: 'Child #1' }, fullpath: { en: 'child_1' }, slug: { en: 'child_1' }, published: true, listed: true), |
| + | new_page(title: { en: 'Child #2' }, fullpath: { en: 'child_2' }, slug: { en: 'child_2' }, published: true, listed: true) |
| ] | |
| home.stub(children: home_children) | |
| other_children = [ | |
| - | entity_class.new(title: { en: 'Child #2.1' }, fullpath: { en: 'child_2/sub_child_1' }, slug: { en: 'sub_child_1' }, published: true, listed: true), |
| - | entity_class.new(title: { en: 'Child #2.2' }, fullpath: { en: 'child_2/sub_child_2' }, slug: { en: 'sub_child_2' }, published: true, listed: true), |
| - | entity_class.new(title: { en: 'Unpublished #2.2' }, fullpath: { en: 'child_2/sub_child_unpublishd_2' }, slug: { en: 'sub_child_unpublished_2' }, published: false, listed: true), |
| - | entity_class.new(title: { en: 'Templatized #2.3' }, fullpath: { en: 'child_2/sub_child_template_3' }, slug: { en: 'sub_child_template_3' }, published: true, templatized: true, listed: true), |
| - | entity_class.new(title: { en: 'Unlisted #2.4' }, fullpath: { en: 'child_2/sub_child_unlisted_4' }, slug: { en: 'sub_child_unlisted_4' }, published: true, listed: false) |
| + | new_page(title: { en: 'Child #2.1' }, fullpath: { en: 'child_2/sub_child_1' }, slug: { en: 'sub_child_1' }, published: true, listed: true), |
| + | new_page(title: { en: 'Child #2.2' }, fullpath: { en: 'child_2/sub_child_2' }, slug: { en: 'sub_child_2' }, published: true, listed: true), |
| + | new_page(title: { en: 'Unpublished #2.2' }, fullpath: { en: 'child_2/sub_child_unpublishd_2' }, slug: { en: 'sub_child_unpublished_2' }, published: false, listed: true), |
| + | new_page(title: { en: 'Templatized #2.3' }, fullpath: { en: 'child_2/sub_child_template_3' }, slug: { en: 'sub_child_template_3' }, published: true, templatized: true, listed: true), |
| + | new_page(title: { en: 'Unlisted #2.4' }, fullpath: { en: 'child_2/sub_child_unlisted_4' }, slug: { en: 'sub_child_unlisted_4' }, published: true, listed: false) |
| ] | |
| home.children.last.stub(children: other_children) | |
| @@ | @@ -104,7 +104,7 @@ describe Locomotive::Steam::Liquid::Tags::Nav do |
| it 'renders a snippet for the title' do | |
| render_nav('site', {}, 'snippet: "-{{page.title}} {{ foo.png | theme_image_tag }}-"') | |
| - | .should match( /<li id="child-1-link" class="link first"><a href="\/child_1">-Child #1 <img src=\"\" >-<\/a><\/li>/) |
| + | .should match( /<li id="child-1-link" class="link first"><a href="\/child_1">-Child #1 <img src=\"\" \/>-<\/a><\/li>/) |
| end | |
| it 'assigns a different dom id' do | |
| @@ | @@ -140,6 +140,14 @@ describe Locomotive::Steam::Liquid::Tags::Nav do |
| end | |
| + | def new_page attributes |
| + | Locomotive::Steam::Decorators::PageDecorator.new( |
| + | Locomotive::Decorators::I18nDecorator.new( |
| + | entity_class.new(attributes), :en |
| + | ) |
| + | ) |
| + | end |
| + | |
| def render_nav(source = 'site', registers = {}, template_option = '') | |
| registers = { site: site, page: home }.merge(registers) | |
| liquid_context = ::Liquid::Context.new({}, {}, registers) | |