fix #289. This fix is different from the one in the master branch. It only the filename (without the whole path and the extension)

This commit is contained in:
did 2012-03-05 14:17:33 -08:00
parent 1da5617b80
commit f77bdd9826
3 changed files with 14 additions and 1 deletions

View File

@ -39,11 +39,13 @@ module Locomotive
alias :_permalink= :_slug= alias :_permalink= :_slug=
def _label(type = nil) def _label(type = nil)
if self._label_field_name value = if self._label_field_name
self.send(self._label_field_name.to_sym) self.send(self._label_field_name.to_sym)
else else
self.send((type || self.content_type).label_field_name.to_sym) self.send((type || self.content_type).label_field_name.to_sym)
end end
value.respond_to?(:to_label) ? value.to_label : value
end end
def next def next

View File

@ -2,6 +2,10 @@ module CarrierWave
module Uploader module Uploader
class Base class Base
def to_label
File.basename(self.to_s, File.extname(self.to_s))
end
def to_liquid def to_liquid
Locomotive::Liquid::Drops::Uploader.new(self) Locomotive::Liquid::Drops::Uploader.new(self)
end end

View File

@ -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 => 'Title', :type => 'string'
@content_type.entries_custom_fields.build :label => 'Description', :type => 'text' @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 => 'Visible ?', :type => 'boolean', :name => 'visible'
@content_type.entries_custom_fields.build :label => 'File', :type => 'file'
@content_type.valid? @content_type.valid?
@content_type.send(:set_default_values) @content_type.send(:set_default_values)
end end
@ -127,6 +128,12 @@ describe Locomotive::ContentEntry do
@content_entry._permalink.should == 'my-test' @content_entry._permalink.should == 'my-test'
end 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 end
describe '#visibility' do describe '#visibility' do