padrino-helpers 0.9.6 → 0.9.7

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 (35) hide show
  1. data/README.rdoc +19 -19
  2. data/Rakefile +1 -1
  3. data/VERSION +1 -1
  4. data/lib/padrino-helpers.rb +6 -6
  5. data/lib/padrino-helpers/asset_tag_helpers.rb +132 -110
  6. data/lib/padrino-helpers/form_builder/abstract_form_builder.rb +1 -1
  7. data/lib/padrino-helpers/form_builder/standard_form_builder.rb +2 -2
  8. data/lib/padrino-helpers/form_helpers.rb +66 -66
  9. data/lib/padrino-helpers/format_helpers.rb +29 -29
  10. data/lib/padrino-helpers/locale/de.yml +3 -3
  11. data/lib/padrino-helpers/locale/en.yml +7 -7
  12. data/lib/padrino-helpers/locale/it.yml +3 -3
  13. data/lib/padrino-helpers/number_helpers.rb +23 -23
  14. data/lib/padrino-helpers/output_helpers.rb +31 -31
  15. data/lib/padrino-helpers/render_helpers.rb +4 -4
  16. data/lib/padrino-helpers/tag_helpers.rb +11 -11
  17. data/lib/padrino-helpers/translation_helpers.rb +2 -2
  18. data/padrino-helpers.gemspec +5 -5
  19. data/test/fixtures/markup_app/views/capture_concat.erb +1 -1
  20. data/test/fixtures/markup_app/views/capture_concat.haml +1 -2
  21. data/test/fixtures/markup_app/views/content_for.erb +3 -3
  22. data/test/fixtures/markup_app/views/content_for.haml +2 -2
  23. data/test/fixtures/markup_app/views/content_tag.erb +1 -1
  24. data/test/fixtures/markup_app/views/content_tag.haml +1 -1
  25. data/test/fixtures/markup_app/views/form_for.erb +1 -1
  26. data/test/fixtures/markup_app/views/form_for.haml +2 -2
  27. data/test/fixtures/markup_app/views/form_tag.erb +1 -1
  28. data/test/fixtures/render_app/app.rb +2 -2
  29. data/test/fixtures/render_app/views/template/_user.haml +1 -1
  30. data/test/helper.rb +0 -4
  31. data/test/test_asset_tag_helpers.rb +27 -10
  32. data/test/test_form_builder.rb +18 -10
  33. data/test/test_form_helpers.rb +8 -4
  34. data/test/test_tag_helpers.rb +0 -1
  35. metadata +5 -5
@@ -8,9 +8,9 @@ de:
8
8
  format:
9
9
  unit: '€'
10
10
  format: '%n%u'
11
- separator:
12
- delimiter:
13
- precision:
11
+ separator:
12
+ delimiter:
13
+ precision:
14
14
  percentage:
15
15
  format:
16
16
  delimiter: ""
@@ -9,7 +9,7 @@ en:
9
9
  delimiter: ","
10
10
  # Number of decimals, behind the separator (the number 1 with a precision of 2 gives: 1.00)
11
11
  precision: 3
12
-
12
+
13
13
  # Used in number_to_currency()
14
14
  currency:
15
15
  format:
@@ -20,15 +20,15 @@ en:
20
20
  separator: "."
21
21
  delimiter: ","
22
22
  precision: 2
23
-
23
+
24
24
  # Used in number_to_percentage()
25
25
  percentage:
26
26
  format:
27
27
  # These three are to override number.format and are optional
28
- # separator:
28
+ # separator:
29
29
  delimiter: ""
30
- # precision:
31
-
30
+ # precision:
31
+
32
32
  # Used in number_to_precision()
33
33
  precision:
34
34
  format:
@@ -36,12 +36,12 @@ en:
36
36
  # separator:
37
37
  delimiter: ""
38
38
  # precision:
39
-
39
+
40
40
  # Used in number_to_human_size()
41
41
  human:
42
42
  format:
43
43
  # These three are to override number.format and are optional
44
- # separator:
44
+ # separator:
45
45
  delimiter: ""
46
46
  precision: 1
47
47
  storage_units:
@@ -16,7 +16,7 @@ it:
16
16
  percentage:
17
17
  format:
18
18
  delimiter: ""
19
- # precision:
19
+ # precision:
20
20
 
21
21
  precision:
22
22
  format:
@@ -27,7 +27,7 @@ it:
27
27
  human:
28
28
  format:
29
29
  # These three are to override number.format and are optional
30
- # separator:
30
+ # separator:
31
31
  delimiter: ""
32
32
  precision: 1
33
33
  storage_units:
@@ -79,7 +79,7 @@ it:
79
79
  models:
80
80
  errors:
81
81
  template:
82
- header:
82
+ header:
83
83
  one: "Non posso salvare questo {{model}}: 1 errore"
84
84
  other: "Non posso salvare questo {{model}}: {{count}} errori."
85
85
  body: "Per favore ricontrolla i seguenti campi:"
@@ -6,16 +6,16 @@ module Padrino
6
6
  # Provides methods for converting numbers into formatted strings.
7
7
  # Methods are provided for phone numbers, currency, percentage,
8
8
  # precision, positional notation, and file size.
9
- #
9
+ #
10
10
  # Verbatim copy of Rails Number Helpers
11
- #
11
+ #
12
12
  module NumberHelpers
13
13
  ##
14
14
  # Formats a +number+ into a currency string (e.g., $13.65). You can customize the format
15
15
  # in the +options+ hash.
16
16
  #
17
17
  # ==== Options
18
- #
18
+ #
19
19
  # :precision:: Sets the level of precision (defaults to 2).
20
20
  # :unit:: Sets the denomination of the currency (defaults to "$").
21
21
  # :separator:: Sets the separator between the units (defaults to ".").
@@ -26,16 +26,16 @@ module Padrino
26
26
  # %n The number
27
27
  #
28
28
  # ==== Examples
29
- #
29
+ #
30
30
  # number_to_currency(1234567890.50) # => $1,234,567,890.50
31
31
  # number_to_currency(1234567890.506) # => $1,234,567,890.51
32
32
  # number_to_currency(1234567890.506, :precision => 3) # => $1,234,567,890.506
33
- #
33
+ #
34
34
  # number_to_currency(1234567890.50, :unit => "£", :separator => ",", :delimiter => "")
35
35
  # # => £1234567890,50
36
36
  # number_to_currency(1234567890.50, :unit => "£", :separator => ",", :delimiter => "", :format => "%n %u")
37
37
  # # => 1234567890,50 £
38
- #
38
+ #
39
39
  def number_to_currency(number, options = {})
40
40
  options.symbolize_keys!
41
41
 
@@ -66,18 +66,18 @@ module Padrino
66
66
  # format in the +options+ hash.
67
67
  #
68
68
  # ==== Options
69
- #
69
+ #
70
70
  # :precision:: Sets the level of precision (defaults to 3).
71
71
  # :separator:: Sets the separator between the units (defaults to ".").
72
72
  # :delimiter:: Sets the thousands delimiter (defaults to "").
73
73
  #
74
74
  # ==== Examples
75
- #
75
+ #
76
76
  # number_to_percentage(100) # => 100.000%
77
77
  # number_to_percentage(100, :precision => 0) # => 100%
78
78
  # number_to_percentage(1000, :delimiter => '.', :separator => ',') # => 1.000,000%
79
79
  # number_to_percentage(302.24398923423, :precision => 5) # => 302.24399%
80
- #
80
+ #
81
81
  def number_to_percentage(number, options = {})
82
82
  options.symbolize_keys!
83
83
 
@@ -104,12 +104,12 @@ module Padrino
104
104
  # customize the format in the +options+ hash.
105
105
  #
106
106
  # ==== Options
107
- #
107
+ #
108
108
  # :delimiter:: Sets the thousands delimiter (defaults to ",").
109
109
  # :separator:: Sets the separator between the units (defaults to ".").
110
110
  #
111
111
  # ==== Examples
112
- #
112
+ #
113
113
  # number_with_delimiter(12345678) # => 12,345,678
114
114
  # number_with_delimiter(12345678.05) # => 12,345,678.05
115
115
  # number_with_delimiter(12345678, :delimiter => ".") # => 12.345.678
@@ -120,10 +120,10 @@ module Padrino
120
120
  # You can still use <tt>number_with_delimiter</tt> with the old API that accepts the
121
121
  # +delimiter+ as its optional second and the +separator+ as its
122
122
  # optional third parameter:
123
- #
123
+ #
124
124
  # number_with_delimiter(12345678, " ") # => 12 345.678
125
125
  # number_with_delimiter(12345678.05, ".", ",") # => 12.345.678,05
126
- #
126
+ #
127
127
  def number_with_delimiter(number, *args)
128
128
  options = args.extract_options!
129
129
  options.symbolize_keys!
@@ -147,13 +147,13 @@ module Padrino
147
147
  # You can customize the format in the +options+ hash.
148
148
  #
149
149
  # ==== Options
150
- #
150
+ #
151
151
  # :precision:: Sets the level of precision (defaults to 3).
152
152
  # :separator:: Sets the separator between the units (defaults to ".").
153
153
  # :delimiter:: Sets the thousands delimiter (defaults to "").
154
154
  #
155
155
  # ==== Examples
156
- #
156
+ #
157
157
  # number_with_precision(111.2345) # => 111.235
158
158
  # number_with_precision(111.2345, :precision => 2) # => 111.23
159
159
  # number_with_precision(13, :precision => 5) # => 13.00000
@@ -163,9 +163,9 @@ module Padrino
163
163
  #
164
164
  # You can still use <tt>number_with_precision</tt> with the old API that accepts the
165
165
  # +precision+ as its optional second parameter:
166
- #
166
+ #
167
167
  # number_with_precision(number_with_precision(111.2345, 2) # => 111.23
168
- #
168
+ #
169
169
  def number_with_precision(number, *args)
170
170
  options = args.extract_options!
171
171
  options.symbolize_keys!
@@ -199,13 +199,13 @@ module Padrino
199
199
  # format in the +options+ hash.
200
200
  #
201
201
  # ==== Options
202
- #
202
+ #
203
203
  # :precision:: Sets the level of precision (defaults to 1).
204
204
  # :separator:: Sets the separator between the units (defaults to ".").
205
205
  # :delimiter:: Sets the thousands delimiter (defaults to "").
206
206
  #
207
207
  # ==== Examples
208
- #
208
+ #
209
209
  # number_to_human_size(123) # => 123 Bytes
210
210
  # number_to_human_size(1234) # => 1.2 KB
211
211
  # number_to_human_size(12345) # => 12.1 KB
@@ -218,16 +218,16 @@ module Padrino
218
218
  #
219
219
  # Zeros after the decimal point are always stripped out, regardless of the
220
220
  # specified precision:
221
- #
221
+ #
222
222
  # helper.number_to_human_size(1234567890123, :precision => 5) # => "1.12283 TB"
223
223
  # helper.number_to_human_size(524288000, :precision=>5) # => "500 MB"
224
224
  #
225
225
  # You can still use <tt>number_to_human_size</tt> with the old API that accepts the
226
226
  # +precision+ as its optional second parameter:
227
- #
227
+ #
228
228
  # number_to_human_size(1234567, 2) # => 1.18 MB
229
229
  # number_to_human_size(483989, 0) # => 473 KB
230
- #
230
+ #
231
231
  def number_to_human_size(number, *args)
232
232
  return nil if number.nil?
233
233
 
@@ -272,4 +272,4 @@ module Padrino
272
272
  end
273
273
  end # NumberHelpers
274
274
  end # Helpers
275
- end # Padrino
275
+ end # Padrino
@@ -3,11 +3,11 @@ module Padrino
3
3
  module OutputHelpers
4
4
  ##
5
5
  # Captures the html from a block of template code for erb or haml
6
- #
6
+ #
7
7
  # ==== Examples
8
- #
8
+ #
9
9
  # capture_html(&block) => "...html..."
10
- #
10
+ #
11
11
  def capture_html(*args, &block)
12
12
  if self.respond_to?(:is_haml?) && is_haml?
13
13
  block_is_haml?(block) ? capture_haml(*args, &block) : block.call
@@ -21,11 +21,11 @@ module Padrino
21
21
 
22
22
  ##
23
23
  # Outputs the given text to the templates buffer directly
24
- #
24
+ #
25
25
  # ==== Examples
26
- #
26
+ #
27
27
  # concat_content("This will be output to the template buffer in erb or haml")
28
- #
28
+ #
29
29
  def concat_content(text="")
30
30
  if self.respond_to?(:is_haml?) && is_haml?
31
31
  haml_concat(text)
@@ -39,11 +39,11 @@ module Padrino
39
39
  ##
40
40
  # Returns true if the block is from an ERB or HAML template; false otherwise.
41
41
  # Used to determine if html should be returned or concatted to view
42
- #
42
+ #
43
43
  # ==== Examples
44
- #
44
+ #
45
45
  # block_is_template?(block)
46
- #
46
+ #
47
47
  def block_is_template?(block)
48
48
  block && (block_is_erb?(block) || (self.respond_to?(:block_is_haml?) && block_is_haml?(block)))
49
49
  end
@@ -51,13 +51,13 @@ module Padrino
51
51
  ##
52
52
  # Capture a block or text of content to be rendered at a later time.
53
53
  # Your blocks can also receive values, which are passed to them by <tt>yield_content</tt>
54
- #
54
+ #
55
55
  # ==== Examples
56
- #
56
+ #
57
57
  # content_for(:name) { ...content... }
58
58
  # content_for(:name) { |name| ...content... }
59
59
  # content_for(:name, "I'm Jeff")
60
- #
60
+ #
61
61
  def content_for(key, content = nil, &block)
62
62
  content_blocks[key.to_sym] << (block_given? ? block : Proc.new { content })
63
63
  end
@@ -66,13 +66,13 @@ module Padrino
66
66
  # Render the captured content blocks for a given key.
67
67
  # You can also pass values to the content blocks by passing them
68
68
  # as arguments after the key.
69
- #
69
+ #
70
70
  # ==== Examples
71
- #
71
+ #
72
72
  # yield_content :include
73
73
  # yield_content :head, "param1", "param2"
74
74
  # yield_content(:title) || "My page title"
75
- #
75
+ #
76
76
  def yield_content(key, *args)
77
77
  blocks = content_blocks[key.to_sym]
78
78
  return nil if blocks.empty?
@@ -84,44 +84,44 @@ module Padrino
84
84
  private
85
85
  ##
86
86
  # Retrieves content_blocks stored by content_for or within yield_content
87
- #
87
+ #
88
88
  # ==== Examples
89
- #
89
+ #
90
90
  # content_blocks[:name] => ['...', '...']
91
- #
91
+ #
92
92
  def content_blocks
93
93
  @content_blocks ||= Hash.new {|h,k| h[k] = [] }
94
94
  end
95
95
 
96
96
  ##
97
97
  # Used to capture the html from a block of erb code
98
- #
98
+ #
99
99
  # ==== Examples
100
- #
100
+ #
101
101
  # capture_erb(&block) => '...html...'
102
- #
102
+ #
103
103
  def capture_erb(*args, &block)
104
104
  erb_with_output_buffer { block_given? && block.call(*args) }
105
105
  end
106
106
 
107
107
  ##
108
108
  # Concats directly to an erb template
109
- #
109
+ #
110
110
  # ==== Examples
111
- #
111
+ #
112
112
  # erb_concat("Direct to buffer")
113
- #
113
+ #
114
114
  def erb_concat(text)
115
115
  @_out_buf << text if has_erb_buffer?
116
116
  end
117
117
 
118
118
  ##
119
119
  # Returns true if an erb buffer is detected
120
- #
120
+ #
121
121
  # ==== Examples
122
- #
122
+ #
123
123
  # has_erb_buffer? => true
124
- #
124
+ #
125
125
  def has_erb_buffer?
126
126
  !@_out_buf.nil?
127
127
  end
@@ -132,17 +132,17 @@ module Padrino
132
132
  # can't take an <% end %> later on, so we have to use <% ... %>
133
133
  # and implicitly concat.
134
134
  def block_is_erb?(block)
135
- has_erb_buffer? || block && eval('defined? __in_erb_template', block)
135
+ has_erb_buffer? || (block && eval('defined? __in_erb_template', block))
136
136
  end
137
137
  else
138
138
  def block_is_erb?(block)
139
- has_erb_buffer? || block && eval('defined? __in_erb_template', block.binding)
139
+ has_erb_buffer? || (block && eval('defined? __in_erb_template', block.binding))
140
140
  end
141
141
  end
142
142
 
143
143
  ##
144
144
  # Used to direct the buffer for the erb capture
145
- #
145
+ #
146
146
  def erb_with_output_buffer(buf = '')
147
147
  @_out_buf, old_buffer = buf, @_out_buf
148
148
  yield
@@ -152,4 +152,4 @@ module Padrino
152
152
  end
153
153
  end # OutputHelpers
154
154
  end # Helpers
155
- end # Padrino
155
+ end # Padrino
@@ -3,13 +3,13 @@ module Padrino
3
3
  module RenderHelpers
4
4
  ##
5
5
  # Partials implementation which includes collections support
6
- #
6
+ #
7
7
  # ==== Examples
8
- #
8
+ #
9
9
  # partial 'photo/item', :object => @photo
10
10
  # partial 'photo/item', :collection => @photos
11
11
  # partial 'photo/item', :locals => { :foo => :bar }
12
- #
12
+ #
13
13
  def partial(template, options={})
14
14
  options.reverse_merge!(:locals => {}, :layout => false)
15
15
  path = template.to_s.split(File::SEPARATOR)
@@ -35,4 +35,4 @@ module Padrino
35
35
  alias :render_partial :partial
36
36
  end # RenderHelpers
37
37
  end # Helpers
38
- end # Padrino
38
+ end # Padrino
@@ -3,11 +3,11 @@ module Padrino
3
3
  module TagHelpers
4
4
  ##
5
5
  # Creates an html input field with given type and options
6
- #
6
+ #
7
7
  # ==== Examples
8
- #
8
+ #
9
9
  # input_tag :text, :class => "test"
10
- #
10
+ #
11
11
  def input_tag(type, options = {})
12
12
  options.reverse_merge!(:type => type)
13
13
  tag(:input, options)
@@ -15,13 +15,13 @@ module Padrino
15
15
 
16
16
  ##
17
17
  # Creates an html tag with given name, content and options
18
- #
18
+ #
19
19
  # ==== Examples
20
- #
20
+ #
21
21
  # content_tag(:p, "hello", :class => 'light')
22
22
  # content_tag(:p, :class => 'dark') do ... end
23
23
  # content_tag(name, content=nil, options={}, &block)
24
- #
24
+ #
25
25
  def content_tag(*args, &block)
26
26
  name = args.first
27
27
  options = args.extract_options!
@@ -32,12 +32,12 @@ module Padrino
32
32
 
33
33
  ##
34
34
  # Creates an html tag with the given name and options
35
- #
35
+ #
36
36
  # ==== Examples
37
- #
37
+ #
38
38
  # tag(:br, :style => 'clear:both')
39
39
  # tag(:p, :content => "hello", :class => 'large')
40
- #
40
+ #
41
41
  def tag(name, options={})
42
42
  content, open_tag = options.delete(:content), options.delete(:open)
43
43
  content = content.join("\n") if content.respond_to?(:join)
@@ -50,10 +50,10 @@ module Padrino
50
50
  private
51
51
  ##
52
52
  # Returns a list of attributes which can only contain an identity value (i.e selected)
53
- #
53
+ #
54
54
  def identity_tag_attributes
55
55
  [:checked, :disabled, :selected, :multiple]
56
56
  end
57
57
  end # TagHelpers
58
58
  end # Helpers
59
- end # Padrino
59
+ end # Padrino