padrino-helpers 0.16.0.pre4 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.rdoc +29 -29
- data/Rakefile +1 -1
- data/lib/padrino/rendering/erb_template.rb +7 -7
- data/lib/padrino/rendering/erubi_template.rb +4 -4
- data/lib/padrino/rendering/erubis_template.rb +4 -4
- data/lib/padrino/rendering/haml_template.rb +1 -1
- data/lib/padrino/rendering/hamlit_template.rb +4 -4
- data/lib/padrino/rendering/slim_template.rb +5 -5
- data/lib/padrino/rendering.rb +54 -45
- data/lib/padrino/safe_buffer.rb +31 -36
- data/lib/padrino-helpers/asset_tag_helpers.rb +48 -48
- data/lib/padrino-helpers/form_builder/abstract_form_builder.rb +74 -70
- data/lib/padrino-helpers/form_builder/standard_form_builder.rb +20 -20
- data/lib/padrino-helpers/form_helpers/errors.rb +14 -14
- data/lib/padrino-helpers/form_helpers/options.rb +25 -24
- data/lib/padrino-helpers/form_helpers/security.rb +5 -5
- data/lib/padrino-helpers/form_helpers.rb +133 -133
- data/lib/padrino-helpers/format_helpers.rb +61 -63
- data/lib/padrino-helpers/number_helpers.rb +82 -78
- data/lib/padrino-helpers/output_helpers/abstract_handler.rb +5 -3
- data/lib/padrino-helpers/output_helpers/erb_handler.rb +2 -2
- data/lib/padrino-helpers/output_helpers/haml_handler.rb +1 -1
- data/lib/padrino-helpers/output_helpers.rb +16 -17
- data/lib/padrino-helpers/render_helpers.rb +28 -27
- data/lib/padrino-helpers/tag_helpers.rb +62 -58
- data/lib/padrino-helpers/translation_helpers.rb +2 -2
- data/lib/padrino-helpers.rb +1 -2
- data/padrino-helpers.gemspec +17 -17
- data/test/fixtures/apps/render.rb +2 -2
- data/test/fixtures/markup_app/app.rb +9 -8
- data/test/fixtures/markup_app/views/button_to.erb +3 -3
- data/test/fixtures/markup_app/views/button_to.haml +2 -2
- data/test/fixtures/markup_app/views/button_to.slim +3 -3
- data/test/fixtures/markup_app/views/content_for.erb +4 -4
- data/test/fixtures/markup_app/views/content_for.haml +4 -4
- data/test/fixtures/markup_app/views/content_for.slim +2 -2
- data/test/fixtures/markup_app/views/content_tag.erb +3 -3
- data/test/fixtures/markup_app/views/content_tag.haml +3 -3
- data/test/fixtures/markup_app/views/content_tag.slim +3 -3
- data/test/fixtures/markup_app/views/fields_for.erb +2 -2
- data/test/fixtures/markup_app/views/fields_for.haml +2 -2
- data/test/fixtures/markup_app/views/fields_for.slim +2 -2
- data/test/fixtures/markup_app/views/form_for.erb +41 -41
- data/test/fixtures/markup_app/views/form_for.haml +41 -41
- data/test/fixtures/markup_app/views/form_for.slim +41 -42
- data/test/fixtures/markup_app/views/form_tag.erb +47 -47
- data/test/fixtures/markup_app/views/form_tag.haml +48 -48
- data/test/fixtures/markup_app/views/form_tag.slim +49 -49
- data/test/fixtures/markup_app/views/link_to.erb +2 -2
- data/test/fixtures/markup_app/views/link_to.haml +2 -2
- data/test/fixtures/markup_app/views/link_to.slim +2 -2
- data/test/fixtures/markup_app/views/meta_tag.erb +2 -2
- data/test/fixtures/markup_app/views/meta_tag.haml +2 -2
- data/test/fixtures/markup_app/views/meta_tag.slim +2 -2
- data/test/fixtures/markup_app/views/simple_partial.erb +1 -1
- data/test/fixtures/markup_app/views/simple_partial.haml +1 -1
- data/test/fixtures/markup_app/views/simple_partial.slim +1 -1
- data/test/fixtures/render_app/app.rb +13 -12
- data/test/fixtures/render_app/views/_unsafe.html.builder +1 -1
- data/test/fixtures/render_app/views/_unsafe_object.html.builder +1 -1
- data/test/fixtures/render_app/views/explicit_engine.haml +3 -3
- data/test/helper.rb +19 -19
- data/test/test_asset_tag_helpers.rb +133 -133
- data/test/test_form_builder.rb +629 -628
- data/test/test_form_helpers.rb +610 -610
- data/test/test_format_helpers.rb +66 -63
- data/test/test_helpers.rb +2 -2
- data/test/test_locale.rb +13 -11
- data/test/test_number_helpers.rb +65 -65
- data/test/test_output_helpers.rb +76 -76
- data/test/test_render_helpers.rb +101 -101
- data/test/test_rendering.rb +329 -326
- data/test/test_rendering_extensions.rb +4 -4
- data/test/test_tag_helpers.rb +55 -55
- metadata +6 -6
|
@@ -59,13 +59,13 @@ module Padrino
|
|
|
59
59
|
# # => "<foo>"
|
|
60
60
|
#
|
|
61
61
|
def capture_html(*args, &block)
|
|
62
|
-
if handler = find_proper_handler
|
|
62
|
+
if (handler = find_proper_handler)
|
|
63
63
|
handler.capture_from_template(*args, &block)
|
|
64
64
|
else
|
|
65
65
|
yield(*args)
|
|
66
66
|
end
|
|
67
67
|
end
|
|
68
|
-
alias
|
|
68
|
+
alias capture capture_html
|
|
69
69
|
|
|
70
70
|
##
|
|
71
71
|
# Outputs the given text to the templates buffer directly.
|
|
@@ -78,14 +78,14 @@ module Padrino
|
|
|
78
78
|
# @example
|
|
79
79
|
# concat_content("This will be output to the template buffer")
|
|
80
80
|
#
|
|
81
|
-
def concat_content(text=
|
|
82
|
-
if handler = find_proper_handler
|
|
81
|
+
def concat_content(text = '')
|
|
82
|
+
if (handler = find_proper_handler)
|
|
83
83
|
handler.concat_to_template(text, binding)
|
|
84
84
|
else
|
|
85
85
|
text
|
|
86
86
|
end
|
|
87
87
|
end
|
|
88
|
-
alias
|
|
88
|
+
alias concat concat_content
|
|
89
89
|
|
|
90
90
|
##
|
|
91
91
|
# Outputs the given text to the templates buffer directly,
|
|
@@ -97,7 +97,7 @@ module Padrino
|
|
|
97
97
|
# @example
|
|
98
98
|
# concat_safe_content("This will be output to the template buffer")
|
|
99
99
|
#
|
|
100
|
-
def concat_safe_content(text=
|
|
100
|
+
def concat_safe_content(text = '')
|
|
101
101
|
concat_content text.html_safe
|
|
102
102
|
end
|
|
103
103
|
|
|
@@ -114,8 +114,7 @@ module Padrino
|
|
|
114
114
|
# @return [Boolean] True if the block is a template; false otherwise.
|
|
115
115
|
#
|
|
116
116
|
def block_is_template?(block)
|
|
117
|
-
|
|
118
|
-
block && handler && handler.engine_matches?(block)
|
|
117
|
+
block && find_proper_handler&.engine_matches?(block)
|
|
119
118
|
end
|
|
120
119
|
|
|
121
120
|
##
|
|
@@ -138,12 +137,12 @@ module Padrino
|
|
|
138
137
|
# content_for(:name) { ...content... }
|
|
139
138
|
# content_for(:name) { |name| ...content... }
|
|
140
139
|
# content_for(:name, "I'm Jeff")
|
|
141
|
-
# content_for(:name, :
|
|
140
|
+
# content_for(:name, flush: true) { ...new content... }
|
|
142
141
|
#
|
|
143
142
|
def content_for(key, content = nil, options = {}, &block)
|
|
144
143
|
options = content if content.is_a?(Hash)
|
|
145
144
|
content_blocks[key.to_sym].clear if options[:flush]
|
|
146
|
-
content_blocks[key.to_sym] << (block_given? ? block :
|
|
145
|
+
content_blocks[key.to_sym] << (block_given? ? block : proc { content })
|
|
147
146
|
end
|
|
148
147
|
|
|
149
148
|
##
|
|
@@ -155,7 +154,7 @@ module Padrino
|
|
|
155
154
|
# @return [TrueClass,FalseClass] Result html for the given +key+
|
|
156
155
|
#
|
|
157
156
|
# @example
|
|
158
|
-
# content_for?
|
|
157
|
+
# content_for?(:header) => true
|
|
159
158
|
#
|
|
160
159
|
def content_for?(key)
|
|
161
160
|
!content_blocks[key.to_sym].empty?
|
|
@@ -181,10 +180,11 @@ module Padrino
|
|
|
181
180
|
def yield_content(key, *args)
|
|
182
181
|
blocks = content_blocks[key.to_sym]
|
|
183
182
|
return nil if blocks.empty?
|
|
184
|
-
blocks.inject(SafeBuffer.new){ |all,content| all << capture_html(*args, &content) }
|
|
183
|
+
blocks.inject(SafeBuffer.new) { |all, content| all << capture_html(*args, &content) }
|
|
185
184
|
end
|
|
186
185
|
|
|
187
186
|
protected
|
|
187
|
+
|
|
188
188
|
##
|
|
189
189
|
# Retrieves content_blocks stored by content_for or within yield_content.
|
|
190
190
|
#
|
|
@@ -192,7 +192,7 @@ module Padrino
|
|
|
192
192
|
# content_blocks[:name] => ['...', '...']
|
|
193
193
|
#
|
|
194
194
|
def content_blocks
|
|
195
|
-
@content_blocks ||= Hash.new { |h,k| h[k] = [] }
|
|
195
|
+
@content_blocks ||= Hash.new { |h, k| h[k] = [] }
|
|
196
196
|
end
|
|
197
197
|
|
|
198
198
|
##
|
|
@@ -203,8 +203,7 @@ module Padrino
|
|
|
203
203
|
# find_proper_handler => <OutputHelpers::HamlHandler>
|
|
204
204
|
#
|
|
205
205
|
def find_proper_handler
|
|
206
|
-
|
|
207
|
-
handler_class && handler_class.new(self)
|
|
206
|
+
OutputHelpers.handlers[current_engine]&.new(self)
|
|
208
207
|
end
|
|
209
208
|
|
|
210
209
|
##
|
|
@@ -216,9 +215,9 @@ module Padrino
|
|
|
216
215
|
# @return [SafeBuffer, Array<SafeBuffer>]
|
|
217
216
|
def mark_safe(value)
|
|
218
217
|
if value.respond_to? :map!
|
|
219
|
-
value.map!{|v| v
|
|
218
|
+
value.map! { |v| v&.html_safe }
|
|
220
219
|
else
|
|
221
|
-
value
|
|
220
|
+
value&.html_safe
|
|
222
221
|
end
|
|
223
222
|
end
|
|
224
223
|
end
|
|
@@ -23,29 +23,30 @@ module Padrino
|
|
|
23
23
|
# @return [String] The html generated from this partial.
|
|
24
24
|
#
|
|
25
25
|
# @example
|
|
26
|
-
# partial 'photo/item', :
|
|
27
|
-
# partial 'photo/item', :
|
|
28
|
-
# partial 'photo/item', :
|
|
29
|
-
# partial 'photo/item', :
|
|
26
|
+
# partial 'photo/item', object: @photo
|
|
27
|
+
# partial 'photo/item', collection: @photos
|
|
28
|
+
# partial 'photo/item', locals: { foo: :bar }
|
|
29
|
+
# partial 'photo/item', engine: :erb
|
|
30
30
|
#
|
|
31
31
|
# @note If using this from Sinatra, pass explicit +:engine+ option
|
|
32
32
|
#
|
|
33
|
-
def partial(template, options={}, &block)
|
|
34
|
-
options = { :
|
|
33
|
+
def partial(template, options = {}, &block)
|
|
34
|
+
options = { layout: false }.update(options)
|
|
35
35
|
explicit_engine = options.delete(:engine)
|
|
36
36
|
|
|
37
37
|
path, _, name = template.to_s.rpartition(File::SEPARATOR)
|
|
38
38
|
template_path = path.empty? ? :"_#{name}" : :"#{path}#{File::SEPARATOR}_#{name}"
|
|
39
39
|
item_name = name.partition('.').first.to_sym
|
|
40
40
|
|
|
41
|
-
items, counter =
|
|
42
|
-
[
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
items, counter =
|
|
42
|
+
if options[:collection].respond_to?(:inject)
|
|
43
|
+
[options.delete(:collection), 0]
|
|
44
|
+
else
|
|
45
|
+
[[options.delete(:object)], nil]
|
|
46
|
+
end
|
|
46
47
|
|
|
47
48
|
locals = options.delete(:locals) || {}
|
|
48
|
-
items.each_with_object(SafeBuffer.new) do |item,html|
|
|
49
|
+
items.each_with_object(SafeBuffer.new) do |item, html|
|
|
49
50
|
locals[item_name] = item if item
|
|
50
51
|
locals["#{item_name}_counter".to_sym] = counter += 1 if counter
|
|
51
52
|
content =
|
|
@@ -57,25 +58,25 @@ module Padrino
|
|
|
57
58
|
html.safe_concat content if content
|
|
58
59
|
end
|
|
59
60
|
end
|
|
60
|
-
alias
|
|
61
|
+
alias render_partial partial
|
|
61
62
|
|
|
62
63
|
def self.included(base)
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
return if base.instance_methods.include?(:render) || base.private_instance_methods.include?(:render)
|
|
65
|
+
|
|
66
|
+
base.class_eval do
|
|
67
|
+
raise "gem 'tilt' is required" unless defined?(::Tilt)
|
|
66
68
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
end
|
|
76
|
-
template = template_engine.new(file.to_s, options)
|
|
77
|
-
template.render(options[:scope] || self, locals, &block)
|
|
69
|
+
def render(engine, file = nil, options = {}, locals = nil, &block)
|
|
70
|
+
options.delete(:layout)
|
|
71
|
+
engine, file = file, engine if file.nil?
|
|
72
|
+
template_engine = engine ? ::Tilt[engine] : ::Tilt.default_mapping[file]
|
|
73
|
+
raise "Engine #{engine.inspect} is not registered with Tilt" unless template_engine
|
|
74
|
+
unless File.file?(file.to_s)
|
|
75
|
+
engine_extensions = ::Tilt.default_mapping.extensions_for(template_engine)
|
|
76
|
+
file = Dir.glob("#{file}.{#{engine_extensions.join(',')}}").first || raise("Template '#{file}' not found")
|
|
78
77
|
end
|
|
78
|
+
template = template_engine.new(file.to_s, options)
|
|
79
|
+
template.render(options[:scope] || self, locals, &block)
|
|
79
80
|
end
|
|
80
81
|
end
|
|
81
82
|
end
|
|
@@ -8,10 +8,10 @@ module Padrino
|
|
|
8
8
|
# Tag values escaped to html entities.
|
|
9
9
|
#
|
|
10
10
|
ESCAPE_VALUES = {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
'"' =>
|
|
11
|
+
'&' => '&',
|
|
12
|
+
'<' => '<',
|
|
13
|
+
'>' => '>',
|
|
14
|
+
'"' => '"'
|
|
15
15
|
}.freeze
|
|
16
16
|
|
|
17
17
|
##
|
|
@@ -20,25 +20,25 @@ module Padrino
|
|
|
20
20
|
#
|
|
21
21
|
ESCAPE_REGEXP = Regexp.union(*ESCAPE_VALUES.keys).freeze
|
|
22
22
|
|
|
23
|
-
BOOLEAN_ATTRIBUTES = [
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
23
|
+
BOOLEAN_ATTRIBUTES = %i[
|
|
24
|
+
autoplay
|
|
25
|
+
autofocus
|
|
26
|
+
formnovalidate
|
|
27
|
+
checked
|
|
28
|
+
disabled
|
|
29
|
+
hidden
|
|
30
|
+
loop
|
|
31
|
+
multiple
|
|
32
|
+
muted
|
|
33
|
+
readonly
|
|
34
|
+
required
|
|
35
|
+
selected
|
|
36
|
+
declare
|
|
37
|
+
defer
|
|
38
|
+
ismap
|
|
39
|
+
itemscope
|
|
40
|
+
noresize
|
|
41
|
+
novalidate
|
|
42
42
|
].freeze
|
|
43
43
|
|
|
44
44
|
##
|
|
@@ -46,14 +46,10 @@ module Padrino
|
|
|
46
46
|
# feel free to update with yours:
|
|
47
47
|
#
|
|
48
48
|
# Padrino::Helpers::TagHelpers::DATA_ATTRIBUTES.push(:dialog)
|
|
49
|
-
# text_field :foo, :
|
|
49
|
+
# text_field :foo, dialog: true
|
|
50
50
|
# # Generates: <input type="text" data-dialog="true" name="foo" />
|
|
51
51
|
#
|
|
52
|
-
DATA_ATTRIBUTES = [
|
|
53
|
-
:method,
|
|
54
|
-
:remote,
|
|
55
|
-
:confirm
|
|
56
|
-
]
|
|
52
|
+
DATA_ATTRIBUTES = %i[method remote confirm]
|
|
57
53
|
|
|
58
54
|
##
|
|
59
55
|
# A html_safe newline string to avoid allocating a new on each
|
|
@@ -102,13 +98,13 @@ module Padrino
|
|
|
102
98
|
# Generated HTML with specified +options+.
|
|
103
99
|
#
|
|
104
100
|
# @example
|
|
105
|
-
# content_tag(:p, 'Hello World', :
|
|
101
|
+
# content_tag(:p, 'Hello World', class: 'light')
|
|
106
102
|
#
|
|
107
103
|
# # => <p class="light">
|
|
108
104
|
# # => Hello World
|
|
109
105
|
# # => </p>
|
|
110
106
|
#
|
|
111
|
-
# content_tag(:p, :
|
|
107
|
+
# content_tag(:p, class: 'dark') do
|
|
112
108
|
# link_to 'Padrino', 'http://www.padrinorb.com'
|
|
113
109
|
# end
|
|
114
110
|
#
|
|
@@ -125,9 +121,13 @@ module Padrino
|
|
|
125
121
|
options = parse_data_options(name, options)
|
|
126
122
|
attributes = tag_attributes(options)
|
|
127
123
|
output = SafeBuffer.new
|
|
124
|
+
|
|
128
125
|
output.safe_concat "<#{name}#{attributes}>"
|
|
129
126
|
if content.respond_to?(:each) && !content.is_a?(String)
|
|
130
|
-
content.each
|
|
127
|
+
content.each do |item|
|
|
128
|
+
output.concat item
|
|
129
|
+
output.safe_concat NEWLINE
|
|
130
|
+
end
|
|
131
131
|
else
|
|
132
132
|
output.concat content.to_s
|
|
133
133
|
end
|
|
@@ -187,20 +187,20 @@ module Padrino
|
|
|
187
187
|
# Generated HTML with specified +options+.
|
|
188
188
|
#
|
|
189
189
|
# @example
|
|
190
|
-
# input_tag :text, :
|
|
190
|
+
# input_tag :text, name: 'handle'
|
|
191
191
|
# # => <input type="test" name="handle" />
|
|
192
192
|
#
|
|
193
|
-
# input_tag :password, :
|
|
193
|
+
# input_tag :password, name: 'password', size: 20
|
|
194
194
|
# # => <input type="password" name="password" size="20" />
|
|
195
195
|
#
|
|
196
|
-
# input_tag :text, :
|
|
196
|
+
# input_tag :text, name: 'username', required: true, autofocus: true
|
|
197
197
|
# # => <input type="text" name="username" required autofocus />
|
|
198
198
|
#
|
|
199
|
-
# input_tag :number, :
|
|
200
|
-
# # => <input type="number" name="credit_card" autocomplete="off" />
|
|
199
|
+
# input_tag :number, name: 'credit_card', autocomplete: :off
|
|
200
|
+
# # => <input type="number" name="credit_card" autocomplete="off" />
|
|
201
201
|
#
|
|
202
202
|
def input_tag(type, options = {})
|
|
203
|
-
tag(:input, { :
|
|
203
|
+
tag(:input, { type: type }.update(options))
|
|
204
204
|
end
|
|
205
205
|
|
|
206
206
|
##
|
|
@@ -217,16 +217,16 @@ module Padrino
|
|
|
217
217
|
# Generated HTML with specified +options+.
|
|
218
218
|
#
|
|
219
219
|
# @example
|
|
220
|
-
# tag :hr, :
|
|
220
|
+
# tag :hr, class: 'dotted'
|
|
221
221
|
# # => <hr class="dotted" />
|
|
222
222
|
#
|
|
223
|
-
# tag :input, :
|
|
223
|
+
# tag :input, name: 'username', type: :text
|
|
224
224
|
# # => <input name="username" type="text" />
|
|
225
225
|
#
|
|
226
|
-
# tag :img, :
|
|
226
|
+
# tag :img, src: 'images/pony.jpg', alt: 'My Little Pony'
|
|
227
227
|
# # => <img src="images/pony.jpg" alt="My Little Pony" />
|
|
228
228
|
#
|
|
229
|
-
# tag :img, :
|
|
229
|
+
# tag :img, src: 'sinatra.jpg', data: { nsfw: false, geo: [34.087, -118.407] }
|
|
230
230
|
# # => <img src="sinatra.jpg" data-nsfw="false" data-geo="34.087 -118.407" />
|
|
231
231
|
#
|
|
232
232
|
def tag(name, options = nil, open = false)
|
|
@@ -255,16 +255,19 @@ module Padrino
|
|
|
255
255
|
#
|
|
256
256
|
def tag_attributes(options)
|
|
257
257
|
return '' unless options
|
|
258
|
-
|
|
258
|
+
|
|
259
|
+
options.inject('') do |all, (key, value)|
|
|
259
260
|
next all unless value
|
|
261
|
+
|
|
260
262
|
all << ' ' if all.empty?
|
|
261
|
-
all <<
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
263
|
+
all <<
|
|
264
|
+
if value.is_a?(Hash)
|
|
265
|
+
nested_values(key, value)
|
|
266
|
+
elsif BOOLEAN_ATTRIBUTES.include?(key)
|
|
267
|
+
%(#{key}="#{key}" )
|
|
268
|
+
else
|
|
269
|
+
%(#{key}="#{escape_value(value)}" )
|
|
270
|
+
end
|
|
268
271
|
end.chomp!(' ')
|
|
269
272
|
end
|
|
270
273
|
|
|
@@ -272,7 +275,7 @@ module Padrino
|
|
|
272
275
|
# Escape tag values to their HTML/XML entities.
|
|
273
276
|
#
|
|
274
277
|
def escape_value(string)
|
|
275
|
-
string =
|
|
278
|
+
string = string.collect(&:to_s).join(' ') if string.is_a?(Array)
|
|
276
279
|
string.to_s.gsub(ESCAPE_REGEXP, ESCAPE_VALUES)
|
|
277
280
|
end
|
|
278
281
|
|
|
@@ -280,13 +283,14 @@ module Padrino
|
|
|
280
283
|
# Iterate through nested values.
|
|
281
284
|
#
|
|
282
285
|
def nested_values(attribute, hash)
|
|
283
|
-
hash.inject('') do |all,(key,value)|
|
|
286
|
+
hash.inject('') do |all, (key, value)|
|
|
284
287
|
attribute_with_name = "#{attribute}-#{key.to_s.tr('_', '-')}"
|
|
285
|
-
all <<
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
288
|
+
all <<
|
|
289
|
+
if value.is_a?(Hash)
|
|
290
|
+
nested_values(attribute_with_name, value)
|
|
291
|
+
else
|
|
292
|
+
%(#{attribute_with_name}="#{escape_value(value)}" )
|
|
293
|
+
end
|
|
290
294
|
end
|
|
291
295
|
end
|
|
292
296
|
|
|
@@ -296,7 +300,7 @@ module Padrino
|
|
|
296
300
|
def parse_data_options(tag, options)
|
|
297
301
|
return unless options
|
|
298
302
|
parsed_options = options.dup
|
|
299
|
-
options.
|
|
303
|
+
options.each_key do |key|
|
|
300
304
|
next if !DATA_ATTRIBUTES.include?(key) || (tag.to_s == 'form' && key == :method)
|
|
301
305
|
parsed_options["data-#{key}"] = parsed_options.delete(key)
|
|
302
306
|
parsed_options[:rel] = 'nofollow' if key == :method
|
|
@@ -17,7 +17,7 @@ module Padrino
|
|
|
17
17
|
options = args.last.is_a?(Hash) ? args.pop : {}
|
|
18
18
|
I18n.translate(*args, **options)
|
|
19
19
|
end
|
|
20
|
-
alias
|
|
20
|
+
alias t translate
|
|
21
21
|
|
|
22
22
|
##
|
|
23
23
|
# Delegates to I18n.localize with no additional functionality.
|
|
@@ -31,7 +31,7 @@ module Padrino
|
|
|
31
31
|
def localize(*args)
|
|
32
32
|
I18n.localize(*args)
|
|
33
33
|
end
|
|
34
|
-
alias
|
|
34
|
+
alias l localize
|
|
35
35
|
end
|
|
36
36
|
end
|
|
37
37
|
end
|
data/lib/padrino-helpers.rb
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
require 'padrino-support'
|
|
2
2
|
require 'padrino-support/inflections'
|
|
3
3
|
require 'i18n'
|
|
4
|
-
require 'enumerator'
|
|
5
4
|
|
|
6
5
|
# remove at 0.14
|
|
7
6
|
require 'padrino/rendering'
|
|
8
7
|
|
|
9
8
|
FileSet.glob_require('padrino-helpers/**/*.rb', __FILE__)
|
|
10
|
-
I18n.load_path += Dir["#{
|
|
9
|
+
I18n.load_path += Dir["#{__dir__}/padrino-helpers/locale/*.yml"]
|
|
11
10
|
I18n.enforce_available_locales = true
|
|
12
11
|
|
|
13
12
|
module Padrino
|
data/padrino-helpers.gemspec
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
#!/usr/bin/env gem build
|
|
2
2
|
# encoding: utf-8
|
|
3
3
|
|
|
4
|
-
require File.expand_path(
|
|
4
|
+
require File.expand_path('../padrino-core/lib/padrino-core/version.rb', __dir__)
|
|
5
5
|
|
|
6
6
|
Gem::Specification.new do |s|
|
|
7
|
-
s.name =
|
|
8
|
-
s.authors = [
|
|
9
|
-
s.email =
|
|
10
|
-
s.summary =
|
|
11
|
-
s.homepage =
|
|
12
|
-
s.description =
|
|
13
|
-
s.required_rubygems_version =
|
|
7
|
+
s.name = 'padrino-helpers'
|
|
8
|
+
s.authors = ['Padrino Team', 'Nathan Esquenazi', "Davide D'Agostino", 'Arthur Chiu']
|
|
9
|
+
s.email = 'padrinorb@gmail.com'
|
|
10
|
+
s.summary = 'Helpers for padrino'
|
|
11
|
+
s.homepage = 'http://www.padrinorb.com'
|
|
12
|
+
s.description = 'Tag helpers, asset helpers, form helpers, form builders and many more helpers for padrino'
|
|
13
|
+
s.required_rubygems_version = '>= 1.3.6'
|
|
14
14
|
s.version = Padrino.version
|
|
15
|
-
s.date = Time.now.strftime(
|
|
16
|
-
s.license =
|
|
15
|
+
s.date = Time.now.strftime('%Y-%m-%d')
|
|
16
|
+
s.license = 'MIT'
|
|
17
17
|
|
|
18
|
-
s.extra_rdoc_files = Dir[
|
|
18
|
+
s.extra_rdoc_files = Dir['*.rdoc']
|
|
19
19
|
s.files = `git ls-files`.split("\n")
|
|
20
20
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
21
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
|
22
|
-
s.require_paths = [
|
|
23
|
-
s.rdoc_options = [
|
|
21
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
|
22
|
+
s.require_paths = ['lib']
|
|
23
|
+
s.rdoc_options = ['--charset=UTF-8']
|
|
24
24
|
|
|
25
|
-
s.add_dependency(
|
|
26
|
-
s.add_dependency(
|
|
27
|
-
s.add_dependency(
|
|
25
|
+
s.add_dependency('padrino-support', Padrino.version)
|
|
26
|
+
s.add_dependency('tilt', '>= 2.1', '< 3')
|
|
27
|
+
s.add_dependency('i18n', '>= 0.6.7', '< 2')
|
|
28
28
|
end
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
PADRINO_ROOT =
|
|
1
|
+
PADRINO_ROOT = __dir__ unless defined? PADRINO_ROOT
|
|
2
2
|
|
|
3
3
|
class RenderDemo2 < Padrino::Application
|
|
4
4
|
register Padrino::Rendering
|
|
@@ -12,7 +12,7 @@ RenderDemo2.controllers :blog do
|
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
get '/override' do
|
|
15
|
-
render 'post', :
|
|
15
|
+
render 'post', layout: RenderDemo2.layout_path('specific')
|
|
16
16
|
end
|
|
17
17
|
end
|
|
18
18
|
|
|
@@ -7,7 +7,7 @@ class MarkupDemo < Sinatra::Base
|
|
|
7
7
|
set :logging, false
|
|
8
8
|
set :padrino_logging, false
|
|
9
9
|
set :environment, :test
|
|
10
|
-
set :root,
|
|
10
|
+
set :root, __dir__
|
|
11
11
|
set :sessions, true
|
|
12
12
|
set :protect_from_csrf, true
|
|
13
13
|
end
|
|
@@ -38,26 +38,26 @@ class MarkupDemo < Sinatra::Base
|
|
|
38
38
|
|
|
39
39
|
def concat_ruby_not_template_block
|
|
40
40
|
concat_if_block_is_template('ruby') do
|
|
41
|
-
content_tag(:span,
|
|
41
|
+
content_tag(:span, 'This not a template block')
|
|
42
42
|
end
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
def content_tag_with_block
|
|
46
46
|
one = content_tag(:p) do
|
|
47
|
-
|
|
47
|
+
'one'
|
|
48
48
|
end
|
|
49
49
|
two = content_tag(:p) do
|
|
50
|
-
|
|
50
|
+
'two'
|
|
51
51
|
end
|
|
52
52
|
one << two
|
|
53
|
-
rescue
|
|
54
|
-
|
|
53
|
+
rescue StandardError
|
|
54
|
+
'<p>failed</p>'.html_safe
|
|
55
55
|
end
|
|
56
56
|
end
|
|
57
57
|
end
|
|
58
58
|
|
|
59
59
|
class MarkupUser
|
|
60
|
-
def errors; { :
|
|
60
|
+
def errors; { fake: 'must be valid', second: 'must be present', third: 'must be a number', email: 'must be an email' }; end
|
|
61
61
|
def session_id; 45; end
|
|
62
62
|
def gender; 'male'; end
|
|
63
63
|
def remember_me; '1'; end
|
|
@@ -67,11 +67,12 @@ class MarkupUser
|
|
|
67
67
|
end
|
|
68
68
|
|
|
69
69
|
class Telephone
|
|
70
|
-
def number;
|
|
70
|
+
def number; '62634576545'; end
|
|
71
71
|
end
|
|
72
72
|
|
|
73
73
|
class Address
|
|
74
74
|
attr_accessor :name
|
|
75
|
+
|
|
75
76
|
def initialize(name, existing); @name, @existing = name, existing; end
|
|
76
77
|
def new_record?; !@existing; end
|
|
77
78
|
def id; @existing ? 25 : nil; end
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
<% button_to 'Foo button', '/foo', :
|
|
1
|
+
<% button_to 'Foo button', '/foo', class: 'foo-form' do %>
|
|
2
2
|
<% field_set_tag do %>
|
|
3
|
-
<%= hidden_field_tag :session_id, :
|
|
3
|
+
<%= hidden_field_tag :session_id, value: "__secret__" %>
|
|
4
4
|
<%= label_tag :username %>
|
|
5
5
|
<% end %>
|
|
6
6
|
<% end %>
|
|
7
|
-
<%= content_tag(:p, 'button_to test', :
|
|
7
|
+
<%= content_tag(:p, 'button_to test', id: 'test-point') %>
|
|
8
8
|
<%= button_to 'Bar button', '/bar' %>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
= button_to 'Foo button', '/foo', :
|
|
1
|
+
= button_to 'Foo button', '/foo', class: 'foo-form' do
|
|
2
2
|
= field_set_tag do
|
|
3
3
|
= label_tag :username
|
|
4
|
-
= content_tag(:p, 'button_to test', :
|
|
4
|
+
= content_tag(:p, 'button_to test', id: 'test-point')
|
|
5
5
|
= button_to 'Bar button', '/bar'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
= button_to 'Foo button', '/foo', :
|
|
1
|
+
= button_to 'Foo button', '/foo', class: 'foo-form' do
|
|
2
2
|
= field_set_tag do
|
|
3
|
-
= hidden_field_tag :session_id, :
|
|
3
|
+
= hidden_field_tag :session_id, value: '__secret__'
|
|
4
4
|
= label_tag :username
|
|
5
|
-
= content_tag(:p, 'button_to test', :
|
|
5
|
+
= content_tag(:p, 'button_to test', id: 'test-point')
|
|
6
6
|
= button_to 'Bar button', '/bar'
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
<h1>This is content yielded from a content_for</h1>
|
|
3
3
|
<% end %>
|
|
4
4
|
|
|
5
|
-
<div class=
|
|
5
|
+
<div class="demo"><%= yield_content :demo %></div>
|
|
6
6
|
|
|
7
7
|
<% content_for :demo2 do |fname, lname| %>
|
|
8
|
-
<h1>This is content yielded with name <%= fname
|
|
8
|
+
<h1>This is content yielded with name <%= "#{fname} #{lname}" %></h1>
|
|
9
9
|
<% end %>
|
|
10
10
|
|
|
11
|
-
<div class=
|
|
11
|
+
<div class="demo2"><%= yield_content :demo2, 'Johnny', 'Smith' %></div>
|
|
12
12
|
|
|
13
13
|
<div class="demo_has_content"><%= content_for?(:demo).to_s %>
|
|
14
14
|
<div class="fake_has_content"><%= content_for?(:fake).to_s %>
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
<% content_for :demo3 do %>
|
|
17
17
|
<p class="duplication">One</p>
|
|
18
18
|
<% end %>
|
|
19
|
-
<% content_for :demo3, :
|
|
19
|
+
<% content_for :demo3, flush: true do %>
|
|
20
20
|
<p class="duplication">Two</p>
|
|
21
21
|
<% end %>
|
|
22
22
|
|
|
@@ -6,14 +6,14 @@
|
|
|
6
6
|
- content_for :demo2 do |fname, lname|
|
|
7
7
|
%h1 This is content yielded with name #{fname + " " + lname}
|
|
8
8
|
|
|
9
|
-
.demo2= yield_content :demo2,
|
|
9
|
+
.demo2= yield_content :demo2, 'Johnny', 'Smith'
|
|
10
10
|
|
|
11
11
|
.demo_has_content= content_for?(:demo)
|
|
12
12
|
.fake_has_content= content_for?(:fake)
|
|
13
13
|
|
|
14
14
|
- content_for :demo3 do
|
|
15
|
-
%p{:
|
|
16
|
-
- content_for :demo3, :
|
|
17
|
-
%p{:
|
|
15
|
+
%p{class: 'duplication'} One
|
|
16
|
+
- content_for :demo3, flush: true do
|
|
17
|
+
%p{class: 'duplication'} Two
|
|
18
18
|
|
|
19
19
|
.demo3= yield_content :demo3
|