2010-05-30 23:57:33 +00:00
|
|
|
require 'spec_helper'
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-30 23:57:33 +00:00
|
|
|
describe Locomotive::Liquid::Filters::Html do
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-30 23:57:33 +00:00
|
|
|
include Locomotive::Liquid::Filters::Html
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-10-12 15:26:05 +00:00
|
|
|
before(:each) do
|
|
|
|
@context = build_context
|
|
|
|
end
|
|
|
|
|
2011-07-19 14:40:58 +00:00
|
|
|
it 'should return a url for a stylesheet file' do
|
|
|
|
result = "/sites/000000000000000000000042/theme/stylesheets/main.css"
|
|
|
|
stylesheet_url('main.css').should == result
|
|
|
|
stylesheet_url('main').should == result
|
|
|
|
stylesheet_url(nil).should == ''
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should return a url for a stylesheet file with folder' do
|
|
|
|
result = "/sites/000000000000000000000042/theme/stylesheets/trash/main.css"
|
|
|
|
stylesheet_url('trash/main.css').should == result
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should return a url for a stylesheet file without touching the url' do
|
|
|
|
result = "/trash/main.css"
|
|
|
|
stylesheet_url('/trash/main.css').should == result
|
|
|
|
stylesheet_url('/trash/main').should == result
|
|
|
|
end
|
|
|
|
|
2010-05-30 23:57:33 +00:00
|
|
|
it 'should return a link tag for a stylesheet file' do
|
2011-01-26 13:07:33 +00:00
|
|
|
result = "<link href=\"/sites/000000000000000000000042/theme/stylesheets/main.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />"
|
2010-05-30 23:57:33 +00:00
|
|
|
stylesheet_tag('main.css').should == result
|
|
|
|
stylesheet_tag('main').should == result
|
|
|
|
stylesheet_tag(nil).should == ''
|
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-10-12 15:26:05 +00:00
|
|
|
it 'should return a link tag for a stylesheet file with folder' do
|
2011-01-26 13:07:33 +00:00
|
|
|
result = "<link href=\"/sites/000000000000000000000042/theme/stylesheets/trash/main.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />"
|
2010-10-12 15:26:05 +00:00
|
|
|
stylesheet_tag('trash/main.css').should == result
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should return a link tag for a stylesheet file without touching the url' do
|
|
|
|
result = "<link href=\"/trash/main.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />"
|
|
|
|
stylesheet_tag('/trash/main.css').should == result
|
|
|
|
stylesheet_tag('/trash/main').should == result
|
|
|
|
end
|
2011-07-01 00:15:45 +00:00
|
|
|
|
2011-04-11 07:22:41 +00:00
|
|
|
it 'should return a link tag for a stylesheet file and media attribute set to print' do
|
|
|
|
result = "<link href=\"/sites/000000000000000000000042/theme/stylesheets/main.css\" media=\"print\" rel=\"stylesheet\" type=\"text/css\" />"
|
|
|
|
stylesheet_tag('main.css','print').should == result
|
|
|
|
stylesheet_tag('main','print').should == result
|
|
|
|
stylesheet_tag(nil).should == ''
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should return a link tag for a stylesheet file with folder and media attribute set to print' do
|
|
|
|
result = "<link href=\"/sites/000000000000000000000042/theme/stylesheets/trash/main.css\" media=\"print\" rel=\"stylesheet\" type=\"text/css\" />"
|
|
|
|
stylesheet_tag('trash/main.css','print').should == result
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should return a link tag for a stylesheet file without touching the url and media attribute set to print' do
|
|
|
|
result = "<link href=\"/trash/main.css\" media=\"print\" rel=\"stylesheet\" type=\"text/css\" />"
|
|
|
|
stylesheet_tag('/trash/main.css','print').should == result
|
|
|
|
stylesheet_tag('/trash/main','print').should == result
|
|
|
|
end
|
2010-10-12 15:26:05 +00:00
|
|
|
|
2011-07-19 14:40:58 +00:00
|
|
|
it 'should return a url for a javascript file' do
|
|
|
|
result = "/sites/000000000000000000000042/theme/javascripts/main.js"
|
|
|
|
javascript_url('main.js').should == result
|
|
|
|
javascript_url('main').should == result
|
|
|
|
javascript_url(nil).should == ''
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should return a url for a javascript file with folder' do
|
|
|
|
result = "/sites/000000000000000000000042/theme/javascripts/trash/main.js"
|
|
|
|
javascript_url('trash/main.js').should == result
|
|
|
|
javascript_url('trash/main').should == result
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should return a url for a javascript file without touching the url' do
|
|
|
|
result = "/trash/main.js"
|
|
|
|
javascript_url('/trash/main.js').should == result
|
|
|
|
javascript_url('/trash/main').should == result
|
|
|
|
end
|
|
|
|
|
2010-05-30 23:57:33 +00:00
|
|
|
it 'should return a script tag for a javascript file' do
|
2011-01-26 13:07:33 +00:00
|
|
|
result = %{<script src="/sites/000000000000000000000042/theme/javascripts/main.js" type="text/javascript"></script>}
|
2010-05-30 23:57:33 +00:00
|
|
|
javascript_tag('main.js').should == result
|
|
|
|
javascript_tag('main').should == result
|
|
|
|
javascript_tag(nil).should == ''
|
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-10-12 15:26:05 +00:00
|
|
|
it 'should return a script tag for a javascript file with folder' do
|
2011-01-26 13:07:33 +00:00
|
|
|
result = %{<script src="/sites/000000000000000000000042/theme/javascripts/trash/main.js" type="text/javascript"></script>}
|
2010-10-12 15:26:05 +00:00
|
|
|
javascript_tag('trash/main.js').should == result
|
|
|
|
javascript_tag('trash/main').should == result
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should return a script tag for a javascript file without touching the url' do
|
|
|
|
result = %{<script src="/trash/main.js" type="text/javascript"></script>}
|
|
|
|
javascript_tag('/trash/main.js').should == result
|
|
|
|
javascript_tag('/trash/main').should == result
|
|
|
|
end
|
2011-04-24 23:21:38 +00:00
|
|
|
|
2011-02-15 07:33:52 +00:00
|
|
|
it 'should return an image tag for a given theme file without parameters' do
|
|
|
|
theme_image_tag('foo.jpg').should == "<img src=\"/sites/000000000000000000000042/theme/images/foo.jpg\" />"
|
|
|
|
end
|
2011-04-24 23:21:38 +00:00
|
|
|
|
2011-02-15 07:33:52 +00:00
|
|
|
it 'should return an image tag for a given theme file with size' do
|
|
|
|
theme_image_tag('foo.jpg', 'width:100', 'height:100').should == "<img src=\"/sites/000000000000000000000042/theme/images/foo.jpg\" height=\"100\" width=\"100\" />"
|
|
|
|
end
|
2010-10-12 15:26:05 +00:00
|
|
|
|
2010-10-29 15:40:58 +00:00
|
|
|
it 'should return an image tag without parameters' do
|
|
|
|
image_tag('foo.jpg').should == "<img src=\"foo.jpg\" />"
|
2010-05-30 23:57:33 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-30 23:57:33 +00:00
|
|
|
it 'should return an image tag with size' do
|
2010-10-29 15:40:58 +00:00
|
|
|
image_tag('foo.jpg', 'width:100', 'height:50').should == "<img src=\"foo.jpg\" height=\"50\" width=\"100\" />"
|
2010-05-30 23:57:33 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-30 23:57:33 +00:00
|
|
|
it 'should return a flash tag without parameters' do
|
|
|
|
flash_tag('foo.flv').should == %{
|
|
|
|
<object>
|
|
|
|
<param name="movie" value="foo.flv" />
|
|
|
|
<embed src="foo.flv" />
|
|
|
|
</embed>
|
|
|
|
</object>
|
|
|
|
}.strip
|
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-30 23:57:33 +00:00
|
|
|
it 'should return a flash tag with size' do
|
|
|
|
flash_tag('foo.flv', 'width:100', 'height:50').should == %{
|
|
|
|
<object height=\"50\" width=\"100\">
|
|
|
|
<param name="movie" value="foo.flv" />
|
|
|
|
<embed src="foo.flv" height=\"50\" width=\"100\" />
|
|
|
|
</embed>
|
|
|
|
</object>
|
|
|
|
}.strip
|
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-30 23:57:33 +00:00
|
|
|
it 'should return a navigation block for the pagination' do
|
2010-07-23 20:09:54 +00:00
|
|
|
pagination = {
|
|
|
|
"previous" => nil,
|
2010-05-30 23:57:33 +00:00
|
|
|
"parts" => [
|
|
|
|
{ 'title' => '1', 'is_link' => false },
|
|
|
|
{ 'title' => '2', 'is_link' => true, 'url' => '/?page=2' },
|
|
|
|
{ 'title' => '…', 'is_link' => false, 'hellip_break' => true },
|
|
|
|
{ 'title' => '5', 'is_link' => true, 'url' => '/?page=5' }
|
|
|
|
],
|
|
|
|
"next" => { 'title' => 'next', 'is_link' => true, 'url' => '/?page=2' }
|
|
|
|
}
|
|
|
|
html = default_pagination(pagination, 'css:flickr_pagination')
|
|
|
|
html.should match(/<div class="pagination flickr_pagination">/)
|
|
|
|
html.should match(/<span class="disabled prev_page">« Previous<\/span>/)
|
2010-07-23 20:09:54 +00:00
|
|
|
html.should match(/<a href="\/\?page=2">2<\/a>/)
|
2010-05-30 23:57:33 +00:00
|
|
|
html.should match(/<span class=\"gap\">\…<\/span>/)
|
|
|
|
html.should match(/<a href="\/\?page=2" class="next_page">Next »<\/a>/)
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-30 23:57:33 +00:00
|
|
|
pagination.merge!({
|
|
|
|
'previous' => { 'title' => 'previous', 'is_link' => true, 'url' => '/?page=4' },
|
2010-07-23 20:09:54 +00:00
|
|
|
'next' => nil
|
2010-05-30 23:57:33 +00:00
|
|
|
})
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-30 23:57:33 +00:00
|
|
|
html = default_pagination(pagination, 'css:flickr_pagination')
|
|
|
|
html.should_not match(/<span class="disabled prev_page">« Previous<\/span>/)
|
|
|
|
html.should match(/<a href="\/\?page=4" class="prev_page">« Previous<\/a>/)
|
|
|
|
html.should match(/<span class="disabled next_page">Next »<\/span>/)
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-30 23:57:33 +00:00
|
|
|
pagination.merge!({ 'parts' => [] })
|
|
|
|
html = default_pagination(pagination, 'css:flickr_pagination')
|
|
|
|
html.should == ''
|
|
|
|
end
|
|
|
|
|
2010-10-12 15:26:05 +00:00
|
|
|
def build_context
|
|
|
|
klass = Class.new
|
|
|
|
klass.class_eval do
|
|
|
|
def registers
|
2011-01-26 13:07:33 +00:00
|
|
|
{ :site => Factory.build(:site, :id => fake_bson_id(42)) }
|
|
|
|
end
|
|
|
|
|
|
|
|
def fake_bson_id(id)
|
|
|
|
BSON::ObjectId(id.to_s.rjust(24, '0'))
|
2010-10-12 15:26:05 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
klass.new
|
|
|
|
end
|
|
|
|
|
2010-07-23 20:09:54 +00:00
|
|
|
end
|