fixing a bug with the link_to liquid tag and the url_for method of the url_builder service
did
committed Feb 16, 2015
commit 980aea7acc8e88408ddb0f6376be0c6db219e14f
Showing 9
changed files with
29 additions
and 20 deletions
locomotive/steam/liquid/tags/concerns/path.rb b/lib/locomotive/steam/liquid/tags/concerns/path.rb
+12
-3
| @@ | @@ -9,8 +9,13 @@ module Locomotive |
| def initialize(tag_name, markup, options) | |
| if markup =~ Syntax | |
| - | @handle = $1 |
| - | @path_options = parse_options_from_string($2) |
| + | @handle, _options = $1, $2 |
| + | |
| + | # FIXME: the with option needs a string with quotes. |
| + | # this is a hack for sites which don't follow the new syntax. |
| + | _options.gsub!(/with: ([\w-]+)/, 'with: "\1"') if _options |
| + | |
| + | @raw_path_options = parse_options_from_string(_options) |
| else | |
| self.wrong_syntax! | |
| end | |
| @@ | @@ -84,11 +89,15 @@ module Locomotive |
| def set_vars_from_context(context) | |
| @context = context | |
| - | @path_options = interpolate_options(@path_options, context) |
| + | @path_options = evaluate_path_options(context) |
| @site = context.registers[:site] | |
| @locale = context.registers[:locale] | |
| end | |
| + | def evaluate_path_options(context) |
| + | interpolate_options(@raw_path_options, context) |
| + | end |
| + | |
| end | |
| end | |
| end | |
locomotive/steam/repositories/filesystem/models/content_entry.rb b/lib/locomotive/steam/repositories/filesystem/models/content_entry.rb
+1
-1
| @@ | @@ -32,7 +32,7 @@ module Locomotive |
| end | |
| def content_type_slug | |
| - | content_type.try(:slug) |
| + | content_type.slug |
| end | |
| def _label | |
locomotive/steam/services/url_builder.rb b/lib/locomotive/steam/services/url_builder.rb
+1
-1
| @@ | @@ -27,7 +27,7 @@ module Locomotive |
| path = page.fullpath | |
| if page.templatized? && page.content_entry | |
| - | path.gsub('content_type_template', page.content_entry._slug) |
| + | path.gsub('content-type-template', page.content_entry._slug) |
| elsif path == 'index' | |
| same_locale ? '' : nil | |
| else | |
spec/fixtures/default/app/views/snippets/song.fr.liquid.haml
+1
-1
| @@ | @@ -5,4 +5,4 @@ |
| {{ song.short_description }} | |
| %p.listen | |
| %a{ :href => "{{ song.audio_url }}" } → écouter ({{ song.duration }} min) | |
| - | .clear |
| \ No newline at end of file | |
| + | .clear |
spec/integration/server/basic_spec.rb
+10
-10
| @@ | @@ -74,16 +74,16 @@ describe Locomotive::Steam::Server do |
| expect(last_response.body).to include 'Propulsé par' | |
| end | |
| - | # it 'provides translation in scopes', pending: true do |
| - | # get '/' |
| - | # last_response.body.should =~ /scoped_translation=.French./ |
| - | # end |
| - | |
| - | # it 'translates a page with link_to tags inside', pending: true do |
| - | # get '/fr/notre-musique' |
| - | # last_response.body.should =~ /<h3><a href="\/fr\/songs\/song-number-8">Song #8<\/a><\/h3>/ |
| - | # last_response.body.should =~ /Propulsé par/ |
| - | # end |
| + | it 'provides translation in scopes' do |
| + | get '/' |
| + | expect(last_response.body).to match /scoped_translation=.French./ |
| + | end |
| + | |
| + | it 'translates a page with link_to tags inside' do |
| + | get '/fr/notre-musique' |
| + | expect(last_response.body).to include '<h3><a href="/fr/songs/song-number-8">Song #8</a></h3>' |
| + | expect(last_response.body).to include 'Propulsé par' |
| + | end |
| end | |
spec/unit/liquid/tags/link_to_spec.rb
+1
-1
| @@ | @@ -82,7 +82,7 @@ describe Locomotive::Steam::Liquid::Tags::PathTo do |
| let(:entry_drop) { Locomotive::Steam::Liquid::Drops::ContentEntry.new(entry, [:_label, :_slug]) } | |
| let(:entry) { liquid_instance_double('Article', attributes: { _label: { en: 'Hello world', fr: 'Bonjour monde' }, _slug: { en: 'hello-world', fr: 'bonjour-monde' } }) } | |
| let(:drop) { Locomotive::Steam::Liquid::Drops::Page.new(page, [:fullpath]) } | |
| - | let(:page) { liquid_instance_double('ArticleTemplate', title: 'Template of an article', handle: 'article', attributes: { fullpath: { en: 'my-articles/content_type_template', fr: 'mes-articles/content_type_template' } }, localized_attributes: [:fullpath], content_entry: entry_drop.send(:_source), templatized?: true) } |
| + | let(:page) { liquid_instance_double('ArticleTemplate', title: 'Template of an article', handle: 'article', attributes: { fullpath: { en: 'my-articles/content-type-template', fr: 'mes-articles/content-type-template' } }, localized_attributes: [:fullpath], content_entry: entry_drop.send(:_source), templatized?: true) } |
| let(:source) { '{% link_to article %}' } | |
| before do | |
spec/unit/liquid/tags/locale_switcher_spec.rb
+1
-1
| @@ | @@ -49,7 +49,7 @@ describe Locomotive::Steam::Liquid::Tags::LocaleSwitcher do |
| let(:entry_drop) { Locomotive::Steam::Liquid::Drops::ContentEntry.new(entry, [:_label, :_slug]) } | |
| let(:entry) { liquid_instance_double('Article', attributes: { _label: { en: 'Hello world', fr: 'Bonjour monde' }, _slug: { en: 'hello-world', fr: 'bonjour-monde' } }) } | |
| let(:drop) { Locomotive::Steam::Liquid::Drops::Page.new(page, [:fullpath]) } | |
| - | let(:attributes) { { fullpath: { en: 'my-articles/content_type_template', fr: 'mes-articles/content_type_template' } } } |
| + | let(:attributes) { { fullpath: { en: 'my-articles/content-type-template', fr: 'mes-articles/content-type-template' } } } |
| let(:page) { liquid_instance_double('ArticleTemplate', title: 'Article template', attributes: attributes, content_entry: entry_drop.send(:_source), templatized?: true) } | |
| let(:source) { '{% locale_switcher label: "title" %}' } | |
spec/unit/liquid/tags/path_to_spec.rb
+1
-1
| @@ | @@ -78,7 +78,7 @@ describe Locomotive::Steam::Liquid::Tags::PathTo do |
| let(:entry_drop) { Locomotive::Steam::Liquid::Drops::ContentEntry.new(entry, [:_slug]) } | |
| let(:entry) { liquid_instance_double('Article', attributes: { _slug: { en: 'hello-world', fr: 'bonjour-monde' } }) } | |
| let(:drop) { Locomotive::Steam::Liquid::Drops::Page.new(page, [:fullpath]) } | |
| - | let(:page) { liquid_instance_double('ArticleTemplate', title: 'Template of an article', handle: 'article', attributes: { fullpath: { en: 'my-articles/content_type_template', fr: 'mes-articles/content_type_template' } }, localized_attributes: [:fullpath], content_entry: entry_drop.send(:_source), templatized?: true) } |
| + | let(:page) { liquid_instance_double('ArticleTemplate', title: 'Template of an article', handle: 'article', attributes: { fullpath: { en: 'my-articles/content-type-template', fr: 'mes-articles/content-type-template' } }, localized_attributes: [:fullpath], content_entry: entry_drop.send(:_source), templatized?: true) } |
| let(:source) { '{% path_to article %}' } | |
| before do | |
spec/unit/services/url_builder_spec.rb
+1
-1
| @@ | @@ -38,7 +38,7 @@ describe Locomotive::Steam::Services::UrlBuilder do |
| describe 'templatized page' do | |
| let(:article) { instance_double('Article', _slug: 'hello-world') } | |
| - | let(:page) { instance_double('Template', fullpath: 'articles/content_type_template', templatized?: true, content_entry: article) } |
| + | let(:page) { instance_double('Template', fullpath: 'articles/content-type-template', templatized?: true, content_entry: article) } |
| it { is_expected.to eq '/articles/hello-world' } | |
| end | |