From f77bdd9826917313c9a4e064add9f208ed95e097 Mon Sep 17 00:00:00 2001 From: did Date: Mon, 5 Mar 2012 14:17:33 -0800 Subject: [PATCH] fix #289. This fix is different from the one in the master branch. It only the filename (without the whole path and the extension) --- app/models/locomotive/content_entry.rb | 4 +++- lib/locomotive/carrierwave/base.rb | 4 ++++ spec/models/locomotive/content_entry_spec.rb | 7 +++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/models/locomotive/content_entry.rb b/app/models/locomotive/content_entry.rb index 47c39dd5..9694cf66 100644 --- a/app/models/locomotive/content_entry.rb +++ b/app/models/locomotive/content_entry.rb @@ -39,11 +39,13 @@ module Locomotive alias :_permalink= :_slug= def _label(type = nil) - if self._label_field_name + value = if self._label_field_name self.send(self._label_field_name.to_sym) else self.send((type || self.content_type).label_field_name.to_sym) end + + value.respond_to?(:to_label) ? value.to_label : value end def next diff --git a/lib/locomotive/carrierwave/base.rb b/lib/locomotive/carrierwave/base.rb index a86b6252..aeb44895 100644 --- a/lib/locomotive/carrierwave/base.rb +++ b/lib/locomotive/carrierwave/base.rb @@ -2,6 +2,10 @@ module CarrierWave module Uploader class Base + def to_label + File.basename(self.to_s, File.extname(self.to_s)) + end + def to_liquid Locomotive::Liquid::Drops::Uploader.new(self) end diff --git a/spec/models/locomotive/content_entry_spec.rb b/spec/models/locomotive/content_entry_spec.rb index 7f7ee022..73edfe31 100644 --- a/spec/models/locomotive/content_entry_spec.rb +++ b/spec/models/locomotive/content_entry_spec.rb @@ -10,6 +10,7 @@ describe Locomotive::ContentEntry do @content_type.entries_custom_fields.build :label => 'Title', :type => 'string' @content_type.entries_custom_fields.build :label => 'Description', :type => 'text' @content_type.entries_custom_fields.build :label => 'Visible ?', :type => 'boolean', :name => 'visible' + @content_type.entries_custom_fields.build :label => 'File', :type => 'file' @content_type.valid? @content_type.send(:set_default_values) end @@ -127,6 +128,12 @@ describe Locomotive::ContentEntry do @content_entry._permalink.should == 'my-test' end + it 'also accepts a file field as the highlighted field' do + @content_entry.stubs(:_label_field_name).returns('file') + @content_entry.file = FixturedAsset.open('5k.png'); @content_entry.send(:set_slug) + @content_entry._permalink.should == '5k' + end + end describe '#visibility' do