new liquid filter: default
This commit is contained in:
parent
90e1c4f438
commit
2329f26e4d
@ -33,6 +33,10 @@ module Locomotive
|
|||||||
input.last
|
input.last
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def default(input, value)
|
||||||
|
input.blank? ? value : input
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
::Liquid::Template.register_filter(Misc)
|
::Liquid::Template.register_filter(Misc)
|
||||||
|
@ -4,7 +4,7 @@ describe Locomotive::Liquid::Filters::Misc do
|
|||||||
|
|
||||||
include Locomotive::Liquid::Filters::Misc
|
include Locomotive::Liquid::Filters::Misc
|
||||||
|
|
||||||
it 'should underscore an input' do
|
it 'underscores an input' do
|
||||||
underscore('foo').should == 'foo'
|
underscore('foo').should == 'foo'
|
||||||
underscore('home page').should == 'home_page'
|
underscore('home page').should == 'home_page'
|
||||||
underscore('My foo Bar').should == 'my_foo_bar'
|
underscore('My foo Bar').should == 'my_foo_bar'
|
||||||
@ -12,19 +12,19 @@ describe Locomotive::Liquid::Filters::Misc do
|
|||||||
underscore('foo/bar/index').should == 'foo_bar_index'
|
underscore('foo/bar/index').should == 'foo_bar_index'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should dasherize an input' do
|
it 'dasherizes an input' do
|
||||||
dasherize('foo').should == 'foo'
|
dasherize('foo').should == 'foo'
|
||||||
dasherize('foo_bar').should == 'foo-bar'
|
dasherize('foo_bar').should == 'foo-bar'
|
||||||
dasherize('foo/bar').should == 'foo-bar'
|
dasherize('foo/bar').should == 'foo-bar'
|
||||||
dasherize('foo/bar/index').should == 'foo-bar-index'
|
dasherize('foo/bar/index').should == 'foo-bar-index'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should concat strings' do
|
it 'concats strings' do
|
||||||
concat('foo', 'bar').should == 'foobar'
|
concat('foo', 'bar').should == 'foobar'
|
||||||
concat('hello', 'foo', 'bar').should == 'hellofoobar'
|
concat('hello', 'foo', 'bar').should == 'hellofoobar'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should return the input string every n occurences' do
|
it 'returns the input string every n occurences' do
|
||||||
modulo('foo', 0, 3).should == ''
|
modulo('foo', 0, 3).should == ''
|
||||||
modulo('foo', 1, 3).should == ''
|
modulo('foo', 1, 3).should == ''
|
||||||
modulo('foo', 2, 3).should == 'foo'
|
modulo('foo', 2, 3).should == 'foo'
|
||||||
@ -33,4 +33,10 @@ describe Locomotive::Liquid::Filters::Misc do
|
|||||||
modulo('foo', 5, 3).should == 'foo'
|
modulo('foo', 5, 3).should == 'foo'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'returns default values if the input is empty' do
|
||||||
|
default('foo', 42).should == 'foo'
|
||||||
|
default('', 42).should == 42
|
||||||
|
default(nil, 42).should == 42
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user