page slugs are now dasherized by default + fix an issue in Wagon about the URL of file fields (content entry)
did
committed May 15, 2015
commit 1d4677137312938a57f250b47568158939389168
Showing 4
changed files with
9 additions
and 5 deletions
locomotive/steam/adapters/filesystem/yaml_loaders/page.rb b/lib/locomotive/steam/adapters/filesystem/yaml_loaders/page.rb
+2
-2
| @@ | @@ -44,7 +44,7 @@ module Locomotive |
| { | |
| title: { locale => attributes.delete(:title) || (default_locale == locale ? slug.humanize : nil) }, | |
| - | slug: { locale => attributes.delete(:slug) || slug }, |
| + | slug: { locale => attributes.delete(:slug) || slug.dasherize }, |
| template_path: { locale => template_path(filepath, attributes, locale) }, | |
| redirect_url: { locale => attributes.delete(:redirect_url) }, | |
| editable_elements: build_editable_elements(attributes.delete(:editable_elements), locale), | |
| @@ | @@ -57,7 +57,7 @@ module Locomotive |
| attributes = get_attributes(filepath, fullpath) | |
| leaf[:title][locale] = attributes.delete(:title) || slug.humanize | |
| - | leaf[:slug][locale] = attributes.delete(:slug) || slug |
| + | leaf[:slug][locale] = attributes.delete(:slug) || slug.dasherize |
| leaf[:template_path][locale] = template_path(filepath, attributes, locale) | |
| leaf[:redirect_url][locale] = attributes.delete(:redirect_url) | |
locomotive/steam/entities/content_entry.rb b/lib/locomotive/steam/entities/content_entry.rb
+1
-1
| @@ | @@ -145,7 +145,7 @@ module Locomotive::Steam |
| class FileField < Struct.new(:filename, :base, :updated_at) | |
| def url | |
| - | "#{base}/#{filename}" |
| + | base.blank? ? filename : "#{base}/#{filename}" |
| end | |
| def to_liquid | |
spec/unit/entities/content_entry_spec.rb
+2
-2
| @@ | @@ -133,10 +133,10 @@ describe Locomotive::Steam::ContentEntry do |
| context 'a file' do | |
| let(:field_type) { :file } | |
| - | let(:value) { 'foo.png' } |
| + | let(:value) { '/foo.png' } |
| it { expect(subject.url).to eq('/foo.png') } | |
| context 'localized' do | |
| - | let(:value) { build_i18n_field(en: 'foo-en.png', fr: 'foo-fr.png') } |
| + | let(:value) { build_i18n_field(en: '/foo-en.png', fr: '/foo-fr.png') } |
| it { expect(subject.translations[:en].url).to eq('/foo-en.png') } | |
| it { expect(subject.translations[:fr].url).to eq('/foo-fr.png') } | |
| end | |
spec/unit/liquid/filters/html_spec.rb
+4
-0
| @@ | @@ -217,6 +217,10 @@ describe Locomotive::Steam::Liquid::Filters::Html do |
| expect(image_tag('foo.jpg')).to eq("<img src=\"foo.jpg\" >") | |
| end | |
| + | it 'returns an image tag for a file with a leading slash' do |
| + | expect(image_tag('/foo.jpg')).to eq "<img src=\"/foo.jpg\" >" |
| + | end |
| + | |
| it 'returns an image tag with size' do | |
| expect(image_tag('foo.jpg', 'width:100', 'height:50')).to eq("<img src=\"foo.jpg\" height=\"50\" width=\"100\" >") | |
| end | |