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
@@ -24,8 +24,25 @@ class TestFormatHelpers < Test::Unit::TestCase
24
24
  end
25
25
 
26
26
  should "support defining a class for the paragraphs" do
27
- actual_text = simple_format("Look ma! A class!", :class => 'description')
28
- assert_equal "<p class=\"description\">Look ma! A class!</p>", actual_text
27
+ actual_text = simple_format("Look me! A class!", :class => 'description')
28
+ assert_equal "<p class=\"description\">Look me! A class!</p>", actual_text
29
+ end
30
+
31
+ context 'wrapped in a custom tag' do
32
+ should "format simple text into html format" do
33
+ actual_text = simple_format("Here is some basic text...\n...with a line break.", :tag => :div)
34
+ assert_equal "<div>Here is some basic text...\n<br />...with a line break.</div>", actual_text
35
+ end
36
+
37
+ should "format more text into html format" do
38
+ actual_text = simple_format("We want to put a paragraph...\n\n...right there.", :tag => :div)
39
+ assert_equal "<div>We want to put a paragraph...</div>\n\n<div>...right there.</div>", actual_text
40
+ end
41
+
42
+ should "support defining a class for the paragraphs" do
43
+ actual_text = simple_format("Look me! A class!", :class => 'description', :tag => :div)
44
+ assert_equal "<div class=\"description\">Look me! A class!</div>", actual_text
45
+ end
29
46
  end
30
47
  end
31
48
 
@@ -18,6 +18,12 @@ class TestOutputHelpers < Test::Unit::TestCase
18
18
  assert_have_selector '.demo h1', :content => "This is content yielded from a content_for"
19
19
  assert_have_selector '.demo2 h1', :content => "This is content yielded with name Johnny Smith"
20
20
  end
21
+
22
+ should "work for slim templates" do
23
+ visit '/slim/content_for'
24
+ assert_have_selector '.demo h1', :content => "This is content yielded from a content_for"
25
+ assert_have_selector '.demo2 h1', :content => "This is content yielded with name Johnny Smith"
26
+ end
21
27
  end
22
28
 
23
29
  context 'for #capture_html method' do
@@ -32,6 +38,12 @@ class TestOutputHelpers < Test::Unit::TestCase
32
38
  assert_have_selector 'p span', :content => "Captured Line 1"
33
39
  assert_have_selector 'p span', :content => "Captured Line 2"
34
40
  end
41
+
42
+ should "work for slim templates" do
43
+ visit '/slim/capture_concat'
44
+ assert_have_selector 'p span', :content => "Captured Line 1"
45
+ assert_have_selector 'p span', :content => "Captured Line 2"
46
+ end
35
47
  end
36
48
 
37
49
  context 'for #concat_content method' do
@@ -44,6 +56,11 @@ class TestOutputHelpers < Test::Unit::TestCase
44
56
  visit '/haml/capture_concat'
45
57
  assert_have_selector 'p', :content => "Concat Line 3", :count => 1
46
58
  end
59
+
60
+ should "work for slim templates" do
61
+ visit '/slim/capture_concat'
62
+ assert_have_selector 'p', :content => "Concat Line 3", :count => 1
63
+ end
47
64
  end
48
65
 
49
66
  context 'for #block_is_template?' do
@@ -59,5 +76,41 @@ class TestOutputHelpers < Test::Unit::TestCase
59
76
  assert_have_selector 'p', :content => "The haml block passed in is a template", :class => 'is_template'
60
77
  assert_have_no_selector 'p', :content => "The ruby block passed in is a template", :class => 'is_template'
61
78
  end
79
+
80
+ should_eventually "work for slim templates" do
81
+ visit '/slim/capture_concat'
82
+ assert_have_selector 'p', :content => "The slim block passed in is a template", :class => 'is_template'
83
+ # TODO Get SLIM template detection working (fix block_is_erb? method)
84
+ # assert_have_no_selector 'p', :content => "The ruby block passed in is a template", :class => 'is_template'
85
+ end
86
+ end
87
+
88
+ context 'for #current_engine method' do
89
+ should 'detect correctly current engine for erb' do
90
+ visit '/erb/current_engine'
91
+ assert_have_selector 'p.start', :content => "erb"
92
+ assert_have_selector 'p.haml', :content => "haml"
93
+ assert_have_selector 'p.erb', :content => "erb"
94
+ assert_have_selector 'p.slim', :content => "slim"
95
+ assert_have_selector 'p.end', :content => "erb"
96
+ end
97
+
98
+ should 'detect correctly current engine for haml' do
99
+ visit '/haml/current_engine'
100
+ assert_have_selector 'p.start', :content => "haml"
101
+ assert_have_selector 'p.haml', :content => "haml"
102
+ assert_have_selector 'p.erb', :content => "erb"
103
+ assert_have_selector 'p.slim', :content => "slim"
104
+ assert_have_selector 'p.end', :content => "haml"
105
+ end
106
+
107
+ should 'detect correctly current engine for slim' do
108
+ visit '/slim/current_engine'
109
+ assert_have_selector 'p.start', :content => "slim"
110
+ assert_have_selector 'p.haml', :content => "haml"
111
+ assert_have_selector 'p.erb', :content => "erb"
112
+ assert_have_selector 'p.slim', :content => "slim"
113
+ assert_have_selector 'p.end', :content => "slim"
114
+ end
62
115
  end
63
116
  end
@@ -46,4 +46,15 @@ class TestRenderHelpers < Test::Unit::TestCase
46
46
  assert_have_selector 'p', :content => "Extra is bar"
47
47
  end
48
48
  end
49
+
50
+ context 'for #current_engine method' do
51
+ should 'detect correctly current engine for a padrino application' do
52
+ visit '/current_engine'
53
+ assert_have_selector 'p.start', :content => "haml"
54
+ assert_have_selector 'p.haml', :content => "haml"
55
+ assert_have_selector 'p.erb', :content => "erb"
56
+ assert_have_selector 'p.slim', :content => "slim"
57
+ assert_have_selector 'p.end', :content => "haml"
58
+ end
59
+ end
49
60
  end
@@ -10,21 +10,26 @@ class TestTagHelpers < Test::Unit::TestCase
10
10
  should("support tags with no content no attributes") do
11
11
  assert_has_tag(:br) { tag(:br) }
12
12
  end
13
+
13
14
  should("support tags with no content with attributes") do
14
15
  actual_html = tag(:br, :style => 'clear:both', :class => 'yellow')
15
16
  assert_has_tag(:br, :class => 'yellow', :style=>'clear:both') { actual_html }
16
17
  end
18
+
17
19
  should "support selected attribute by using 'selected' if true" do
18
20
  actual_html = tag(:option, :selected => true)
19
21
  assert_has_tag('option', :selected => 'selected') { actual_html }
20
22
  end
23
+
21
24
  should "support tags with content no attributes" do
22
25
  assert_has_tag(:p, :content => "Demo String") { tag(:p, :content => "Demo String") }
23
26
  end
27
+
24
28
  should "support tags with content and attributes" do
25
29
  actual_html = tag(:p, :content => "Demo", :class => 'large', :id => 'intro')
26
30
  assert_has_tag('p#intro.large', :content => "Demo") { actual_html }
27
31
  end
32
+
28
33
  should "support open tags" do
29
34
  actual_html = tag(:p, :class => 'demo', :open => true)
30
35
  assert_equal "<p class=\"demo\">", actual_html
@@ -36,10 +41,12 @@ class TestTagHelpers < Test::Unit::TestCase
36
41
  actual_html = content_tag(:p, "Demo", :class => 'large', :id => 'thing')
37
42
  assert_has_tag('p.large#thing', :content => "Demo") { actual_html }
38
43
  end
44
+
39
45
  should "support tags with content as block" do
40
46
  actual_html = content_tag(:p, :class => 'large', :id => 'star') { "Demo" }
41
47
  assert_has_tag('p.large#star', :content => "Demo") { actual_html }
42
48
  end
49
+
43
50
  should "support tags with erb" do
44
51
  visit '/erb/content_tag'
45
52
  assert_have_selector :p, :content => "Test 1", :class => 'test', :id => 'test1'
@@ -47,6 +54,7 @@ class TestTagHelpers < Test::Unit::TestCase
47
54
  assert_have_selector :p, :content => "Test 3"
48
55
  assert_have_selector :p, :content => "Test 4"
49
56
  end
57
+
50
58
  should "support tags with haml" do
51
59
  visit '/haml/content_tag'
52
60
  assert_have_selector :p, :content => "Test 1", :class => 'test', :id => 'test1'
@@ -54,24 +62,36 @@ class TestTagHelpers < Test::Unit::TestCase
54
62
  assert_have_selector :p, :content => "Test 3", :class => 'test', :id => 'test3'
55
63
  assert_have_selector :p, :content => "Test 4"
56
64
  end
65
+
66
+ should "support tags with slim" do
67
+ visit '/slim/content_tag'
68
+ assert_have_selector :p, :content => "Test 1", :class => 'test', :id => 'test1'
69
+ assert_have_selector :p, :content => "Test 2"
70
+ assert_have_selector :p, :content => "Test 3", :class => 'test', :id => 'test3'
71
+ assert_have_selector :p, :content => "Test 4"
72
+ end
57
73
  end
58
74
 
59
75
  context 'for #input_tag method' do
60
76
  should "support field with type" do
61
77
  assert_has_tag('input[type=text]') { input_tag(:text) }
62
78
  end
79
+
63
80
  should "support field with type and options" do
64
81
  actual_html = input_tag(:text, :class => "first", :id => 'texter')
65
82
  assert_has_tag('input.first#texter[type=text]') { actual_html }
66
83
  end
84
+
67
85
  should "support checked attribute by using 'checked' if true" do
68
86
  actual_html = input_tag(:checkbox, :checked => true)
69
87
  assert_has_tag('input[type=checkbox]', :checked => 'checked') { actual_html }
70
88
  end
89
+
71
90
  should "remove checked attribute if false" do
72
91
  actual_html = input_tag(:checkbox, :checked => false)
73
92
  assert_has_no_tag('input[type=checkbox][checked=false]') { actual_html }
74
93
  end
94
+
75
95
  should "support disabled attribute by using 'disabled' if true" do
76
96
  actual_html = input_tag(:checkbox, :disabled => true)
77
97
  assert_has_tag('input[type=checkbox]', :disabled => 'disabled') { actual_html }
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: padrino-helpers
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
4
+ hash: 9
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
- - 24
10
- version: 0.9.24
9
+ - 25
10
+ version: 0.9.25
11
11
  platform: ruby
12
12
  authors:
13
13
  - Padrino Team
@@ -18,7 +18,7 @@ autorequire:
18
18
  bindir: bin
19
19
  cert_chain: []
20
20
 
21
- date: 2011-04-28 00:00:00 +02:00
21
+ date: 2011-04-27 00:00:00 +02:00
22
22
  default_executable:
23
23
  dependencies:
24
24
  - !ruby/object:Gem::Dependency
@@ -29,12 +29,12 @@ dependencies:
29
29
  requirements:
30
30
  - - "="
31
31
  - !ruby/object:Gem::Version
32
- hash: 11
32
+ hash: 9
33
33
  segments:
34
34
  - 0
35
35
  - 9
36
- - 24
37
- version: 0.9.24
36
+ - 25
37
+ version: 0.9.25
38
38
  type: :runtime
39
39
  version_requirements: *id001
40
40
  - !ruby/object:Gem::Dependency
@@ -69,7 +69,6 @@ files:
69
69
  - Rakefile
70
70
  - padrino-helpers.gemspec
71
71
  - lib/padrino-helpers/asset_tag_helpers.rb
72
- - lib/padrino-helpers/dom_helpers.rb
73
72
  - lib/padrino-helpers/form_builder/abstract_form_builder.rb
74
73
  - lib/padrino-helpers/form_builder/standard_form_builder.rb
75
74
  - lib/padrino-helpers/form_helpers.rb
@@ -95,6 +94,7 @@ files:
95
94
  - lib/padrino-helpers/output_helpers/abstract_handler.rb
96
95
  - lib/padrino-helpers/output_helpers/erb_handler.rb
97
96
  - lib/padrino-helpers/output_helpers/haml_handler.rb
97
+ - lib/padrino-helpers/output_helpers/slim_handler.rb
98
98
  - lib/padrino-helpers/output_helpers.rb
99
99
  - lib/padrino-helpers/render_helpers.rb
100
100
  - lib/padrino-helpers/tag_helpers.rb
@@ -103,23 +103,42 @@ files:
103
103
  - test/fixtures/markup_app/app.rb
104
104
  - test/fixtures/markup_app/views/capture_concat.erb
105
105
  - test/fixtures/markup_app/views/capture_concat.haml
106
+ - test/fixtures/markup_app/views/capture_concat.slim
106
107
  - test/fixtures/markup_app/views/content_for.erb
107
108
  - test/fixtures/markup_app/views/content_for.haml
109
+ - test/fixtures/markup_app/views/content_for.slim
108
110
  - test/fixtures/markup_app/views/content_tag.erb
109
111
  - test/fixtures/markup_app/views/content_tag.haml
112
+ - test/fixtures/markup_app/views/content_tag.slim
113
+ - test/fixtures/markup_app/views/current_engine.erb
114
+ - test/fixtures/markup_app/views/current_engine.haml
115
+ - test/fixtures/markup_app/views/current_engine.slim
110
116
  - test/fixtures/markup_app/views/fields_for.erb
111
117
  - test/fixtures/markup_app/views/fields_for.haml
118
+ - test/fixtures/markup_app/views/fields_for.slim
112
119
  - test/fixtures/markup_app/views/form_for.erb
113
120
  - test/fixtures/markup_app/views/form_for.haml
121
+ - test/fixtures/markup_app/views/form_for.slim
114
122
  - test/fixtures/markup_app/views/form_tag.erb
115
123
  - test/fixtures/markup_app/views/form_tag.haml
124
+ - test/fixtures/markup_app/views/form_tag.slim
116
125
  - test/fixtures/markup_app/views/link_to.erb
117
126
  - test/fixtures/markup_app/views/link_to.haml
127
+ - test/fixtures/markup_app/views/link_to.slim
118
128
  - test/fixtures/markup_app/views/mail_to.erb
119
129
  - test/fixtures/markup_app/views/mail_to.haml
130
+ - test/fixtures/markup_app/views/mail_to.slim
120
131
  - test/fixtures/markup_app/views/meta_tag.erb
121
132
  - test/fixtures/markup_app/views/meta_tag.haml
133
+ - test/fixtures/markup_app/views/meta_tag.slim
134
+ - test/fixtures/markup_app/views/partials/_erb.erb
135
+ - test/fixtures/markup_app/views/partials/_haml.haml
136
+ - test/fixtures/markup_app/views/partials/_slim.slim
122
137
  - test/fixtures/render_app/app.rb
138
+ - test/fixtures/render_app/views/current_engine.haml
139
+ - test/fixtures/render_app/views/current_engines/_erb.erb
140
+ - test/fixtures/render_app/views/current_engines/_haml.haml
141
+ - test/fixtures/render_app/views/current_engines/_slim.slim
123
142
  - test/fixtures/render_app/views/erb/test.erb
124
143
  - test/fixtures/render_app/views/haml/test.haml
125
144
  - test/fixtures/render_app/views/template/_user.haml
@@ -127,7 +146,6 @@ files:
127
146
  - test/fixtures/render_app/views/template/some_template.haml
128
147
  - test/helper.rb
129
148
  - test/test_asset_tag_helpers.rb
130
- - test/test_dom_helpers.rb
131
149
  - test/test_form_builder.rb
132
150
  - test/test_form_helpers.rb
133
151
  - test/test_format_helpers.rb
@@ -1,46 +0,0 @@
1
- module Padrino
2
- module Helpers
3
- module DomHelpers
4
- ##
5
- # Create DOM id from given object. You can also specify optional prefix.
6
- #
7
- # ==== Examples
8
- #
9
- # @user = User.new
10
- # dom_id(@user, "new") # => "new_user"
11
- #
12
- # @user.save
13
- # @user.id # => 10
14
- # dom_id(@user) # => user_10
15
- # dom_id(@user, "edit") # => edit_user_10
16
- #
17
- def dom_id(object, prefix=nil)
18
- chain = []
19
- chain << prefix if prefix
20
- chain << object.class.to_s.underscore.gsub("/", "_")
21
- chain << object.id if object.respond_to?('id') && object.id
22
- chain.join('_')
23
- end
24
-
25
- ##
26
- # Create DOM class name from given object. You can also specify optional
27
- # prefix.
28
- #
29
- # ==== Examples
30
- #
31
- # @user = User.new
32
- # dom_class(@user, "new") # => new_user
33
- # dom_class(@user) # => user
34
- #
35
- # @user.save
36
- # @user.id # => 11
37
- # dom_class(@user) # => user
38
- def dom_class(object, prefix=nil)
39
- chain = []
40
- chain << prefix if prefix
41
- chain << object.class.to_s.underscore.gsub("/", "_")
42
- chain.join('_')
43
- end
44
- end # DomHelpers
45
- end # Helpers
46
- end # Padrino
@@ -1,37 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/helper')
2
-
3
- class TestObject
4
- attr_accessor :id
5
- end
6
-
7
- class TestDomHelpers < Test::Unit::TestCase
8
- include Padrino::Helpers::DomHelpers
9
-
10
- class SecondTestObject
11
- attr_accessor :id
12
- end
13
-
14
- context 'for #dom_id method' do
15
- should "return DOM id based on name of given object" do
16
- assert_equal dom_id(TestObject.new), "test_object"
17
- assert_equal dom_id(TestDomHelpers::SecondTestObject.new), "test_dom_helpers_second_test_object"
18
- end
19
- should "prepend given prefix to generated id" do
20
- assert_equal dom_id(TestObject.new, "new"), "new_test_object"
21
- end
22
- should "append object #id to generated id if it's not empty" do
23
- test_obj = TestObject.new
24
- test_obj.id = 10
25
- assert_equal dom_id(test_obj), "test_object_10"
26
- end
27
- end
28
-
29
- context 'for #dom_class method' do
30
- should "return DOM class name based on name of given object" do
31
- assert_equal dom_class(TestObject.new), "test_object"
32
- end
33
- should "prepend given prefix to generated class name" do
34
- assert_equal dom_class(TestObject.new, "new"), "new_test_object"
35
- end
36
- end
37
- end