padrino-helpers 0.10.7 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/padrino-helpers.rb +2 -1
- data/lib/padrino-helpers/asset_tag_helpers.rb +57 -65
- data/lib/padrino-helpers/breadcrumb_helpers.rb +171 -0
- data/lib/padrino-helpers/form_builder/abstract_form_builder.rb +82 -24
- data/lib/padrino-helpers/form_helpers.rb +84 -17
- data/lib/padrino-helpers/format_helpers.rb +2 -1
- data/lib/padrino-helpers/locale/fr.yml +12 -12
- data/lib/padrino-helpers/locale/pt_br.yml +2 -2
- data/lib/padrino-helpers/output_helpers.rb +42 -2
- data/lib/padrino-helpers/output_helpers/erb_handler.rb +1 -1
- data/lib/padrino-helpers/output_helpers/slim_handler.rb +4 -5
- data/lib/padrino-helpers/render_helpers.rb +2 -2
- data/lib/padrino-helpers/tag_helpers.rb +33 -5
- data/padrino-helpers.gemspec +0 -0
- data/test/fixtures/markup_app/app.rb +13 -6
- data/test/fixtures/markup_app/views/capture_concat.erb +2 -2
- data/test/fixtures/markup_app/views/capture_concat.haml +2 -2
- data/test/fixtures/markup_app/views/capture_concat.slim +4 -5
- data/test/fixtures/markup_app/views/content_for.slim +4 -4
- data/test/fixtures/markup_app/views/content_tag.slim +5 -5
- data/test/fixtures/markup_app/views/current_engine.haml +1 -1
- data/test/fixtures/markup_app/views/fields_for.slim +13 -13
- data/test/fixtures/markup_app/views/form_for.slim +43 -43
- data/test/fixtures/markup_app/views/form_tag.slim +57 -57
- data/test/fixtures/markup_app/views/link_to.slim +2 -2
- data/test/fixtures/markup_app/views/mail_to.slim +2 -2
- data/test/fixtures/markup_app/views/meta_tag.slim +2 -2
- data/test/fixtures/markup_app/views/partials/_slim.slim +1 -1
- data/test/fixtures/markup_app/views/simple_partial.slim +1 -1
- data/test/fixtures/render_app/app.rb +3 -0
- data/test/test_asset_tag_helpers.rb +17 -4
- data/test/test_form_builder.rb +35 -1
- data/test/test_form_helpers.rb +29 -0
- data/test/test_format_helpers.rb +4 -0
- data/test/test_output_helpers.rb +5 -3
- data/test/test_tag_helpers.rb +11 -0
- metadata +10 -15
data/padrino-helpers.gemspec
CHANGED
File without changes
|
@@ -2,12 +2,19 @@ require 'sinatra/base'
|
|
2
2
|
require 'haml'
|
3
3
|
require 'erubis'
|
4
4
|
require 'slim'
|
5
|
+
require 'padrino-core/application/rendering/extensions/erubis'
|
6
|
+
require 'padrino-core/application/rendering/extensions/haml'
|
7
|
+
require 'padrino-core/application/rendering/extensions/slim'
|
5
8
|
|
6
9
|
class MarkupDemo < Sinatra::Base
|
7
10
|
register Padrino::Helpers
|
8
11
|
|
9
12
|
configure do
|
10
13
|
set :root, File.dirname(__FILE__)
|
14
|
+
set :erb, :engine_class => Padrino::Erubis::SafeBufferTemplate
|
15
|
+
set :haml, :escape_html => true
|
16
|
+
set :slim, :generator => Temple::Generators::RailsOutputBuffer,
|
17
|
+
:buffer => "out_buf"
|
11
18
|
end
|
12
19
|
|
13
20
|
get '/:engine/:file' do
|
@@ -23,19 +30,19 @@ class MarkupDemo < Sinatra::Base
|
|
23
30
|
|
24
31
|
def captured_content(&block)
|
25
32
|
content_html = capture_html(&block)
|
26
|
-
"<p>#{content_html}</p>"
|
33
|
+
"<p>#{content_html}</p>".html_safe
|
27
34
|
end
|
28
35
|
|
29
36
|
def concat_in_p(content_html)
|
30
|
-
|
37
|
+
concat_safe_content "<p>#{content_html}</p>"
|
31
38
|
end
|
32
39
|
|
33
|
-
def
|
34
|
-
|
40
|
+
def concat_if_block_is_template(name, &block)
|
41
|
+
concat_safe_content "<p class='is_template'>The #{name} block passed in is a template</p>" if block_is_template?(block)
|
35
42
|
end
|
36
43
|
|
37
|
-
def
|
38
|
-
|
44
|
+
def concat_ruby_not_template_block
|
45
|
+
concat_if_block_is_template('ruby') do
|
39
46
|
content_tag(:span, "This not a template block")
|
40
47
|
end
|
41
48
|
end
|
@@ -6,9 +6,9 @@
|
|
6
6
|
|
7
7
|
<% concat_in_p('Concat Line 3') %>
|
8
8
|
|
9
|
-
<%
|
9
|
+
<% concat_if_block_is_template('erb') do %>
|
10
10
|
<span>This is erb</span>
|
11
11
|
<span>This is erb</span>
|
12
12
|
<% end %>
|
13
13
|
|
14
|
-
<%
|
14
|
+
<% concat_ruby_not_template_block %>
|
@@ -1,13 +1,12 @@
|
|
1
1
|
- @content = captured_content do
|
2
2
|
span Captured Line 1
|
3
3
|
span Captured Line 2
|
4
|
+
= @content
|
4
5
|
|
5
|
-
|
6
|
+
- concat_in_p('Concat Line 3')
|
6
7
|
|
7
|
-
-
|
8
|
+
- concat_if_block_is_template('slim') do
|
8
9
|
span This is slim
|
9
10
|
span This is slim
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
== ruby_not_template_block
|
12
|
+
- concat_ruby_not_template_block
|
@@ -1,12 +1,12 @@
|
|
1
1
|
- content_for :demo do
|
2
2
|
h1 This is content yielded from a content_for
|
3
3
|
|
4
|
-
.demo
|
4
|
+
.demo= yield_content :demo
|
5
5
|
|
6
6
|
- content_for :demo2 do |fname, lname|
|
7
7
|
h1 This is content yielded with name #{fname + " " + lname}
|
8
8
|
|
9
|
-
.demo2
|
9
|
+
.demo2= yield_content :demo2, "Johnny", "Smith"
|
10
10
|
|
11
|
-
.demo_has_content
|
12
|
-
.fake_has_content
|
11
|
+
.demo_has_content= content_for?(:demo)
|
12
|
+
.fake_has_content= content_for?(:fake)
|
@@ -1,9 +1,9 @@
|
|
1
|
-
|
1
|
+
=content_tag :p, "Test 1", :class => 'test', :id => "test1"
|
2
2
|
|
3
|
-
|
3
|
+
=content_tag :p, "Test 2"
|
4
4
|
|
5
|
-
|
5
|
+
=content_tag(:p, :class => 'test', :id => 'test3') do
|
6
6
|
span Test 3
|
7
7
|
|
8
|
-
|
9
|
-
span Test 4
|
8
|
+
=content_tag(:p) do
|
9
|
+
span Test 4
|
@@ -1,15 +1,15 @@
|
|
1
1
|
- @user = MarkupUser.new
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
13
|
- unless child_form.object.new_record?
|
14
|
-
|
15
|
-
|
14
|
+
= child_form.check_box '_destroy'
|
15
|
+
= child_form.label '_destroy', :caption => 'Remove'
|
@@ -1,59 +1,59 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
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
4
|
p
|
5
|
-
|
6
|
-
|
5
|
+
= f.label :username, :caption => "Login: ", :class => 'user-label'
|
6
|
+
= f.text_field :username, :class => 'user-text', :value => "John"
|
7
7
|
p
|
8
|
-
|
9
|
-
|
8
|
+
= f.label :password
|
9
|
+
= f.password_field :password, :class => 'user-password', :value => "secret"
|
10
10
|
p
|
11
|
-
|
12
|
-
|
11
|
+
= f.label :age
|
12
|
+
= f.number_field :age, :class => 'numeric'
|
13
13
|
p
|
14
|
-
|
15
|
-
|
14
|
+
= f.label :telephone
|
15
|
+
= f.telephone_field :telephone, :class => 'numeric'
|
16
16
|
p
|
17
|
-
|
18
|
-
|
17
|
+
= f.label :email, :caption => 'Email Address: '
|
18
|
+
= f.email_field :email, :class => 'string'
|
19
19
|
p
|
20
|
-
|
21
|
-
|
20
|
+
= f.label :webpage, :caption => 'Your Web Page: '
|
21
|
+
= f.url_field :webpage, :class => 'string'
|
22
22
|
p
|
23
|
-
|
24
|
-
|
23
|
+
= f.label :search
|
24
|
+
= f.search_field :search, :class => 'string'
|
25
25
|
p
|
26
|
-
|
27
|
-
|
26
|
+
= f.label :photo
|
27
|
+
= f.file_field :photo, :class => 'user-photo'
|
28
28
|
p
|
29
|
-
|
30
|
-
|
29
|
+
= f.label :about, :caption => "About Me: "
|
30
|
+
= f.text_area :about, :class => 'user-about'
|
31
31
|
p
|
32
|
-
|
33
|
-
|
34
|
-
|
32
|
+
= f.label :gender, :caption => "Your gender: "
|
33
|
+
= f.radio_button :gender, :value => 'male'
|
34
|
+
= f.radio_button :gender, :value => 'female'
|
35
35
|
p
|
36
|
-
|
37
|
-
|
36
|
+
= f.label :country, :caption => "Your country"
|
37
|
+
= f.select :country, :options => ['USA', 'Canada', 'Mexico'], :selected => 'USA', :class => 'selector'
|
38
38
|
p
|
39
|
-
|
40
|
-
|
39
|
+
= f.label :remember_me
|
40
|
+
= f.check_box :remember_me, :value => "1"
|
41
41
|
p
|
42
|
-
|
42
|
+
= f.submit "Create", :class => 'success', :id => 'demo-button'
|
43
43
|
p
|
44
|
-
|
44
|
+
= f.image_submit "buttons/post.png", :class => 'success', :id => 'image-button'
|
45
45
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
46
|
+
= form_for MarkupUser.new, '/another_demo', :id => 'demo2', :method => 'get' do |f|
|
47
|
+
= f.error_messages :header_message => "custom MarkupUser cannot be saved!"
|
48
|
+
= f.hidden_field :session_id
|
49
|
+
= f.text_field_block :username, { :class => 'input' }, { :caption => 'Nickname: ', :class => 'label' }
|
50
|
+
= f.password_field_block :code, { :class => 'input' }
|
51
|
+
= f.text_area_block :about, { :class => 'textarea' }
|
52
|
+
= f.file_field_block :photo, { :class => 'upload' }
|
53
|
+
= f.check_box_block :remember_me, { :class => 'checker' }
|
54
|
+
= f.select_block :state, :options => ['California', 'Texas'], :class => 'selector'
|
55
|
+
= f.submit_block "Create", { :class => 'button' }
|
56
|
+
= f.image_submit_block "buttons/ok.png", { :class => 'image' }
|
57
57
|
|
58
|
-
|
59
|
-
|
58
|
+
= form_for :markup_user, '/third_demo', :id => 'demo3', :method => 'get' do |f|
|
59
|
+
= f.text_field_block :username
|
@@ -1,70 +1,70 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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 :email
|
10
|
+
= email_field_tag :email
|
11
|
+
= label_tag :age
|
12
|
+
= number_field_tag :age
|
13
|
+
= label_tag :telephone
|
14
|
+
= telephone_field_tag :telephone
|
15
|
+
= label_tag :webpage
|
16
|
+
= url_field_tag :webpage
|
17
|
+
= label_tag :search
|
18
|
+
= search_field_tag :search
|
19
|
+
= label_tag :color
|
20
|
+
= select_tag :color, :options => ['green', 'orange', 'purple']
|
21
|
+
= label_tag :gender
|
22
|
+
= radio_button_tag :gender, :value => 'male'
|
23
|
+
= radio_button_tag :gender, :value => 'female'
|
24
|
+
= check_box_tag :remember_me
|
25
|
+
= submit_tag
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
= form_tag '/advanced', :id => 'advanced', :class => 'advanced-form', :method => 'get' do
|
28
|
+
= error_messages_for MarkupUser.new, :header_message => "There are problems with saving user!"
|
29
|
+
= hidden_field_tag :session_id, :value => "__secret__"
|
30
|
+
= field_set_tag "Advanced", :class => 'advanced-field-set' do
|
31
31
|
p
|
32
|
-
|
33
|
-
|
32
|
+
= label_tag :username, :class => 'first', :caption => "Nickname"
|
33
|
+
= text_field_tag :username, :value => params[:username], :id => 'the_username'
|
34
34
|
p
|
35
|
-
|
36
|
-
|
35
|
+
= label_tag :password, :class => 'first'
|
36
|
+
= password_field_tag :password, :value => params[:password]
|
37
37
|
p
|
38
|
-
|
39
|
-
|
38
|
+
= label_tag :email, :caption => 'Email Address'
|
39
|
+
= email_field_tag :email, :class => 'string'
|
40
40
|
p
|
41
|
-
|
42
|
-
|
41
|
+
= label_tag :age, :class => 'age'
|
42
|
+
= number_field_tag :age, :class => 'numeric'
|
43
43
|
p
|
44
|
-
|
45
|
-
|
44
|
+
= label_tag :telephone, :class => 'telephone'
|
45
|
+
= telephone_field_tag :telephone, :class => 'numeric'
|
46
46
|
p
|
47
|
-
|
48
|
-
|
47
|
+
= label_tag :webpage, :caption => 'Your Home Page'
|
48
|
+
= url_field_tag :webpage, :class => 'string'
|
49
49
|
p
|
50
|
-
|
51
|
-
|
50
|
+
= label_tag :search
|
51
|
+
= search_field_tag :search, :class => 'string'
|
52
52
|
p
|
53
|
-
|
54
|
-
|
53
|
+
= label_tag :about, :class => 'about', :caption => "About Me"
|
54
|
+
= text_area_tag :about, :class => 'large'
|
55
55
|
p
|
56
|
-
|
57
|
-
|
58
|
-
|
56
|
+
= label_tag :gender, :class => 'gender'
|
57
|
+
= radio_button_tag :gender, :value => 'male', :checked => true
|
58
|
+
= radio_button_tag :gender, :value => 'female'
|
59
59
|
p
|
60
|
-
|
61
|
-
|
60
|
+
= label_tag :photo, :class => 'photo'
|
61
|
+
= file_field_tag :photo, :class => 'upload'
|
62
62
|
p
|
63
|
-
|
64
|
-
|
63
|
+
= label_tag :fav_color
|
64
|
+
= select_tag :fav_color, :options => [ ['green', '1'], ['orange', '2'], ['purple', '3'] ], :selected => '2'
|
65
65
|
p
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
66
|
+
= check_box_tag :remember_me, :value => "1", :checked => true
|
67
|
+
= field_set_tag(:class => 'buttons') do
|
68
|
+
= submit_tag "Login"
|
69
|
+
= button_tag "Cancel"
|
70
|
+
= image_submit_tag "buttons/submit.png"
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
= link_to "Test 1 No Block", '/test1', :class => 'test', :id => 'test1'
|
2
2
|
|
3
|
-
|
3
|
+
= link_to("/test2", :class => 'test', :id => 'test2') do
|
4
4
|
span Test 2 With Block
|
@@ -1,3 +1,3 @@
|
|
1
|
-
p.simple
|
1
|
+
p.simple= mail_to 'test@demo.com'
|
2
2
|
|
3
|
-
p.captioned
|
3
|
+
p.captioned= mail_to 'test@demo.com', "Click my Email"
|
@@ -1,3 +1,3 @@
|
|
1
|
-
|
1
|
+
= meta_tag "weblog,news", :name => "keywords"
|
2
2
|
|
3
|
-
|
3
|
+
= meta_tag "text/html; charset=UTF-8", :"http-equiv" => "Content-Type"
|
@@ -1 +1 @@
|
|
1
|
-
=current_engine
|
1
|
+
= current_engine
|
@@ -1 +1 @@
|
|
1
|
-
p.slim= partial 'partials/slim', :engine => "slim"
|
1
|
+
p.slim= partial 'partials/slim', :engine => "slim"
|
@@ -16,6 +16,9 @@ class RenderDemo < Padrino::Application
|
|
16
16
|
configure do
|
17
17
|
set :logging, false
|
18
18
|
set :padrino_logging, false
|
19
|
+
set :erb, :engine_class => Padrino::Erubis::SafeBufferTemplate
|
20
|
+
set :haml, :escape_html => true
|
21
|
+
set :slim, :generator => Temple::Generators::RailsOutputBuffer
|
19
22
|
end
|
20
23
|
|
21
24
|
# get current engines from partials
|
@@ -70,6 +70,17 @@ describe "AssetTagHelpers" do
|
|
70
70
|
assert_has_tag('a#binky.first', :content => "Sign up", :href => '/register') { actual_link }
|
71
71
|
end
|
72
72
|
|
73
|
+
should "escape the link text" do
|
74
|
+
actual_link = link_to('/register', :class => 'first', :id => 'binky') { "<>" }
|
75
|
+
assert_has_tag('a#binky.first', :href => '/register') { actual_link }
|
76
|
+
assert_match "<>", actual_link
|
77
|
+
end
|
78
|
+
|
79
|
+
should "not escape image_tag" do
|
80
|
+
actual_link = link_to(image_tag("/my/fancy/image.png"), :class => 'first', :id => 'binky')
|
81
|
+
assert_has_tag('img', :src => "/my/fancy/image.png") { actual_link }
|
82
|
+
end
|
83
|
+
|
73
84
|
should "display link block element in haml" do
|
74
85
|
visit '/haml/link_to'
|
75
86
|
assert_have_selector :a, :content => "Test 1 No Block", :href => '/test1', :class => 'test', :id => 'test1'
|
@@ -183,16 +194,15 @@ describe "AssetTagHelpers" do
|
|
183
194
|
should "display image tag relative link with incorrect spacing" do
|
184
195
|
time = stop_time_for_test
|
185
196
|
assert_has_tag('img.photo', :src => "/images/%20relative/%20pic.gif%20%20?#{time.to_i}") {
|
186
|
-
image_tag(' relative/ pic.gif ', :class => 'photo')
|
197
|
+
image_tag(' relative/ pic.gif ', :class => 'photo')
|
198
|
+
}
|
187
199
|
end
|
188
200
|
|
189
201
|
should "not use a timestamp if stamp setting is false" do
|
190
|
-
self.class.expects(:asset_stamp).returns(false)
|
191
202
|
assert_has_tag('img', :src => "/absolute/pic.gif") { image_tag('/absolute/pic.gif') }
|
192
203
|
end
|
193
204
|
|
194
205
|
should "have xhtml convention tag" do
|
195
|
-
self.class.expects(:asset_stamp).returns(false)
|
196
206
|
assert_equal image_tag('/absolute/pic.gif'), '<img src="/absolute/pic.gif" />'
|
197
207
|
end
|
198
208
|
end
|
@@ -200,8 +210,10 @@ describe "AssetTagHelpers" do
|
|
200
210
|
context 'for #stylesheet_link_tag method' do
|
201
211
|
should "display stylesheet link item" do
|
202
212
|
time = stop_time_for_test
|
213
|
+
actual_html = stylesheet_link_tag('style')
|
203
214
|
expected_options = { :media => "screen", :rel => "stylesheet", :type => "text/css" }
|
204
|
-
assert_has_tag('link', expected_options.merge(:href => "/stylesheets/style.css?#{time.to_i}")) {
|
215
|
+
assert_has_tag('link', expected_options.merge(:href => "/stylesheets/style.css?#{time.to_i}")) { actual_html }
|
216
|
+
assert actual_html.html_safe?
|
205
217
|
end
|
206
218
|
|
207
219
|
should "display stylesheet link item for long relative path" do
|
@@ -248,6 +260,7 @@ describe "AssetTagHelpers" do
|
|
248
260
|
time = stop_time_for_test
|
249
261
|
actual_html = javascript_include_tag('application')
|
250
262
|
assert_has_tag('script', :src => "/javascripts/application.js?#{time.to_i}", :type => "text/javascript") { actual_html }
|
263
|
+
assert actual_html.html_safe?
|
251
264
|
end
|
252
265
|
|
253
266
|
should "display javascript item for long relative path" do
|