padrino-helpers 0.9.24 → 0.9.25

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/lib/padrino-helpers.rb +0 -1
  2. data/lib/padrino-helpers/asset_tag_helpers.rb +2 -2
  3. data/lib/padrino-helpers/form_builder/abstract_form_builder.rb +1 -1
  4. data/lib/padrino-helpers/form_helpers.rb +57 -12
  5. data/lib/padrino-helpers/format_helpers.rb +8 -6
  6. data/lib/padrino-helpers/output_helpers.rb +28 -8
  7. data/lib/padrino-helpers/output_helpers/abstract_handler.rb +17 -10
  8. data/lib/padrino-helpers/output_helpers/erb_handler.rb +31 -32
  9. data/lib/padrino-helpers/output_helpers/haml_handler.rb +13 -4
  10. data/lib/padrino-helpers/output_helpers/slim_handler.rb +82 -0
  11. data/lib/padrino-helpers/render_helpers.rb +1 -1
  12. data/lib/padrino-helpers/tag_helpers.rb +1 -1
  13. data/test/fixtures/markup_app/app.rb +6 -4
  14. data/test/fixtures/markup_app/views/capture_concat.slim +13 -0
  15. data/test/fixtures/markup_app/views/content_for.slim +9 -0
  16. data/test/fixtures/markup_app/views/content_tag.slim +9 -0
  17. data/test/fixtures/markup_app/views/current_engine.erb +5 -0
  18. data/test/fixtures/markup_app/views/current_engine.haml +5 -0
  19. data/test/fixtures/markup_app/views/current_engine.slim +5 -0
  20. data/test/fixtures/markup_app/views/fields_for.erb +1 -1
  21. data/test/fixtures/markup_app/views/fields_for.haml +7 -7
  22. data/test/fixtures/markup_app/views/fields_for.slim +15 -0
  23. data/test/fixtures/markup_app/views/form_for.slim +47 -0
  24. data/test/fixtures/markup_app/views/form_tag.slim +45 -0
  25. data/test/fixtures/markup_app/views/link_to.slim +4 -0
  26. data/test/fixtures/markup_app/views/mail_to.slim +3 -0
  27. data/test/fixtures/markup_app/views/meta_tag.slim +3 -0
  28. data/test/fixtures/markup_app/views/partials/_erb.erb +1 -0
  29. data/test/fixtures/markup_app/views/partials/_haml.haml +1 -0
  30. data/test/fixtures/markup_app/views/partials/_slim.slim +1 -0
  31. data/test/fixtures/render_app/app.rb +10 -0
  32. data/test/fixtures/render_app/views/current_engine.haml +5 -0
  33. data/test/fixtures/render_app/views/current_engines/_erb.erb +1 -0
  34. data/test/fixtures/render_app/views/current_engines/_haml.haml +1 -0
  35. data/test/fixtures/render_app/views/current_engines/_slim.slim +1 -0
  36. data/test/helper.rb +1 -12
  37. data/test/test_asset_tag_helpers.rb +48 -0
  38. data/test/test_form_builder.rb +159 -6
  39. data/test/test_form_helpers.rb +165 -4
  40. data/test/test_format_helpers.rb +19 -2
  41. data/test/test_output_helpers.rb +53 -0
  42. data/test/test_render_helpers.rb +11 -0
  43. data/test/test_tag_helpers.rb +20 -0
  44. metadata +27 -9
  45. data/lib/padrino-helpers/dom_helpers.rb +0 -46
  46. data/test/test_dom_helpers.rb +0 -37
@@ -1,6 +1,5 @@
1
1
  module Padrino
2
2
  module Helpers
3
-
4
3
  module OutputHelpers
5
4
  class HamlHandler < AbstractHandler
6
5
  ##
@@ -46,9 +45,19 @@ module Padrino
46
45
  template.haml_concat(text)
47
46
  nil
48
47
  end
49
- end # HamlHandler
50
48
 
49
+ ##
50
+ # Returns an array of engines used for the template
51
+ #
52
+ # ==== Examples
53
+ #
54
+ # @handler.engines => [:erb, :erubis]
55
+ #
56
+ def engines
57
+ @_engines ||= [:haml]
58
+ end
59
+ end # HamlHandler
51
60
  OutputHelpers.register(HamlHandler)
52
61
  end # OutputHelpers
53
- end
54
- end
62
+ end # Helpers
63
+ end # Padrino
@@ -0,0 +1,82 @@
1
+ # Make slim works with sinatra/padrino
2
+ Slim::Engine.set_default_options(:buffer => '@_out_buf', :generator => Temple::Generators::StringBuffer) if defined?(Slim)
3
+
4
+ module Padrino
5
+ module Helpers
6
+ module OutputHelpers
7
+ class SlimHandler < AbstractHandler
8
+ attr_reader :output_buffer
9
+
10
+ def initialize(template)
11
+ super
12
+ @output_buffer = template.instance_variable_get(:@_out_buf)
13
+ end
14
+
15
+ ##
16
+ # Returns true if the current template type is same as this handlers; false otherwise.
17
+ #
18
+ # ==== Examples
19
+ #
20
+ # @handler.is_type? => true
21
+ #
22
+ def is_type?
23
+ !self.output_buffer.nil?
24
+ end
25
+
26
+ # Captures the html from a block of template code for this handler
27
+ #
28
+ # ==== Examples
29
+ #
30
+ # @handler.capture_from_template(&block) => "...html..."
31
+ #
32
+ def capture_from_template(*args, &block)
33
+ self.output_buffer, _buf_was = "", self.output_buffer
34
+ block.call(*args)
35
+ ret = eval("@_out_buf", block.binding)
36
+ self.output_buffer = _buf_was
37
+ ret
38
+ end
39
+
40
+ ##
41
+ # Outputs the given text to the templates buffer directly
42
+ #
43
+ # ==== Examples
44
+ #
45
+ # @handler.concat_to_template("This will be output to the template buffer")
46
+ #
47
+ def concat_to_template(text="")
48
+ self.output_buffer << text if is_type? && text
49
+ nil
50
+ end
51
+
52
+ ##
53
+ # Returns true if the block given is of the handler's template type; false otherwise.
54
+ #
55
+ # ==== Examples
56
+ #
57
+ # @handler.block_is_type?(block) => true
58
+ #
59
+ def block_is_type?(block)
60
+ is_type? || (block && eval('defined? __in_erb_template', block.binding))
61
+ end
62
+
63
+ ##
64
+ # Returns an array of engines used for the template
65
+ #
66
+ # ==== Examples
67
+ #
68
+ # @handler.engines => [:erb, :erubis]
69
+ #
70
+ def engines
71
+ @_engines ||= [:slim]
72
+ end
73
+
74
+ protected
75
+ def output_buffer=(val)
76
+ template.instance_variable_set(:@_out_buf, val)
77
+ end
78
+ end # ErbHandler
79
+ OutputHelpers.register(SlimHandler)
80
+ end # OutputHelpers
81
+ end # Helpers
82
+ end # Padrino
@@ -20,7 +20,7 @@ module Padrino
20
20
  if collection = options.delete(:collection)
21
21
  options.delete(:object)
22
22
  counter = 0
23
- collection.collect { |member|
23
+ collection.map { |member|
24
24
  counter += 1
25
25
  options[:locals].merge!(object_name => member, "#{object_name}_counter".to_sym => counter)
26
26
  render(template_path, nil, options.dup)
@@ -42,7 +42,7 @@ module Padrino
42
42
  content, open_tag = options.delete(:content), options.delete(:open)
43
43
  content = content.join("\n") if content.respond_to?(:join)
44
44
  identity_tag_attributes.each { |attr| options[attr] = attr.to_s if options[attr] }
45
- html_attrs = options.collect { |a, v| v.nil? || v == false ? nil : "#{a}=\"#{v}\"" }.compact.join(" ")
45
+ html_attrs = options.map { |a, v| v.nil? || v == false ? nil : "#{a}=\"#{v}\"" }.compact.join(" ")
46
46
  base_tag = (html_attrs.present? ? "<#{name} #{html_attrs}" : "<#{name}")
47
47
  base_tag << (open_tag ? ">" : (content ? ">#{content}</#{name}>" : " />"))
48
48
  end
@@ -1,5 +1,7 @@
1
1
  require 'sinatra/base'
2
2
  require 'haml'
3
+ require 'erubis'
4
+ require 'slim'
3
5
 
4
6
  class MarkupDemo < Sinatra::Base
5
7
  register Padrino::Helpers
@@ -28,15 +30,15 @@ class MarkupDemo < Sinatra::Base
28
30
  concat_content "<p>#{content_html}</p>"
29
31
  end
30
32
 
33
+ def determine_block_is_template(name, &block)
34
+ concat_content "<p class='is_template'>The #{name} block passed in is a template</p>" if block_is_template?(block)
35
+ end
36
+
31
37
  def ruby_not_template_block
32
38
  determine_block_is_template('ruby') do
33
39
  content_tag(:span, "This not a template block")
34
40
  end
35
41
  end
36
-
37
- def determine_block_is_template(name, &block)
38
- concat_content "<p class='is_template'>The #{name} block passed in is a template</p>" if block_is_template?(block)
39
- end
40
42
  end
41
43
  end
42
44
 
@@ -0,0 +1,13 @@
1
+ -@content = captured_content do
2
+ span Captured Line 1
3
+ span Captured Line 2
4
+
5
+ ==@content
6
+
7
+ ==determine_block_is_template('slim') do
8
+ span This is slim
9
+ span This is slim
10
+
11
+ ==concat_in_p('Concat Line 3')
12
+
13
+ ==ruby_not_template_block
@@ -0,0 +1,9 @@
1
+ - content_for :demo do
2
+ h1 This is content yielded from a content_for
3
+
4
+ .demo== yield_content :demo
5
+
6
+ - content_for :demo2 do |fname, lname|
7
+ h1 This is content yielded with name #{fname + " " + lname}
8
+
9
+ .demo2== yield_content :demo2, "Johnny", "Smith"
@@ -0,0 +1,9 @@
1
+ ==content_tag :p, "Test 1", :class => 'test', :id => "test1"
2
+
3
+ == content_tag :p, "Test 2"
4
+
5
+ ==content_tag(:p, :class => 'test', :id => 'test3') do
6
+ span Test 3
7
+
8
+ ==content_tag(:p) do
9
+ span Test 4
@@ -0,0 +1,5 @@
1
+ <p class="start"><%= current_engine %></p>
2
+ <p class="haml"><%= haml :'partials/_haml' %></p>
3
+ <p class="erb"><%= erb :'partials/_erb' %></p>
4
+ <p class="slim"><%= slim :'partials/_slim' %></p>
5
+ <p class="end"><%= current_engine %></p>
@@ -0,0 +1,5 @@
1
+ %p.start= current_engine
2
+ %p.haml= haml :'partials/_haml'
3
+ %p.erb= erb :'partials/_erb'
4
+ %p.slim= slim :'partials/_slim'
5
+ %p.end= current_engine
@@ -0,0 +1,5 @@
1
+ p.start= current_engine
2
+ p.haml= haml :'partials/_haml'
3
+ p.erb= erb :'partials/_erb'
4
+ p.slim= slim :'partials/_slim'
5
+ p.end= current_engine
@@ -7,7 +7,7 @@
7
7
  <% end %>
8
8
  <% f.fields_for :telephone do |child_form| %>
9
9
  <%= child_form.label :number %>
10
- <%= child_form.text_field :number %>
10
+ <%= child_form.text_field :number %>
11
11
  <% end %>
12
12
  <% f.fields_for :addresses do |child_form| %>
13
13
  <%= child_form.label :name %>
@@ -6,10 +6,10 @@
6
6
  = permission.check_box :can_delete
7
7
  - f.fields_for :telephone do |child_form|
8
8
  = child_form.label :number
9
- = child_form.text_field :number
10
- - f.fields_for :addresses do |child_form|
11
- = child_form.label :name
12
- = child_form.text_field :name
13
- - unless child_form.object.new_record?
14
- = child_form.check_box '_destroy'
15
- = child_form.label '_destroy', :caption => 'Remove'
9
+ = child_form.text_field :number
10
+ - f.fields_for :addresses do |child_form|
11
+ = child_form.label :name
12
+ = child_form.text_field :name
13
+ - unless child_form.object.new_record?
14
+ = child_form.check_box '_destroy'
15
+ = child_form.label '_destroy', :caption => 'Remove'
@@ -0,0 +1,15 @@
1
+ - @user = MarkupUser.new
2
+ == form_for @user , '/demo1', :id => 'demo-fields-for' do |f|
3
+ == f.text_field :gender
4
+ == fields_for @user.permission do |permission|
5
+ == permission.check_box :can_edit
6
+ == permission.check_box :can_delete
7
+ == f.fields_for :telephone do |child_form|
8
+ == child_form.label :number
9
+ == child_form.text_field :number
10
+ == f.fields_for :addresses do |child_form|
11
+ == child_form.label :name
12
+ == child_form.text_field :name
13
+ - unless child_form.object.new_record?
14
+ == child_form.check_box '_destroy'
15
+ == child_form.label '_destroy', :caption => 'Remove'
@@ -0,0 +1,47 @@
1
+ == form_for MarkupUser.new, '/demo', :id => 'demo' do |f|
2
+ == f.error_messages(:header_message => "custom MarkupUser cannot be saved!")
3
+ == f.hidden_field :session_id
4
+ p
5
+ == f.label :username, :caption => "Login: ", :class => 'user-label'
6
+ == f.text_field :username, :class => 'user-text', :value => "John"
7
+ p
8
+ == f.label :email, :caption => "Email", :class => 'user-email'
9
+ == f.text_field :email
10
+ p
11
+ == f.label :password
12
+ == f.password_field :password, :class => 'user-password', :value => "secret"
13
+ p
14
+ == f.label :photo
15
+ == f.file_field :photo, :class => 'user-photo'
16
+ p
17
+ == f.label :about, :caption => "About Me: "
18
+ == f.text_area :about, :class => 'user-about'
19
+ p
20
+ == f.label :gender, :caption => "Your gender: "
21
+ == f.radio_button :gender, :value => 'male'
22
+ == f.radio_button :gender, :value => 'female'
23
+ p
24
+ == f.label :country, :caption => "Your country"
25
+ == f.select :country, :options => ['USA', 'Canada', 'Mexico'], :selected => 'USA', :class => 'selector'
26
+ p
27
+ == f.label :remember_me
28
+ == f.check_box :remember_me, :value => "1"
29
+ p
30
+ == f.submit "Create", :class => 'success', :id => 'demo-button'
31
+ p
32
+ == f.image_submit "buttons/post.png", :class => 'success', :id => 'image-button'
33
+
34
+ == form_for MarkupUser.new, '/another_demo', :id => 'demo2', :method => 'get' do |f|
35
+ == f.error_messages :header_message => "custom MarkupUser cannot be saved!"
36
+ == f.hidden_field :session_id
37
+ == f.text_field_block :username, { :class => 'input' }, { :caption => 'Nickname: ', :class => 'label' }
38
+ == f.password_field_block :code, { :class => 'input' }
39
+ == f.text_area_block :about, { :class => 'textarea' }
40
+ == f.file_field_block :photo, { :class => 'upload' }
41
+ == f.check_box_block :remember_me, { :class => 'checker' }
42
+ == f.select_block :state, :options => ['California', 'Texas'], :class => 'selector'
43
+ == f.submit_block "Create", { :class => 'button' }
44
+ == f.image_submit_block "buttons/ok.png", { :class => 'image' }
45
+
46
+ == form_for :markup_user, '/third_demo', :id => 'demo3', :method => 'get' do |f|
47
+ == f.text_field_block :username
@@ -0,0 +1,45 @@
1
+ == form_tag '/simple', :class => 'simple-form' do
2
+ == error_messages_for nil
3
+ == field_set_tag do
4
+ == hidden_field_tag :session_id, :value => "__secret__"
5
+ == label_tag :username
6
+ == text_field_tag :username
7
+ == label_tag :password
8
+ == password_field_tag :password
9
+ == label_tag :color
10
+ == select_tag :color, :options => ['green', 'orange', 'purple']
11
+ == label_tag :gender
12
+ == radio_button_tag :gender, :value => 'male'
13
+ == radio_button_tag :gender, :value => 'female'
14
+ == check_box_tag :remember_me
15
+ == submit_tag
16
+
17
+ == form_tag '/advanced', :id => 'advanced', :class => 'advanced-form', :method => 'get' do
18
+ == error_messages_for MarkupUser.new, :header_message => "There are problems with saving user!"
19
+ == hidden_field_tag :session_id, :value => "__secret__"
20
+ == field_set_tag "Advanced", :class => 'advanced-field-set' do
21
+ p
22
+ == label_tag :username, :class => 'first', :caption => "Nickname"
23
+ == text_field_tag :username, :value => params[:username], :id => 'the_username'
24
+ p
25
+ == label_tag :password, :class => 'first'
26
+ == password_field_tag :password, :value => params[:password]
27
+ p
28
+ == label_tag :about, :class => 'about', :caption => "About Me"
29
+ == text_area_tag :about, :class => 'large'
30
+ p
31
+ == label_tag :gender, :class => 'gender'
32
+ == radio_button_tag :gender, :value => 'male', :checked => true
33
+ == radio_button_tag :gender, :value => 'female'
34
+ p
35
+ == label_tag :photo, :class => 'photo'
36
+ == file_field_tag :photo, :class => 'upload'
37
+ p
38
+ == label_tag :fav_color
39
+ == select_tag :fav_color, :options => [ ['green', '1'], ['orange', '2'], ['purple', '3'] ], :selected => '2'
40
+ p
41
+ == check_box_tag :remember_me, :value => "1", :checked => true
42
+ == field_set_tag(:class => 'buttons') do
43
+ == submit_tag "Login"
44
+ == button_tag "Cancel"
45
+ == image_submit_tag "buttons/submit.png"
@@ -0,0 +1,4 @@
1
+ = link_to "Test 1 No Block", '/test1', :class => 'test', :id => 'test1'
2
+
3
+ - link_to("/test2", :class => 'test', :id => 'test2') do
4
+ span Test 2 With Block
@@ -0,0 +1,3 @@
1
+ p.simple== mail_to 'test@demo.com'
2
+
3
+ p.captioned== mail_to 'test@demo.com', "Click my Email"
@@ -0,0 +1,3 @@
1
+ == meta_tag "weblog,news", :name => "keywords"
2
+
3
+ == meta_tag "text/html; charset=UTF-8", :"http-equiv" => "Content-Type"
@@ -0,0 +1 @@
1
+ <%= current_engine %>
@@ -0,0 +1 @@
1
+ =current_engine
@@ -0,0 +1 @@
1
+ =current_engine
@@ -11,6 +11,16 @@ end
11
11
  class RenderDemo < Padrino::Application
12
12
  register Padrino::Helpers
13
13
 
14
+ configure do
15
+ set :logging, false
16
+ set :padrino_logging, false
17
+ end
18
+
19
+ # get current engines from partials
20
+ get '/current_engine' do
21
+ render :current_engine
22
+ end
23
+
14
24
  # partial with object
15
25
  get '/partial/object' do
16
26
  partial 'template/user', :object => RenderUser.new('John'), :locals => { :extra => "bar" }
@@ -0,0 +1,5 @@
1
+ %p.start= current_engine
2
+ %p.haml= partial 'current_engines/haml'
3
+ %p.erb= partial 'current_engines/erb'
4
+ %p.slim= partial 'current_engines/slim'
5
+ %p.end= current_engine
@@ -0,0 +1 @@
1
+ <%= current_engine %>
@@ -5,18 +5,7 @@ require 'mocha'
5
5
  require 'rack/test'
6
6
  require 'webrat'
7
7
  require 'padrino-helpers'
8
-
9
- # We need some extension for do our tests
10
- begin
11
- # As 2.3.x
12
- require 'active_support/core_ext/date'
13
- require 'active_support/core_ext/time'
14
- require 'active_support/core_ext/numeric'
15
- require 'active_support/duration'
16
- rescue LoadError
17
- # As 3.x
18
- require 'active_support/time'
19
- end
8
+ require 'active_support/time'
20
9
 
21
10
  class Test::Unit::TestCase
22
11
  include Padrino::Helpers::OutputHelpers
@@ -26,39 +26,48 @@ class TestAssetTagHelpers < Test::Unit::TestCase
26
26
  should "display link element with no given attributes" do
27
27
  assert_has_tag('a', :content => "Sign up", :href => '/register') { link_to('Sign up', '/register') }
28
28
  end
29
+
29
30
  should "display link element with given attributes" do
30
31
  actual_html = link_to('Sign up', '/register', :class => 'first', :id => 'linky')
31
32
  assert_has_tag('a#linky.first', :content => "Sign up", :href => '/register') { actual_html }
32
33
  end
34
+
33
35
  should "display link element with anchor attribute" do
34
36
  actual_html = link_to("Anchor", "/anchor", :anchor => :foo)
35
37
  assert_has_tag('a', :content => "Anchor", :href => '/anchor#foo') { actual_html }
36
38
  end
39
+
37
40
  should "display link element with void url and options" do
38
41
  actual_link = link_to('Sign up', :class => "test")
39
42
  assert_has_tag('a', :content => "Sign up", :href => 'javascript:void(0);', :class => 'test') { actual_link }
40
43
  end
44
+
41
45
  should "display link element with remote option" do
42
46
  actual_link = link_to('Sign up', '/register', :remote => true)
43
47
  assert_has_tag('a', :content => "Sign up", :href => '/register', 'data-remote' => 'true') { actual_link }
44
48
  end
49
+
45
50
  should "display link element with method option" do
46
51
  actual_link = link_to('Sign up', '/register', :method => :delete)
47
52
  assert_has_tag('a', :content => "Sign up", :href => '/register', 'data-method' => 'delete', :rel => 'nofollow') { actual_link }
48
53
  end
54
+
49
55
  should "display link element with confirm option" do
50
56
  actual_link = link_to('Sign up', '/register', :confirm => "Are you sure?")
51
57
  assert_has_tag('a', :content => "Sign up", :href => '/register', 'data-confirm' => 'Are you sure?') { actual_link }
52
58
  end
59
+
53
60
  should "display link element with ruby block" do
54
61
  actual_link = link_to('/register', :class => 'first', :id => 'binky') { "Sign up" }
55
62
  assert_has_tag('a#binky.first', :content => "Sign up", :href => '/register') { actual_link }
56
63
  end
64
+
57
65
  should "display link block element in haml" do
58
66
  visit '/haml/link_to'
59
67
  assert_have_selector :a, :content => "Test 1 No Block", :href => '/test1', :class => 'test', :id => 'test1'
60
68
  assert_have_selector :a, :content => "Test 2 With Block", :href => '/test2', :class => 'test', :id => 'test2'
61
69
  end
70
+
62
71
  should "display link block element in erb" do
63
72
  visit '/erb/link_to'
64
73
  assert_have_selector :a, :content => "Test 1 No Block", :href => '/test1', :class => 'test', :id => 'test1'
@@ -96,6 +105,12 @@ class TestAssetTagHelpers < Test::Unit::TestCase
96
105
  assert_have_selector 'p.simple a', :href => 'mailto:test@demo.com', :content => 'test@demo.com'
97
106
  assert_have_selector 'p.captioned a', :href => 'mailto:test@demo.com', :content => 'Click my Email'
98
107
  end
108
+
109
+ should "display mail link element in slim" do
110
+ visit '/slim/mail_to'
111
+ assert_have_selector 'p.simple a', :href => 'mailto:test@demo.com', :content => 'test@demo.com'
112
+ assert_have_selector 'p.captioned a', :href => 'mailto:test@demo.com', :content => 'Click my Email'
113
+ end
99
114
  end
100
115
 
101
116
  context 'for #meta_tag method' do
@@ -103,20 +118,29 @@ class TestAssetTagHelpers < Test::Unit::TestCase
103
118
  actual_html = meta_tag("weblog,news", :name => "keywords")
104
119
  assert_has_tag("meta", :name => "keywords", "content" => "weblog,news") { actual_html }
105
120
  end
121
+
106
122
  should "display meta tag with given content and http-equiv" do
107
123
  actual_html = meta_tag("text/html; charset=UTF-8", :"http-equiv" => "Content-Type")
108
124
  assert_has_tag("meta", :"http-equiv" => "Content-Type", "content" => "text/html; charset=UTF-8") { actual_html }
109
125
  end
126
+
110
127
  should "display meta tag element in haml" do
111
128
  visit '/haml/meta_tag'
112
129
  assert_have_selector 'meta', "content" => "weblog,news", :name => "keywords"
113
130
  assert_have_selector 'meta', "content" => "text/html; charset=UTF-8", :"http-equiv" => "Content-Type"
114
131
  end
132
+
115
133
  should "display meta tag element in erb" do
116
134
  visit '/erb/meta_tag'
117
135
  assert_have_selector 'meta', "content" => "weblog,news", :name => "keywords"
118
136
  assert_have_selector 'meta', "content" => "text/html; charset=UTF-8", :"http-equiv" => "Content-Type"
119
137
  end
138
+
139
+ should "display meta tag element in slim" do
140
+ visit '/slim/meta_tag'
141
+ assert_have_selector 'meta', "content" => "weblog,news", :name => "keywords"
142
+ assert_have_selector 'meta', "content" => "text/html; charset=UTF-8", :"http-equiv" => "Content-Type"
143
+ end
120
144
  end
121
145
 
122
146
  context 'for #image_tag method' do
@@ -124,29 +148,35 @@ class TestAssetTagHelpers < Test::Unit::TestCase
124
148
  time = stop_time_for_test
125
149
  assert_has_tag('img', :src => "/absolute/pic.gif?#{time.to_i}") { image_tag('/absolute/pic.gif') }
126
150
  end
151
+
127
152
  should "display image tag absolute link with specified uri root" do
128
153
  time = stop_time_for_test
129
154
  self.class.stubs(:uri_root).returns("/blog")
130
155
  assert_has_tag('img', :src => "/blog/images/relative/pic.gif?#{time.to_i}") { image_tag('relative/pic.gif') }
131
156
  end
157
+
132
158
  should "display image tag relative link with options" do
133
159
  time = stop_time_for_test
134
160
  assert_has_tag('img.photo', :src => "/images/relative/pic.gif?#{time.to_i}") {
135
161
  image_tag('relative/pic.gif', :class => 'photo') }
136
162
  end
163
+
137
164
  should "display image tag uri link with options" do
138
165
  time = stop_time_for_test
139
166
  assert_has_tag('img.photo', :src => "http://demo.org/pic.gif") { image_tag('http://demo.org/pic.gif', :class => 'photo') }
140
167
  end
168
+
141
169
  should "display image tag relative link with incorrect spacing" do
142
170
  time = stop_time_for_test
143
171
  assert_has_tag('img.photo', :src => "/images/%20relative/%20pic.gif%20%20?#{time.to_i}") {
144
172
  image_tag(' relative/ pic.gif ', :class => 'photo') }
145
173
  end
174
+
146
175
  should "not use a timestamp if stamp setting is false" do
147
176
  self.class.expects(:asset_stamp).returns(false)
148
177
  assert_has_tag('img', :src => "/absolute/pic.gif") { image_tag('/absolute/pic.gif') }
149
178
  end
179
+
150
180
  should "have xhtml convention tag" do
151
181
  self.class.expects(:asset_stamp).returns(false)
152
182
  assert_equal image_tag('/absolute/pic.gif'), '<img src="/absolute/pic.gif" />'
@@ -159,18 +189,21 @@ class TestAssetTagHelpers < Test::Unit::TestCase
159
189
  expected_options = { :media => "screen", :rel => "stylesheet", :type => "text/css" }
160
190
  assert_has_tag('link', expected_options.merge(:href => "/stylesheets/style.css?#{time.to_i}")) { stylesheet_link_tag('style') }
161
191
  end
192
+
162
193
  should "display stylesheet link item for long relative path" do
163
194
  time = stop_time_for_test
164
195
  expected_options = { :media => "screen", :rel => "stylesheet", :type => "text/css" }
165
196
  actual_html = stylesheet_link_tag('example/demo/style')
166
197
  assert_has_tag('link', expected_options.merge(:href => "/stylesheets/example/demo/style.css?#{time.to_i}")) { actual_html }
167
198
  end
199
+
168
200
  should "display stylesheet link item with absolute path" do
169
201
  time = stop_time_for_test
170
202
  expected_options = { :media => "screen", :rel => "stylesheet", :type => "text/css" }
171
203
  actual_html = stylesheet_link_tag('/css/style')
172
204
  assert_has_tag('link', expected_options.merge(:href => "/css/style.css?#{time.to_i}")) { actual_html }
173
205
  end
206
+
174
207
  should "display stylesheet link item with uri root" do
175
208
  self.class.stubs(:uri_root).returns("/blog")
176
209
  time = stop_time_for_test
@@ -178,6 +211,7 @@ class TestAssetTagHelpers < Test::Unit::TestCase
178
211
  actual_html = stylesheet_link_tag('style')
179
212
  assert_has_tag('link', expected_options.merge(:href => "/blog/stylesheets/style.css?#{time.to_i}")) { actual_html }
180
213
  end
214
+
181
215
  should "display stylesheet link items" do
182
216
  time = stop_time_for_test
183
217
  actual_html = stylesheet_link_tag('style', 'layout.css', 'http://google.com/style.css')
@@ -185,7 +219,9 @@ class TestAssetTagHelpers < Test::Unit::TestCase
185
219
  assert_has_tag('link', :href => "/stylesheets/style.css?#{time.to_i}") { actual_html }
186
220
  assert_has_tag('link', :href => "/stylesheets/layout.css?#{time.to_i}") { actual_html }
187
221
  assert_has_tag('link', :href => "http://google.com/style.css") { actual_html }
222
+ assert_equal actual_html, stylesheet_link_tag(['style', 'layout.css', 'http://google.com/style.css'])
188
223
  end
224
+
189
225
  should "not use a timestamp if stamp setting is false" do
190
226
  self.class.expects(:asset_stamp).returns(false)
191
227
  expected_options = { :media => "screen", :rel => "stylesheet", :type => "text/css" }
@@ -199,32 +235,38 @@ class TestAssetTagHelpers < Test::Unit::TestCase
199
235
  actual_html = javascript_include_tag('application')
200
236
  assert_has_tag('script', :src => "/javascripts/application.js?#{time.to_i}", :type => "text/javascript") { actual_html }
201
237
  end
238
+
202
239
  should "display javascript item for long relative path" do
203
240
  time = stop_time_for_test
204
241
  actual_html = javascript_include_tag('example/demo/application')
205
242
  assert_has_tag('script', :src => "/javascripts/example/demo/application.js?#{time.to_i}", :type => "text/javascript") { actual_html }
206
243
  end
244
+
207
245
  should "display javascript item for path containing js" do
208
246
  time = stop_time_for_test
209
247
  actual_html = javascript_include_tag 'test/jquery.json'
210
248
  assert_has_tag('script', :src => "/javascripts/test/jquery.json?#{time.to_i}", :type => "text/javascript") { actual_html }
211
249
  end
250
+
212
251
  should "display javascript item for path containing period" do
213
252
  time = stop_time_for_test
214
253
  actual_html = javascript_include_tag 'test/jquery.min'
215
254
  assert_has_tag('script', :src => "/javascripts/test/jquery.min.js?#{time.to_i}", :type => "text/javascript") { actual_html }
216
255
  end
256
+
217
257
  should "display javascript item with absolute path" do
218
258
  time = stop_time_for_test
219
259
  actual_html = javascript_include_tag('/js/application')
220
260
  assert_has_tag('script', :src => "/js/application.js?#{time.to_i}", :type => "text/javascript") { actual_html }
221
261
  end
262
+
222
263
  should "display javascript item with uri root" do
223
264
  self.class.stubs(:uri_root).returns("/blog")
224
265
  time = stop_time_for_test
225
266
  actual_html = javascript_include_tag('application')
226
267
  assert_has_tag('script', :src => "/blog/javascripts/application.js?#{time.to_i}", :type => "text/javascript") { actual_html }
227
268
  end
269
+
228
270
  should "display javascript items" do
229
271
  time = stop_time_for_test
230
272
  actual_html = javascript_include_tag('application', 'base.js', 'http://google.com/lib.js')
@@ -232,7 +274,9 @@ class TestAssetTagHelpers < Test::Unit::TestCase
232
274
  assert_has_tag('script', :src => "/javascripts/application.js?#{time.to_i}") { actual_html }
233
275
  assert_has_tag('script', :src => "/javascripts/base.js?#{time.to_i}") { actual_html }
234
276
  assert_has_tag('script', :src => "http://google.com/lib.js") { actual_html }
277
+ assert_equal actual_html, javascript_include_tag(['application', 'base.js', 'http://google.com/lib.js'])
235
278
  end
279
+
236
280
  should "not use a timestamp if stamp setting is false" do
237
281
  self.class.expects(:asset_stamp).returns(false)
238
282
  actual_html = javascript_include_tag('application')
@@ -246,11 +290,13 @@ class TestAssetTagHelpers < Test::Unit::TestCase
246
290
  actual_html = favicon_tag('icons/favicon.png')
247
291
  assert_has_tag('link', :rel => 'icon', :type => 'image/png', :href => "/images/icons/favicon.png?#{time.to_i}") { actual_html }
248
292
  end
293
+
249
294
  should "match type with file ext" do
250
295
  time = stop_time_for_test
251
296
  actual_html = favicon_tag('favicon.ico')
252
297
  assert_has_tag('link', :rel => 'icon', :type => 'image/ico', :href => "/images/favicon.ico?#{time.to_i}") { actual_html }
253
298
  end
299
+
254
300
  should "allow option overrides" do
255
301
  time = stop_time_for_test
256
302
  actual_html = favicon_tag('favicon.png', :type => 'image/ico')
@@ -262,9 +308,11 @@ class TestAssetTagHelpers < Test::Unit::TestCase
262
308
  should "generate correctly link tag for rss" do
263
309
  assert_has_tag('link', :type => 'application/rss+xml', :rel => 'alternate', :href => "/blog/post.rss", :title => 'rss') { feed_tag :rss, "/blog/post.rss" }
264
310
  end
311
+
265
312
  should "generate correctly link tag for atom" do
266
313
  assert_has_tag('link', :type => 'application/atom+xml', :rel => 'alternate', :href => "/blog/post.atom", :title => 'atom') { feed_tag :atom, "/blog/post.atom" }
267
314
  end
315
+
268
316
  should "override options" do
269
317
  assert_has_tag('link', :type => 'my-type', :rel => 'my-rel', :href => "/blog/post.rss", :title => 'my-title') { feed_tag :rss, "/blog/post.rss", :type => "my-type", :rel => "my-rel", :title => "my-title" }
270
318
  end