make the link_to fail decently if pages are not translated
did
committed Aug 21, 2013
commit 1ecef631c58ef8e71742de89bfb77b6b59804347
Showing 9
changed files with
45 additions
and 10 deletions
locomotive/wagon/liquid/errors.rb b/lib/locomotive/wagon/liquid/errors.rb
+2
-0
| @@ | @@ -3,6 +3,8 @@ module Locomotive |
| module Liquid | |
| class PageNotFound < ::Liquid::Error; end | |
| + | class PageNotTranslated < ::Liquid::Error; end |
| + | |
| class UnknownConditionInScope < ::Liquid::Error; end | |
| end | |
| end | |
locomotive/wagon/liquid/tags/link_to.rb b/lib/locomotive/wagon/liquid/tags/link_to.rb
+8
-2
| @@ | @@ -32,7 +32,7 @@ module Locomotive |
| %{<a href="#{path}">#{label}</a>} | |
| else | |
| - | '' # no page found |
| + | raise Liquid::PageNotTranslated.new(%{[link_to] Unable to find a page for the #{@handle}. Wrong handle or missing template for your content.}) |
| end | |
| end | |
| @@ | @@ -89,8 +89,14 @@ module Locomotive |
| def public_page_url(context, page) | |
| mounting_point = context.registers[:mounting_point] | |
| + | locale = @options['locale'] || ::I18n.locale |
| - | fullpath = ::Locomotive::Mounter.with_locale(@options['locale']) do |
| + | if !page.translated_in?(locale) |
| + | title = page.title_translations.values.compact.first |
| + | raise Liquid::PageNotTranslated.new(%{the "#{title}" page is not translated in #{locale.upcase}}) |
| + | end |
| + | |
| + | fullpath = ::Locomotive::Mounter.with_locale(locale) do |
| page.fullpath.clone | |
| end | |
locomotivecms_wagon.gemspec
+1
-1
| @@ | @@ -35,7 +35,7 @@ Gem::Specification.new do |gem| |
| gem.add_dependency 'httmultiparty', '0.3.10' | |
| gem.add_dependency 'will_paginate', '~> 3.0.3' | |
| - | gem.add_dependency 'locomotivecms_mounter', '~> 1.2.4' |
| + | gem.add_dependency 'locomotivecms_mounter', '~> 1.2.5' |
| gem.add_dependency 'faker', '~> 0.9.5' | |
spec/fixtures/default/app/views/pages/index.liquid.haml
+1
-6
| @@ | @@ -91,12 +91,7 @@ title: Home page |
| #footer | |
| #is_templatized{templatized: "{{ page.templatized? }}"} | |
| #scoped_translation{scoped_translation: "{{ 'fr' | translate: 'en', 'locomotive.locales' }}"} | |
| - | |
| - | %p {% locale_switcher %} |
| - | %p |
| - | {{ 'powered_by' | translate }} <a href="http://www.locomotivecms.com">LocomotiveCMS</a>. Designed by <a href="http://www.sachagreif.com">Sacha Greif</a>. |
| - | %p |
| - | All photos are licensed under Creative Commons. (see original ones <a href='http://www.flickr.com/photos/38687875@N00/3391588262/'>here</a> or <a href='http://www.flickr.com/photos/cool_dry_place/55454498/'>here</a>). |
| + | {% include footer %} |
| {% google_analytics 'UA-20661758-1' %} | |
spec/fixtures/default/app/views/pages/music.fr.liquid.haml
+4
-0
| @@ | @@ -0,0 +1,4 @@ |
| + | --- |
| + | title: Notre musique |
| + | slug: notre-musique |
| + | --- |
spec/fixtures/default/app/views/pages/songs/template.fr.liquid.haml
+16
-0
| @@ | @@ -0,0 +1,16 @@ |
| + | --- |
| + | title: Le template d'une chanson |
| + | --- |
| + | {% extends 'index' %} |
| + | |
| + | {% block content %} |
| + | |
| + | %h3 {{ song.title }} [FR] |
| + | |
| + | %p {{ song.short_description }} |
| + | |
| + | #is_templatized{templatized: "{{ page.templatized? }}"} |
| + | #content_type_size{content_type_size: "{{ page.content_type.size }}"} |
| + | #content_type_count{content_type_count: "{{ page.content_type.count }}"} |
| + | |
| + | {% endblock %} |
| \ No newline at end of file | |
spec/fixtures/default/app/views/snippets/footer.liquid.haml
+6
-0
| @@ | @@ -0,0 +1,6 @@ |
| + | %p {% locale_switcher %} |
| + | |
| + | %p |
| + | {{ 'powered_by' | translate }} <a href="http://www.locomotivecms.com">LocomotiveCMS</a>. Designed by <a href="http://www.sachagreif.com">Sacha Greif</a>. |
| + | %p |
| + | All photos are licensed under Creative Commons. (see original ones <a href='http://www.flickr.com/photos/38687875@N00/3391588262/'>here</a> or <a href='http://www.flickr.com/photos/cool_dry_place/55454498/'>here</a>). |
| \ No newline at end of file | |
spec/fixtures/default/app/views/snippets/song.fr.liquid.haml
+1
-1
| @@ | @@ -1,5 +1,5 @@ |
| %li | |
| - | %h3 {{ song.title }} |
| + | %h3 {% link_to song, with: a-song-template %} |
| .cover {{ song.cover.url | image_tag }} | |
| .info | |
| {{ song.short_description }} | |
spec/integration/server/basic_spec.rb
+6
-0
| @@ | @@ -46,6 +46,12 @@ describe Locomotive::Wagon::Server do |
| last_response.body.should =~ /scoped_translation=.French./ | |
| end | |
| + | it 'translates a page with link_to tags inside' do |
| + | get '/fr/notre-musique' |
| + | last_response.body.should =~ /<h3><a href="\/fr\/songs\/song-8">Song #8<\/a><\/h3>/ |
| + | last_response.body.should =~ /Propulsé par/ |
| + | end |
| + | |
| it 'returns all the pages' do | |
| get '/all' | |
| last_response.body.should =~ /Home page/ | |