padrino-helpers 0.11.3 → 0.11.4

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.
Files changed (50) hide show
  1. checksums.yaml +7 -0
  2. data/README.rdoc +1 -1
  3. data/lib/padrino-helpers.rb +3 -5
  4. data/lib/padrino-helpers/asset_tag_helpers.rb +32 -40
  5. data/lib/padrino-helpers/breadcrumb_helpers.rb +21 -39
  6. data/lib/padrino-helpers/form_builder/abstract_form_builder.rb +121 -118
  7. data/lib/padrino-helpers/form_builder/standard_form_builder.rb +6 -9
  8. data/lib/padrino-helpers/form_helpers.rb +190 -193
  9. data/lib/padrino-helpers/format_helpers.rb +29 -42
  10. data/lib/padrino-helpers/locale/cs.yml +14 -14
  11. data/lib/padrino-helpers/locale/da.yml +1 -1
  12. data/lib/padrino-helpers/locale/de.yml +1 -1
  13. data/lib/padrino-helpers/locale/en.yml +16 -16
  14. data/lib/padrino-helpers/locale/es.yml +16 -16
  15. data/lib/padrino-helpers/locale/fr.yml +1 -2
  16. data/lib/padrino-helpers/locale/hu.yml +16 -16
  17. data/lib/padrino-helpers/locale/it.yml +2 -2
  18. data/lib/padrino-helpers/locale/ja.yml +16 -16
  19. data/lib/padrino-helpers/locale/lv.yml +16 -16
  20. data/lib/padrino-helpers/locale/nl.yml +1 -1
  21. data/lib/padrino-helpers/locale/no.yml +1 -1
  22. data/lib/padrino-helpers/locale/pl.yml +7 -7
  23. data/lib/padrino-helpers/locale/pt_br.yml +16 -16
  24. data/lib/padrino-helpers/locale/ro.yml +16 -16
  25. data/lib/padrino-helpers/locale/ru.yml +16 -16
  26. data/lib/padrino-helpers/locale/sv.yml +16 -16
  27. data/lib/padrino-helpers/locale/tr.yml +16 -16
  28. data/lib/padrino-helpers/locale/uk.yml +16 -16
  29. data/lib/padrino-helpers/locale/zh_cn.yml +16 -16
  30. data/lib/padrino-helpers/locale/zh_tw.yml +16 -16
  31. data/lib/padrino-helpers/number_helpers.rb +10 -15
  32. data/lib/padrino-helpers/output_helpers.rb +49 -57
  33. data/lib/padrino-helpers/output_helpers/abstract_handler.rb +16 -18
  34. data/lib/padrino-helpers/output_helpers/erb_handler.rb +11 -12
  35. data/lib/padrino-helpers/output_helpers/haml_handler.rb +9 -9
  36. data/lib/padrino-helpers/output_helpers/slim_handler.rb +11 -13
  37. data/lib/padrino-helpers/render_helpers.rb +5 -6
  38. data/lib/padrino-helpers/tag_helpers.rb +18 -21
  39. data/lib/padrino-helpers/translation_helpers.rb +4 -6
  40. data/test/fixtures/markup_app/app.rb +7 -3
  41. data/test/fixtures/render_app/app.rb +1 -0
  42. data/test/test_asset_tag_helpers.rb +1 -1
  43. data/test/test_form_builder.rb +5 -6
  44. data/test/test_form_helpers.rb +24 -12
  45. data/test/test_format_helpers.rb +3 -3
  46. data/test/test_number_helpers.rb +4 -0
  47. data/test/test_output_helpers.rb +1 -1
  48. data/test/test_render_helpers.rb +1 -1
  49. data/test/test_tag_helpers.rb +1 -1
  50. metadata +9 -15
@@ -29,7 +29,7 @@ module Padrino
29
29
  # %u The currency unit
30
30
  # %n The number
31
31
  #
32
- # @return [String] The formatted representation of the currency
32
+ # @return [String] The formatted representation of the currency.
33
33
  #
34
34
  # @example
35
35
  # number_to_currency(1234567890.50) # => $1,234,567,890.50
@@ -40,7 +40,6 @@ module Padrino
40
40
  # number_to_currency(1234567890.50, :unit => "£", :separator => ",", :delimiter => "", :format => "%n %u")
41
41
  # # => 1234567890,50 £
42
42
  #
43
- # @api public
44
43
  def number_to_currency(number, options = {})
45
44
  options.symbolize_keys!
46
45
 
@@ -79,7 +78,7 @@ module Padrino
79
78
  # @option options [String] :separator (".")
80
79
  # Sets the separator between the units.
81
80
  # @option options [String] :delimiter ("")
82
- # Sets the thousands delimiter
81
+ # Sets the thousands delimiter.
83
82
  #
84
83
  # @return [String] The formatted representation of the percentage
85
84
  #
@@ -89,7 +88,6 @@ module Padrino
89
88
  # number_to_percentage(1000, :delimiter => '.', :separator => ',') # => 1.000,000%
90
89
  # number_to_percentage(302.24398923423, :precision => 5) # => 302.24399%
91
90
  #
92
- # @api public
93
91
  def number_to_percentage(number, options = {})
94
92
  options.symbolize_keys!
95
93
 
@@ -121,11 +119,11 @@ module Padrino
121
119
  # @param [Hash] options
122
120
  # Options for formatter.
123
121
  # @option options [String] :delimiter (", ")
124
- # Sets the thousands delimiter
122
+ # Sets the thousands delimiter.
125
123
  # @option options [String] :separator (".")
126
124
  # Sets the separator between the units.
127
125
  #
128
- # @return [String] The formatted representation of the number
126
+ # @return [String] The formatted representation of the number.
129
127
  #
130
128
  # @example
131
129
  # number_with_delimiter(12345678) # => 12,345,678
@@ -135,7 +133,6 @@ module Padrino
135
133
  # number_with_delimiter(98765432.98, :delimiter => " ", :separator => ",")
136
134
  # # => 98 765 432,98
137
135
  #
138
- # @api public
139
136
  def number_with_delimiter(number, *args)
140
137
  options = args.extract_options!
141
138
  options.symbolize_keys!
@@ -168,9 +165,9 @@ module Padrino
168
165
  # @option options [String] :separator (".")
169
166
  # Sets the separator between the units.
170
167
  # @option options [String] :delimiter ("")
171
- # Sets the thousands delimiter
168
+ # Sets the thousands delimiter.
172
169
  #
173
- # @return [String] The formatted representation of the number
170
+ # @return [String] The formatted representation of the number.
174
171
  #
175
172
  # @example
176
173
  # number_with_precision(111.2345) # => 111.235
@@ -180,7 +177,6 @@ module Padrino
180
177
  # number_with_precision(1111.2345, :precision => 2, :separator => ',', :delimiter => '.')
181
178
  # # => 1.111,23
182
179
  #
183
- # @api public
184
180
  def number_with_precision(number, *args)
185
181
  options = args.extract_options!
186
182
  options.symbolize_keys!
@@ -225,7 +221,7 @@ module Padrino
225
221
  # @option options [String] :separator (".")
226
222
  # Sets the separator between the units.
227
223
  # @option options [String] :delimiter ("")
228
- # Sets the thousands delimiter
224
+ # Sets the thousands delimiter.
229
225
  #
230
226
  # @return [String] The formatted representation of bytes
231
227
  #
@@ -240,7 +236,6 @@ module Padrino
240
236
  # number_to_human_size(483989, :precision => 0) # => 473 KB
241
237
  # number_to_human_size(1234567, :precision => 2, :separator => ',') # => 1,18 MB
242
238
  #
243
- # @api public
244
239
  def number_to_human_size(number, *args)
245
240
  return nil if number.nil?
246
241
 
@@ -283,6 +278,6 @@ module Padrino
283
278
  end
284
279
  end
285
280
  end
286
- end # NumberHelpers
287
- end # Helpers
288
- end # Padrino
281
+ end
282
+ end
283
+ end
@@ -1,21 +1,20 @@
1
1
  module Padrino
2
2
  module Helpers
3
- ###
3
+ ##
4
4
  # Helpers related to buffer output for various template engines.
5
5
  #
6
6
  module OutputHelpers
7
-
8
- def self.included(base) # @private
7
+ def self.included(base)
9
8
  base.send(:include, SinatraCurrentEngine) unless base.method_defined?(:current_engine)
10
9
  end
11
10
 
12
11
  ##
13
- # Module used to detect the current engine in vanilla sinatra apps.
14
- # @private
12
+ # Module used to detect the current engine in vanilla Sinatra apps.
13
+ #
15
14
  module SinatraCurrentEngine
16
15
  attr_reader :current_engine
17
16
 
18
- def render(engine, *) # @private
17
+ def render(engine, *)
19
18
  @current_engine, engine_was = engine, @current_engine
20
19
  output = super
21
20
  @current_engine = engine_was
@@ -29,11 +28,11 @@ module Padrino
29
28
  # Be aware that trusting the html is up to the caller.
30
29
  #
31
30
  # @param [Object] *args
32
- # Objects yield to the captured block
31
+ # Objects yield to the captured block.
33
32
  # @param [Proc] &block
34
- # Template code to capture as html
33
+ # Template code to capture as HTML.
35
34
  #
36
- # @return [String] Captured html resulting from the block
35
+ # @return [String] Captured HTML resulting from the block.
37
36
  #
38
37
  # @example
39
38
  # capture_html(&block) => "...html..."
@@ -45,7 +44,6 @@ module Padrino
45
44
  # ActiveSupport::SafeBuffer.new.safe_concat(capture_html { "<foo>" })
46
45
  # # => "<foo>"
47
46
  #
48
- # @api semipublic
49
47
  def capture_html(*args, &block)
50
48
  handler = find_proper_handler
51
49
  captured_block, captured_html = nil, ""
@@ -63,13 +61,12 @@ module Padrino
63
61
  #
64
62
  # The output might be subject to escaping, if it is not marked as safe.
65
63
  #
66
- # @param [String,SafeBuffer] text
64
+ # @param [String, SafeBuffer] text
67
65
  # Text to concatenate to the buffer.
68
66
  #
69
67
  # @example
70
68
  # concat_content("This will be output to the template buffer")
71
69
  #
72
- # @api semipublic
73
70
  def concat_content(text="")
74
71
  handler = find_proper_handler
75
72
  if handler && handler.is_type?
@@ -90,7 +87,6 @@ module Padrino
90
87
  # @example
91
88
  # concat_safe_content("This will be output to the template buffer")
92
89
  #
93
- # @api semipublic
94
90
  def concat_safe_content(text="")
95
91
  concat_content text.html_safe
96
92
  end
@@ -107,7 +103,6 @@ module Padrino
107
103
  #
108
104
  # @return [Boolean] True if the block is a template; false otherwise.
109
105
  #
110
- # @api semipublic
111
106
  def block_is_template?(block)
112
107
  handler = find_proper_handler
113
108
  block && handler && handler.block_is_type?(block)
@@ -115,7 +110,7 @@ module Padrino
115
110
 
116
111
  ##
117
112
  # Capture a block or text of content to be rendered at a later time.
118
- # Your blocks can also receive values, which are passed to them by <tt>yield_content</tt>
113
+ # Your blocks can also receive values, which are passed to them by <tt>yield_content</tt>.
119
114
  #
120
115
  # @overload content_for(key, content)
121
116
  # @param [Symbol] key Name of your key for the content yield.
@@ -129,7 +124,6 @@ module Padrino
129
124
  # content_for(:name) { |name| ...content... }
130
125
  # content_for(:name, "I'm Jeff")
131
126
  #
132
- # @api public
133
127
  def content_for(key, content = nil, &block)
134
128
  content_blocks[key.to_sym] << (block_given? ? block : Proc.new { content })
135
129
  end
@@ -138,14 +132,13 @@ module Padrino
138
132
  # Is there a content block for a given key?
139
133
  #
140
134
  # @param [Symbol] key
141
- # Name of content to yield
135
+ # Name of content to yield.
142
136
  #
143
137
  # @return [TrueClass,FalseClass] Result html for the given +key+
144
138
  #
145
139
  # @example
146
140
  # content_for? :header => true
147
141
  #
148
- # @api public
149
142
  def content_for?(key)
150
143
  content_blocks[key.to_sym].present?
151
144
  end
@@ -156,18 +149,17 @@ module Padrino
156
149
  # as arguments after the key.
157
150
  #
158
151
  # @param [Symbol] key
159
- # Name of content to yield
152
+ # Name of content to yield.
160
153
  # @param *args
161
- # Values to pass to the content block
154
+ # Values to pass to the content block.
162
155
  #
163
- # @return [String] Result html for the given +key+
156
+ # @return [String] Result HTML for the given +key+.
164
157
  #
165
158
  # @example
166
159
  # yield_content :include
167
160
  # yield_content :head, "param1", "param2"
168
161
  # yield_content(:title) || "My page title"
169
162
  #
170
- # @api public
171
163
  def yield_content(key, *args)
172
164
  blocks = content_blocks[key.to_sym]
173
165
  return nil if blocks.empty?
@@ -175,41 +167,41 @@ module Padrino
175
167
  end
176
168
 
177
169
  protected
178
- ##
179
- # Retrieves content_blocks stored by content_for or within yield_content
180
- #
181
- # @example
182
- # content_blocks[:name] => ['...', '...']
183
- #
184
- def content_blocks
185
- @content_blocks ||= Hash.new { |h,k| h[k] = [] }
186
- end
170
+ ##
171
+ # Retrieves content_blocks stored by content_for or within yield_content.
172
+ #
173
+ # @example
174
+ # content_blocks[:name] => ['...', '...']
175
+ #
176
+ def content_blocks
177
+ @content_blocks ||= Hash.new { |h,k| h[k] = [] }
178
+ end
187
179
 
188
- ##
189
- # Retrieves the template handler for the given output context.
190
- # Can handle any output related to capturing or concating in a given template.
191
- #
192
- # @example
193
- # find_proper_handler => <OutputHelpers::HamlHandler>
194
- #
195
- def find_proper_handler
196
- OutputHelpers.handlers.map { |h| h.new(self) }.find { |h| h.engines.include?(current_engine) && h.is_type? }
197
- end
180
+ ##
181
+ # Retrieves the template handler for the given output context.
182
+ # Can handle any output related to capturing or concatenating in a given template.
183
+ #
184
+ # @example
185
+ # find_proper_handler => <OutputHelpers::HamlHandler>
186
+ #
187
+ def find_proper_handler
188
+ OutputHelpers.handlers.map { |h| h.new(self) }.find { |h| h.engines.include?(current_engine) && h.is_type? }
189
+ end
198
190
 
199
- ##
200
- # Marks a String or a collection of Strings as safe. `nil` is accepted
201
- # but ignored.
202
- #
203
- # @param [String, Array<String>] the values to be marked safe.
204
- #
205
- # @return [ActiveSupport::SafeBuffer, Array<ActiveSupport::SafeBuffer>]
206
- def mark_safe(value)
207
- if value.respond_to? :map!
208
- value.map!{|v| v.html_safe if v }
209
- else
210
- value.html_safe if value
211
- end
191
+ ##
192
+ # Marks a String or a collection of Strings as safe. `nil` is accepted
193
+ # but ignored.
194
+ #
195
+ # @param [String, Array<String>] the values to be marked safe.
196
+ #
197
+ # @return [ActiveSupport::SafeBuffer, Array<ActiveSupport::SafeBuffer>]
198
+ def mark_safe(value)
199
+ if value.respond_to? :map!
200
+ value.map!{|v| v.html_safe if v }
201
+ else
202
+ value.html_safe if value
212
203
  end
213
- end # OutputHelpers
214
- end # Helpers
215
- end # Padrino
204
+ end
205
+ end
206
+ end
207
+ end
@@ -2,28 +2,26 @@ module Padrino
2
2
  module Helpers
3
3
  module OutputHelpers
4
4
  ##
5
- # Returns the list of all available template handlers
5
+ # Returns the list of all available template handlers.
6
6
  #
7
7
  # @example
8
8
  # OutputHelpers.handlers => [<OutputHelpers::HamlHandler>, <OutputHelpers::ErbHandler>]
9
9
  #
10
- # @private
11
10
  def self.handlers
12
11
  @_template_handlers ||= []
13
12
  end
14
13
 
15
14
  ##
16
- # Registers a new handler as available to the output helpers
15
+ # Registers a new handler as available to the output helpers.
17
16
  #
18
17
  # @example
19
18
  # OutputHelpers.register(OutputHelpers::HamlHandler)
20
19
  #
21
- # @private
22
20
  def self.register(handler)
23
21
  handlers << handler
24
22
  end
25
23
 
26
- # @abstract Extend this to create a template handler
24
+ # @abstract Extend this to create a template handler.
27
25
  class AbstractHandler
28
26
  attr_reader :template
29
27
 
@@ -32,7 +30,7 @@ module Padrino
32
30
  end
33
31
 
34
32
  ##
35
- # Returns extension of the template
33
+ # Returns extension of the template.
36
34
  #
37
35
  # @example
38
36
  # @handler.template_extension => "erb"
@@ -44,13 +42,13 @@ module Padrino
44
42
  end
45
43
 
46
44
  ##
47
- # Returns an array of engines used for the template
45
+ # Returns an array of engines used for the template.
48
46
  #
49
47
  # @example
50
48
  # @handler.engines => [:erb, :erubis]
51
49
  #
52
50
  def engines
53
- # Implemented in subclass
51
+ # Implemented in subclass.
54
52
  end
55
53
 
56
54
  ##
@@ -60,7 +58,7 @@ module Padrino
60
58
  # @handler.is_type? => true
61
59
  #
62
60
  def is_type?
63
- # Implemented in subclass
61
+ # Implemented in subclass.
64
62
  end
65
63
 
66
64
  ##
@@ -70,29 +68,29 @@ module Padrino
70
68
  # @handler.block_is_type?(block) => true
71
69
  #
72
70
  def block_is_type?(block)
73
- # Implemented in subclass
71
+ # Implemented in subclass.
74
72
  end
75
73
 
76
74
  ##
77
- # Captures the html from a block of template code for this handler
75
+ # Captures the html from a block of template code for this handler.
78
76
  #
79
77
  # @example
80
78
  # @handler.capture_from_template(&block) => "...html..."
81
79
  #
82
80
  def capture_from_template(*args, &block)
83
- # Implemented in subclass
81
+ # Implemented in subclass.
84
82
  end
85
83
 
86
84
  ##
87
- # Outputs the given text to the templates buffer directly
85
+ # Outputs the given text to the templates buffer directly.
88
86
  #
89
87
  # @example
90
88
  # @handler.concat_to_template("This will be output to the template buffer")
91
89
  #
92
90
  def concat_to_template(text="")
93
- # Implemented in subclass
91
+ # Implemented in subclass.
94
92
  end
95
- end # AbstractHandler
96
- end # OutputHelpers
97
- end # Helpers
98
- end # Padrino
93
+ end
94
+ end
95
+ end
96
+ end
@@ -22,7 +22,8 @@ module Padrino
22
22
  !self.output_buffer.nil?
23
23
  end
24
24
 
25
- # Captures the html from a block of template code for this handler
25
+ ##
26
+ # Captures the html from a block of template code for this handler.
26
27
  #
27
28
  # @example
28
29
  # @handler.capture_from_template(&block) => "...html..."
@@ -36,7 +37,7 @@ module Padrino
36
37
  end
37
38
 
38
39
  ##
39
- # Outputs the given text to the templates buffer directly
40
+ # Outputs the given text to the templates buffer directly.
40
41
  #
41
42
  # @example
42
43
  # @handler.concat_to_template("This will be output to the template buffer")
@@ -57,7 +58,7 @@ module Padrino
57
58
  end
58
59
 
59
60
  ##
60
- # Returns an array of engines used for the template
61
+ # Returns an array of engines used for the template.
61
62
  #
62
63
  # @example
63
64
  # @handler.engines => [:erb, :erubis]
@@ -67,13 +68,11 @@ module Padrino
67
68
  end
68
69
 
69
70
  protected
70
-
71
- def output_buffer=(val)
72
- template.instance_variable_set(:@_out_buf, val)
73
- end
74
- end # ErbHandler
75
-
71
+ def output_buffer=(val)
72
+ template.instance_variable_set(:@_out_buf, val)
73
+ end
74
+ end
76
75
  OutputHelpers.register(ErbHandler)
77
- end # OutputHelpers
78
- end # Helpers
79
- end # Padrino
76
+ end
77
+ end
78
+ end