fix issue #411
This commit is contained in:
parent
24ae75c6f5
commit
2ac74c9a50
@ -28,7 +28,7 @@ module Locomotive
|
|||||||
if @options[:snippet]
|
if @options[:snippet]
|
||||||
template = @options[:snippet].include?('{') ? @options[:snippet] : context[:site].snippets.where(:slug => @options[:snippet] ).try(:first).try(:template)
|
template = @options[:snippet].include?('{') ? @options[:snippet] : context[:site].snippets.where(:slug => @options[:snippet] ).try(:first).try(:template)
|
||||||
unless template.blank?
|
unless template.blank?
|
||||||
@options[:liquid_render] = ::Liquid::Template.parse( template )
|
@options[:liquid_render] = ::Liquid::Template.parse(template)
|
||||||
@options[:add_attributes] = ['editable_elements']
|
@options[:add_attributes] = ['editable_elements']
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -70,12 +70,12 @@ module Locomotive
|
|||||||
@site, @page = context.registers[:site], context.registers[:page]
|
@site, @page = context.registers[:site], context.registers[:page]
|
||||||
|
|
||||||
children = (case @source
|
children = (case @source
|
||||||
when 'site' then @site.pages.root.minimal_attributes( @options[:add_attributes] ).first # start from home page
|
when 'site' then @site.pages.root.minimal_attributes(@options[:add_attributes]).first # start from home page
|
||||||
when 'parent' then @page.parent || @page
|
when 'parent' then @page.parent || @page
|
||||||
when 'page' then @page
|
when 'page' then @page
|
||||||
else
|
else
|
||||||
@site.pages.fullpath(@source).minimal_attributes( @options[:add_attributes] ).first
|
@site.pages.fullpath(@source).minimal_attributes(@options[:add_attributes]).first
|
||||||
end).children_with_minimal_attributes( @options[:add_attributes] ).to_a
|
end).children_with_minimal_attributes(@options[:add_attributes]).to_a
|
||||||
|
|
||||||
children.delete_if { |p| !include_page?(p) }
|
children.delete_if { |p| !include_page?(p) }
|
||||||
end
|
end
|
||||||
@ -86,12 +86,12 @@ module Locomotive
|
|||||||
|
|
||||||
icon = @options[:icon] ? '<span></span>' : ''
|
icon = @options[:icon] ? '<span></span>' : ''
|
||||||
|
|
||||||
title = @options[:liquid_render] ? @options[:liquid_render].render( 'page' => page ) : page.title
|
title = @options[:liquid_render] ? @options[:liquid_render].render('page' => page) : page.title
|
||||||
|
|
||||||
label = %{#{icon if @options[:icon] != 'after' }#{title}#{icon if @options[:icon] == 'after' }}
|
label = %{#{icon if @options[:icon] != 'after' }#{title}#{icon if @options[:icon] == 'after' }}
|
||||||
|
|
||||||
link_options = caret = ''
|
link_options = caret = ''
|
||||||
href = "/#{page.fullpath}"
|
href = File.join('/', @site.localized_page_fullpath(page))
|
||||||
|
|
||||||
if render_children_for_page?(page, depth) && bootstrap?
|
if render_children_for_page?(page, depth) && bootstrap?
|
||||||
css += ' dropdown'
|
css += ' dropdown'
|
||||||
@ -116,7 +116,7 @@ module Locomotive
|
|||||||
def render_entry_children(page, depth)
|
def render_entry_children(page, depth)
|
||||||
output = %{}
|
output = %{}
|
||||||
|
|
||||||
children = page.children_with_minimal_attributes( @options[:add_attributes] ).reject { |c| !include_page?(c) }
|
children = page.children_with_minimal_attributes(@options[:add_attributes]).reject { |c| !include_page?(c) }
|
||||||
if children.present?
|
if children.present?
|
||||||
output = %{<ul id="#{@options[:id]}-#{page.slug.to_s.dasherize}" class="#{bootstrap? ? 'dropdown-menu' : ''}">}
|
output = %{<ul id="#{@options[:id]}-#{page.slug.to_s.dasherize}" class="#{bootstrap? ? 'dropdown-menu' : ''}">}
|
||||||
children.each do |c, page|
|
children.each do |c, page|
|
||||||
|
@ -24,7 +24,7 @@ describe Locomotive::Liquid::Tags::Nav do
|
|||||||
pages = [@home]
|
pages = [@home]
|
||||||
pages.stubs(:root).returns(pages)
|
pages.stubs(:root).returns(pages)
|
||||||
pages.stubs(:minimal_attributes).returns(pages) # iso
|
pages.stubs(:minimal_attributes).returns(pages) # iso
|
||||||
@site = FactoryGirl.build(:site)
|
@site = FactoryGirl.build(:site, :locales => %w(en fr))
|
||||||
@site.stubs(:pages).returns(pages)
|
@site.stubs(:pages).returns(pages)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -122,6 +122,12 @@ describe Locomotive::Liquid::Tags::Nav do
|
|||||||
render_nav('site', {}, 'no_wrapper: true').should_not match /<ul id="nav">/
|
render_nav('site', {}, 'no_wrapper: true').should_not match /<ul id="nav">/
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'localizes the links' do
|
||||||
|
I18n.with_locale('fr') do
|
||||||
|
render_nav.should == '<ul id="nav"><li id="child-1-link" class="link first"><a href="/fr/child_1">Child #1</a></li><li id="child-2-link" class="link last"><a href="/fr/child_2">Child #2</a></li></ul>'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_nav(source = 'site', registers = {}, template_option = '')
|
def render_nav(source = 'site', registers = {}, template_option = '')
|
||||||
|
Loading…
Reference in New Issue
Block a user