From ce5576da09a8759f1943c8f756cebc3e70f33b71 Mon Sep 17 00:00:00 2001 From: Didier Lafforgue Date: Sun, 22 Apr 2012 23:25:18 +0200 Subject: [PATCH] the extends tag was not looking for the right fullpath (when localization is enabled) + sample in order to modify the tinyMCE settings in the back-office --- .../javascripts/locomotive/aloha.js.coffee | 7 +------ lib/locomotive/liquid/tags/extends.rb | 4 +++- .../javascripts/locomotive_misc.js.coffee | 2 ++ .../shared/_main_app_head.html.haml | 1 + .../locomotive/liquid/tags/extends_spec.rb | 20 +++++++++++++++---- 5 files changed, 23 insertions(+), 11 deletions(-) create mode 100644 spec/dummy/app/assets/javascripts/locomotive_misc.js.coffee create mode 100644 spec/dummy/app/views/locomotive/shared/_main_app_head.html.haml diff --git a/app/assets/javascripts/locomotive/aloha.js.coffee b/app/assets/javascripts/locomotive/aloha.js.coffee index f2d488f2..c6c3b0c3 100644 --- a/app/assets/javascripts/locomotive/aloha.js.coffee +++ b/app/assets/javascripts/locomotive/aloha.js.coffee @@ -1,7 +1,2 @@ #= require ./utils/aloha_settings -#= require aloha - - -# r equire_tree ./../aloha/plugins - -# . /.. / aloha / plugins \ No newline at end of file +#= require aloha \ No newline at end of file diff --git a/lib/locomotive/liquid/tags/extends.rb b/lib/locomotive/liquid/tags/extends.rb index 3c49a4f1..634c60c0 100644 --- a/lib/locomotive/liquid/tags/extends.rb +++ b/lib/locomotive/liquid/tags/extends.rb @@ -27,8 +27,10 @@ module Locomotive @context[:parent_page] = @context[:page].parent end else + locale = ::Mongoid::Fields::I18n.locale + @context[:parent_page] = @context[:cached_pages].try(:[], @template_name) || - @context[:site].pages.where(:fullpath => @template_name).first + @context[:site].pages.where("fullpath.#{locale}" => @template_name).first end raise PageNotFound.new("Page with fullpath '#{@template_name}' was not found") if @context[:parent_page].nil? diff --git a/spec/dummy/app/assets/javascripts/locomotive_misc.js.coffee b/spec/dummy/app/assets/javascripts/locomotive_misc.js.coffee new file mode 100644 index 00000000..b3d4aca8 --- /dev/null +++ b/spec/dummy/app/assets/javascripts/locomotive_misc.js.coffee @@ -0,0 +1,2 @@ +# FIXME: just to demonstrate how easy it is to change the tinymce settings for the LocomotiveCMS back-office +# window.Locomotive.tinyMCE.defaultSettings.theme_advanced_buttons2 = 'formatselect,fontselect,fontsizeselect' \ No newline at end of file diff --git a/spec/dummy/app/views/locomotive/shared/_main_app_head.html.haml b/spec/dummy/app/views/locomotive/shared/_main_app_head.html.haml new file mode 100644 index 00000000..0d92fabb --- /dev/null +++ b/spec/dummy/app/views/locomotive/shared/_main_app_head.html.haml @@ -0,0 +1 @@ += javascript_include_tag 'locomotive_misc' diff --git a/spec/lib/locomotive/liquid/tags/extends_spec.rb b/spec/lib/locomotive/liquid/tags/extends_spec.rb index 0a53f54d..bc70568a 100644 --- a/spec/lib/locomotive/liquid/tags/extends_spec.rb +++ b/spec/lib/locomotive/liquid/tags/extends_spec.rb @@ -12,17 +12,29 @@ describe Locomotive::Liquid::Tags::Extends do end it 'works' do - lambda { + page = FactoryGirl.build(:page, :slug => 'sub_page_1', :parent => @home) + parse('parent', page).render.should == 'Hello world' + end + + it 'looks for the index with the right locale' do + ::Mongoid::Fields::I18n.with_locale 'fr' do + @home.raw_template = 'Bonjour le monde' + @home.send :serialize_template + end + + @site.pages.expects(:where).with('fullpath.fr' => 'index').returns([@home]) + + ::Mongoid::Fields::I18n.with_locale 'fr' do page = FactoryGirl.build(:page, :slug => 'sub_page_1', :parent => @home) - parse('parent', page) - }.should_not raise_error + parse('index', page).render.should == 'Bonjour le monde' + end end context '#errors' do it 'raises an error if the source page does not exist' do lambda { - @site.pages.expects(:where).with(:fullpath => 'foo').returns([]) + @site.pages.expects(:where).with('fullpath.en' => 'foo').returns([]) parse('foo') }.should raise_error(Locomotive::Liquid::PageNotFound, "Page with fullpath 'foo' was not found") end