This commit is contained in:
Didier Lafforgue 2012-05-25 13:24:10 +02:00
parent 24ae75c6f5
commit 2ac74c9a50
2 changed files with 14 additions and 8 deletions

View File

@ -28,7 +28,7 @@ module Locomotive
if @options[:snippet]
template = @options[:snippet].include?('{') ? @options[:snippet] : context[:site].snippets.where(:slug => @options[:snippet] ).try(:first).try(:template)
unless template.blank?
@options[:liquid_render] = ::Liquid::Template.parse( template )
@options[:liquid_render] = ::Liquid::Template.parse(template)
@options[:add_attributes] = ['editable_elements']
end
end
@ -70,12 +70,12 @@ module Locomotive
@site, @page = context.registers[:site], context.registers[:page]
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 'page' then @page
else
@site.pages.fullpath(@source).minimal_attributes( @options[:add_attributes] ).first
end).children_with_minimal_attributes( @options[:add_attributes] ).to_a
@site.pages.fullpath(@source).minimal_attributes(@options[:add_attributes]).first
end).children_with_minimal_attributes(@options[:add_attributes]).to_a
children.delete_if { |p| !include_page?(p) }
end
@ -86,12 +86,12 @@ module Locomotive
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' }}
link_options = caret = ''
href = "/#{page.fullpath}"
href = File.join('/', @site.localized_page_fullpath(page))
if render_children_for_page?(page, depth) && bootstrap?
css += ' dropdown'
@ -116,7 +116,7 @@ module Locomotive
def render_entry_children(page, depth)
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?
output = %{<ul id="#{@options[:id]}-#{page.slug.to_s.dasherize}" class="#{bootstrap? ? 'dropdown-menu' : ''}">}
children.each do |c, page|

View File

@ -24,7 +24,7 @@ describe Locomotive::Liquid::Tags::Nav do
pages = [@home]
pages.stubs(:root).returns(pages)
pages.stubs(:minimal_attributes).returns(pages) # iso
@site = FactoryGirl.build(:site)
@site = FactoryGirl.build(:site, :locales => %w(en fr))
@site.stubs(:pages).returns(pages)
end
@ -122,6 +122,12 @@ describe Locomotive::Liquid::Tags::Nav do
render_nav('site', {}, 'no_wrapper: true').should_not match /<ul id="nav">/
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
def render_nav(source = 'site', registers = {}, template_option = '')