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.
- data/README.rdoc +19 -19
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/padrino-helpers.rb +6 -6
- data/lib/padrino-helpers/asset_tag_helpers.rb +132 -110
- data/lib/padrino-helpers/form_builder/abstract_form_builder.rb +1 -1
- data/lib/padrino-helpers/form_builder/standard_form_builder.rb +2 -2
- data/lib/padrino-helpers/form_helpers.rb +66 -66
- data/lib/padrino-helpers/format_helpers.rb +29 -29
- data/lib/padrino-helpers/locale/de.yml +3 -3
- data/lib/padrino-helpers/locale/en.yml +7 -7
- data/lib/padrino-helpers/locale/it.yml +3 -3
- data/lib/padrino-helpers/number_helpers.rb +23 -23
- data/lib/padrino-helpers/output_helpers.rb +31 -31
- data/lib/padrino-helpers/render_helpers.rb +4 -4
- data/lib/padrino-helpers/tag_helpers.rb +11 -11
- data/lib/padrino-helpers/translation_helpers.rb +2 -2
- data/padrino-helpers.gemspec +5 -5
- data/test/fixtures/markup_app/views/capture_concat.erb +1 -1
- data/test/fixtures/markup_app/views/capture_concat.haml +1 -2
- data/test/fixtures/markup_app/views/content_for.erb +3 -3
- data/test/fixtures/markup_app/views/content_for.haml +2 -2
- data/test/fixtures/markup_app/views/content_tag.erb +1 -1
- data/test/fixtures/markup_app/views/content_tag.haml +1 -1
- data/test/fixtures/markup_app/views/form_for.erb +1 -1
- data/test/fixtures/markup_app/views/form_for.haml +2 -2
- data/test/fixtures/markup_app/views/form_tag.erb +1 -1
- data/test/fixtures/render_app/app.rb +2 -2
- data/test/fixtures/render_app/views/template/_user.haml +1 -1
- data/test/helper.rb +0 -4
- data/test/test_asset_tag_helpers.rb +27 -10
- data/test/test_form_builder.rb +18 -10
- data/test/test_form_helpers.rb +8 -4
- data/test/test_tag_helpers.rb +0 -1
- metadata +5 -5
@@ -7,14 +7,14 @@ module Padrino
|
|
7
7
|
|
8
8
|
##
|
9
9
|
# StandardFormBuilder
|
10
|
-
#
|
10
|
+
#
|
11
11
|
# text_field_block(:username, { :class => 'long' }, { :class => 'wide-label' })
|
12
12
|
# text_area_block(:summary, { :class => 'long' }, { :class => 'wide-label' })
|
13
13
|
# password_field_block(:password, { :class => 'long' }, { :class => 'wide-label' })
|
14
14
|
# file_field_block(:photo, { :class => 'long' }, { :class => 'wide-label' })
|
15
15
|
# check_box_block(:remember_me, { :class => 'long' }, { :class => 'wide-label' })
|
16
16
|
# select_block(:color, :options => ['green', 'black'])
|
17
|
-
#
|
17
|
+
#
|
18
18
|
(self.field_types - [ :hidden_field, :radio_button ]).each do |field_type|
|
19
19
|
class_eval <<-EOF
|
20
20
|
def #{field_type}_block(field, options={}, label_options={})
|
@@ -3,12 +3,12 @@ module Padrino
|
|
3
3
|
module FormHelpers
|
4
4
|
##
|
5
5
|
# Constructs a form for object using given or default form_builder
|
6
|
-
#
|
6
|
+
#
|
7
7
|
# ==== Examples
|
8
|
-
#
|
8
|
+
#
|
9
9
|
# form_for :user, '/register' do |f| ... end
|
10
10
|
# form_for @user, '/register', :id => 'register' do |f| ... end
|
11
|
-
#
|
11
|
+
#
|
12
12
|
def form_for(object, url, settings={}, &block)
|
13
13
|
builder_class = configured_form_builder_class(settings[:builder])
|
14
14
|
form_html = capture_html(builder_class.new(self, object), &block)
|
@@ -18,12 +18,12 @@ module Padrino
|
|
18
18
|
##
|
19
19
|
# Constructs form fields for an object using given or default form_builder
|
20
20
|
# Used within an existing form to allow alternate objects within one form
|
21
|
-
#
|
21
|
+
#
|
22
22
|
# ==== Examples
|
23
|
-
#
|
23
|
+
#
|
24
24
|
# fields_for @user.assignment do |assignment| ... end
|
25
25
|
# fields_for :assignment do |assigment| ... end
|
26
|
-
#
|
26
|
+
#
|
27
27
|
def fields_for(object, settings={}, &block)
|
28
28
|
builder_class = configured_form_builder_class(settings[:builder])
|
29
29
|
fields_html = capture_html(builder_class.new(self, object), &block)
|
@@ -32,11 +32,11 @@ module Padrino
|
|
32
32
|
|
33
33
|
##
|
34
34
|
# Constructs a form without object based on options
|
35
|
-
#
|
35
|
+
#
|
36
36
|
# ==== Examples
|
37
|
-
#
|
37
|
+
#
|
38
38
|
# form_tag '/register' do ... end
|
39
|
-
#
|
39
|
+
#
|
40
40
|
def form_tag(url, options={}, &block)
|
41
41
|
desired_method = options[:method]
|
42
42
|
options.delete(:method) if options[:method].to_s !~ /get|post/i
|
@@ -51,12 +51,12 @@ module Padrino
|
|
51
51
|
# Returns the hidden method field for 'put' and 'delete' forms
|
52
52
|
# Only 'get' and 'post' are allowed within browsers;
|
53
53
|
# 'put' and 'delete' are just specified using hidden fields with form action still 'put'.
|
54
|
-
#
|
54
|
+
#
|
55
55
|
# ==== Examples
|
56
|
-
#
|
56
|
+
#
|
57
57
|
# # Generate: <input name="_method" value="delete" />
|
58
58
|
# hidden_form_method_field('delete')
|
59
|
-
#
|
59
|
+
#
|
60
60
|
def hidden_form_method_field(desired_method)
|
61
61
|
return '' if desired_method.blank? || desired_method.to_s =~ /get|post/i
|
62
62
|
hidden_field_tag(:_method, :value => desired_method)
|
@@ -64,11 +64,11 @@ module Padrino
|
|
64
64
|
|
65
65
|
##
|
66
66
|
# Constructs a field_set to group fields with given options
|
67
|
-
#
|
67
|
+
#
|
68
68
|
# ==== Examples
|
69
|
-
#
|
69
|
+
#
|
70
70
|
# field_set_tag("Office", :class => 'office-set')
|
71
|
-
#
|
71
|
+
#
|
72
72
|
def field_set_tag(*args, &block)
|
73
73
|
options = args.extract_options!
|
74
74
|
legend_text = args[0].is_a?(String) ? args.first : nil
|
@@ -79,7 +79,7 @@ module Padrino
|
|
79
79
|
|
80
80
|
##
|
81
81
|
# Constructs list html for the errors for a given symbol
|
82
|
-
#
|
82
|
+
#
|
83
83
|
# ==== Options
|
84
84
|
#
|
85
85
|
# :header_tag:: Used for the header of the error div (default: "h2").
|
@@ -95,11 +95,11 @@ module Padrino
|
|
95
95
|
# :message:: The explanation message after the header message and before
|
96
96
|
# the error list. Pass +nil+ or an empty string to avoid the explanation message
|
97
97
|
# altogether. (Default: "There were problems with the following fields:").
|
98
|
-
#
|
98
|
+
#
|
99
99
|
# ==== Examples
|
100
|
-
#
|
100
|
+
#
|
101
101
|
# error_messages_for :user
|
102
|
-
#
|
102
|
+
#
|
103
103
|
def error_messages_for(*objects)
|
104
104
|
options = objects.extract_options!.symbolize_keys
|
105
105
|
objects = objects.collect {|object_name| object_name.is_a?(Symbol) ? instance_variable_get("@#{object_name}") : object_name }.compact
|
@@ -145,22 +145,22 @@ module Padrino
|
|
145
145
|
# Returns a string containing the error message attached to the +method+ on the +object+ if one exists.
|
146
146
|
#
|
147
147
|
# ==== Options
|
148
|
-
#
|
148
|
+
#
|
149
149
|
# :tag:: The tag that enclose your error. (Default 'div')
|
150
150
|
# :prepend:: Text to add before error.
|
151
151
|
# :append:: Text to add after error.
|
152
|
-
#
|
152
|
+
#
|
153
153
|
# ==== Examples
|
154
|
-
#
|
154
|
+
#
|
155
155
|
# # => <span class="error">can't be blank</div>
|
156
156
|
# error_message_on :post, :title
|
157
|
-
#
|
157
|
+
#
|
158
158
|
# # => <div class="custom" style="border:1px solid red">can't be blank</div>
|
159
159
|
# error_message_on :post, :title, :tag => :id, :class => :custom, :style => "border:1px solid red"
|
160
|
-
#
|
160
|
+
#
|
161
161
|
# # => <div class="error">This title can't be blank (or it won't work)</div>
|
162
162
|
# error_message_on :post, :title, :prepend => "This title", :append => "(or it won't work)"
|
163
|
-
#
|
163
|
+
#
|
164
164
|
def error_message_on(object, field, options={})
|
165
165
|
object = instance_variable_get("@#{object}")
|
166
166
|
error = object.errors[field] rescue nil
|
@@ -176,12 +176,12 @@ module Padrino
|
|
176
176
|
|
177
177
|
##
|
178
178
|
# Constructs a label tag from the given options
|
179
|
-
#
|
179
|
+
#
|
180
180
|
# ==== Examples
|
181
|
-
#
|
181
|
+
#
|
182
182
|
# label_tag :username, :class => 'long-label'
|
183
183
|
# label_tag :username, :class => 'long-label' do ... end
|
184
|
-
#
|
184
|
+
#
|
185
185
|
def label_tag(name, options={}, &block)
|
186
186
|
options.reverse_merge!(:caption => "#{name.to_s.titleize}: ", :for => name)
|
187
187
|
caption_text = options.delete(:caption)
|
@@ -196,11 +196,11 @@ module Padrino
|
|
196
196
|
|
197
197
|
##
|
198
198
|
# Constructs a hidden field input from the given options
|
199
|
-
#
|
199
|
+
#
|
200
200
|
# ==== Examples
|
201
|
-
#
|
201
|
+
#
|
202
202
|
# hidden_field_tag :session_key, :value => "__secret__"
|
203
|
-
#
|
203
|
+
#
|
204
204
|
def hidden_field_tag(name, options={})
|
205
205
|
options.reverse_merge!(:name => name)
|
206
206
|
input_tag(:hidden, options)
|
@@ -208,11 +208,11 @@ module Padrino
|
|
208
208
|
|
209
209
|
##
|
210
210
|
# Constructs a text field input from the given options
|
211
|
-
#
|
211
|
+
#
|
212
212
|
# ==== Examples
|
213
|
-
#
|
213
|
+
#
|
214
214
|
# text_field_tag :username, :class => 'long'
|
215
|
-
#
|
215
|
+
#
|
216
216
|
def text_field_tag(name, options={})
|
217
217
|
options.reverse_merge!(:name => name)
|
218
218
|
input_tag(:text, options)
|
@@ -220,11 +220,11 @@ module Padrino
|
|
220
220
|
|
221
221
|
##
|
222
222
|
# Constructs a text area input from the given options
|
223
|
-
#
|
223
|
+
#
|
224
224
|
# ==== Examples
|
225
|
-
#
|
225
|
+
#
|
226
226
|
# text_area_tag :username, :class => 'long', :value => "Demo?"
|
227
|
-
#
|
227
|
+
#
|
228
228
|
def text_area_tag(name, options={})
|
229
229
|
options.reverse_merge!(:name => name)
|
230
230
|
content_tag(:textarea, options.delete(:value).to_s, options)
|
@@ -232,11 +232,11 @@ module Padrino
|
|
232
232
|
|
233
233
|
##
|
234
234
|
# Constructs a password field input from the given options
|
235
|
-
#
|
235
|
+
#
|
236
236
|
# ==== Examples
|
237
|
-
#
|
237
|
+
#
|
238
238
|
# password_field_tag :password, :class => 'long'
|
239
|
-
#
|
239
|
+
#
|
240
240
|
def password_field_tag(name, options={})
|
241
241
|
options.reverse_merge!(:name => name)
|
242
242
|
input_tag(:password, options)
|
@@ -244,14 +244,14 @@ module Padrino
|
|
244
244
|
|
245
245
|
##
|
246
246
|
# Constructs a check_box from the given options
|
247
|
-
#
|
247
|
+
#
|
248
248
|
# ==== Examples
|
249
|
-
#
|
249
|
+
#
|
250
250
|
# options = [['caption', 'value'], ['Green', 'green1'], ['Blue', 'blue1'], ['Black', "black1"]]
|
251
251
|
# options = ['option', 'red', 'yellow' ]
|
252
252
|
# select_tag(:favorite_color, :options => ['red', 'yellow'], :selected => 'green1')
|
253
253
|
# select_tag(:country, :collection => @countries, :fields => [:name, :code], :include_blank => 'None')
|
254
|
-
#
|
254
|
+
#
|
255
255
|
def select_tag(name, options={})
|
256
256
|
options.reverse_merge!(:name => name)
|
257
257
|
collection, fields = options.delete(:collection), options.delete(:fields)
|
@@ -265,11 +265,11 @@ module Padrino
|
|
265
265
|
|
266
266
|
##
|
267
267
|
# Constructs a check_box from the given options
|
268
|
-
#
|
268
|
+
#
|
269
269
|
# ==== Examples
|
270
|
-
#
|
270
|
+
#
|
271
271
|
# check_box_tag :remember_me, :value => 'Yes'
|
272
|
-
#
|
272
|
+
#
|
273
273
|
def check_box_tag(name, options={})
|
274
274
|
options.reverse_merge!(:name => name, :value => '1')
|
275
275
|
input_tag(:checkbox, options)
|
@@ -277,11 +277,11 @@ module Padrino
|
|
277
277
|
|
278
278
|
##
|
279
279
|
# Constructs a radio_button from the given options
|
280
|
-
#
|
280
|
+
#
|
281
281
|
# ==== Examples
|
282
|
-
#
|
282
|
+
#
|
283
283
|
# radio_button_tag :remember_me, :value => 'true'
|
284
|
-
#
|
284
|
+
#
|
285
285
|
def radio_button_tag(name, options={})
|
286
286
|
options.reverse_merge!(:name => name)
|
287
287
|
input_tag(:radio, options)
|
@@ -289,11 +289,11 @@ module Padrino
|
|
289
289
|
|
290
290
|
##
|
291
291
|
# Constructs a file field input from the given options
|
292
|
-
#
|
292
|
+
#
|
293
293
|
# ==== Examples
|
294
|
-
#
|
294
|
+
#
|
295
295
|
# file_field_tag :photo, :class => 'long'
|
296
|
-
#
|
296
|
+
#
|
297
297
|
def file_field_tag(name, options={})
|
298
298
|
options.reverse_merge!(:name => name)
|
299
299
|
input_tag(:file, options)
|
@@ -301,11 +301,11 @@ module Padrino
|
|
301
301
|
|
302
302
|
##
|
303
303
|
# Constructs a submit button from the given options
|
304
|
-
#
|
304
|
+
#
|
305
305
|
# ==== Examples
|
306
|
-
#
|
306
|
+
#
|
307
307
|
# submit_tag "Create", :class => 'success'
|
308
|
-
#
|
308
|
+
#
|
309
309
|
def submit_tag(caption="Submit", options={})
|
310
310
|
options.reverse_merge!(:value => caption)
|
311
311
|
input_tag(:submit, options)
|
@@ -313,22 +313,22 @@ module Padrino
|
|
313
313
|
|
314
314
|
##
|
315
315
|
# Constructs a button input from the given options
|
316
|
-
#
|
316
|
+
#
|
317
317
|
# ==== Examples
|
318
|
-
#
|
318
|
+
#
|
319
319
|
# button_tag "Cancel", :class => 'clear'
|
320
|
-
#
|
320
|
+
#
|
321
321
|
def button_tag(caption, options = {})
|
322
322
|
options.reverse_merge!(:value => caption)
|
323
323
|
input_tag(:button, options)
|
324
324
|
end
|
325
325
|
|
326
326
|
# Constructs a submit button from the given options
|
327
|
-
#
|
327
|
+
#
|
328
328
|
# ==== Examples
|
329
|
-
#
|
329
|
+
#
|
330
330
|
# submit_tag "Create", :class => 'success'
|
331
|
-
#
|
331
|
+
#
|
332
332
|
def image_submit_tag(source, options={})
|
333
333
|
options.reverse_merge!(:src => image_path(source))
|
334
334
|
input_tag(:image, options)
|
@@ -337,14 +337,14 @@ module Padrino
|
|
337
337
|
##
|
338
338
|
# Returns an array of option items for a select field based on the given collection
|
339
339
|
# fields is an array containing the fields to display from each item in the collection
|
340
|
-
#
|
340
|
+
#
|
341
341
|
def options_from_collection(collection, fields)
|
342
342
|
collection.collect { |item| [ item.send(fields.first), item.send(fields.last) ] }
|
343
343
|
end
|
344
344
|
|
345
345
|
#
|
346
346
|
# Returns the options tags for a select based on the given option items
|
347
|
-
#
|
347
|
+
#
|
348
348
|
def options_for_select(option_items, selected_value=nil)
|
349
349
|
return '' if option_items.blank?
|
350
350
|
option_items.collect do |caption, value|
|
@@ -357,9 +357,9 @@ module Padrino
|
|
357
357
|
##
|
358
358
|
# Returns the FormBuilder class to use based on all available setting sources
|
359
359
|
# If explicitly defined, returns that, otherwise returns defaults.
|
360
|
-
#
|
360
|
+
#
|
361
361
|
# configured_form_builder_class(nil) => StandardFormBuilder
|
362
|
-
#
|
362
|
+
#
|
363
363
|
def configured_form_builder_class(explicit_builder=nil)
|
364
364
|
default_builder = self.respond_to?(:options) && self.options.default_builder
|
365
365
|
configured_builder = explicit_builder || default_builder || 'StandardFormBuilder'
|
@@ -368,4 +368,4 @@ module Padrino
|
|
368
368
|
end
|
369
369
|
end # FormHelpers
|
370
370
|
end # Helpers
|
371
|
-
end # Padrino
|
371
|
+
end # Padrino
|
@@ -1,9 +1,9 @@
|
|
1
1
|
module Padrino
|
2
2
|
module Helpers
|
3
3
|
module FormatHelpers
|
4
|
-
##
|
4
|
+
##
|
5
5
|
# Returns escaped text to protect against malicious content
|
6
|
-
#
|
6
|
+
#
|
7
7
|
def escape_html(text)
|
8
8
|
Rack::Utils.escape_html(text)
|
9
9
|
end
|
@@ -13,7 +13,7 @@ module Padrino
|
|
13
13
|
##
|
14
14
|
# Returns escaped text to protect against malicious content
|
15
15
|
# Returns blank if the text is empty
|
16
|
-
#
|
16
|
+
#
|
17
17
|
def h!(text, blank_text = ' ')
|
18
18
|
return blank_text if text.nil? || text.empty?
|
19
19
|
h text
|
@@ -21,7 +21,7 @@ module Padrino
|
|
21
21
|
|
22
22
|
##
|
23
23
|
# Strips all HTML tags from the html
|
24
|
-
#
|
24
|
+
#
|
25
25
|
def strip_tags(html)
|
26
26
|
html.gsub(/<\/?[^>]*>/, "") if html
|
27
27
|
end
|
@@ -30,11 +30,11 @@ module Padrino
|
|
30
30
|
# Returns text transformed into HTML using simple formatting rules. Two or more consecutive newlines(\n\n) are considered
|
31
31
|
# as a paragraph and wrapped in <p> tags. One newline (\n) is considered as a linebreak and a <br /> tag is appended.
|
32
32
|
# This method does not remove the newlines from the text.
|
33
|
-
#
|
33
|
+
#
|
34
34
|
# ==== Examples
|
35
|
-
#
|
35
|
+
#
|
36
36
|
# simple_format("hello\nworld") # => "<p>hello<br/>world</p>"
|
37
|
-
#
|
37
|
+
#
|
38
38
|
def simple_format(text, html_options={})
|
39
39
|
start_tag = tag('p', html_options.merge(:open => true))
|
40
40
|
text = text.to_s.dup
|
@@ -48,11 +48,11 @@ module Padrino
|
|
48
48
|
##
|
49
49
|
# Attempts to pluralize the singular word unless count is 1. If plural is supplied, it will use that when count is > 1,
|
50
50
|
# otherwise it will use the Inflector to determine the plural form
|
51
|
-
#
|
51
|
+
#
|
52
52
|
# ==== Examples
|
53
|
-
#
|
53
|
+
#
|
54
54
|
# pluralize(2, 'person') => '2 people'
|
55
|
-
#
|
55
|
+
#
|
56
56
|
def pluralize(count, singular, plural = nil)
|
57
57
|
"#{count || 0} " + ((count == 1 || count == '1') ? singular : (plural || singular.pluralize))
|
58
58
|
end
|
@@ -60,11 +60,11 @@ module Padrino
|
|
60
60
|
##
|
61
61
|
# Truncates a given text after a given :length if text is longer than :length (defaults to 30).
|
62
62
|
# The last characters will be replaced with the :omission (defaults to "…") for a total length not exceeding :length.
|
63
|
-
#
|
63
|
+
#
|
64
64
|
# ==== Examples
|
65
|
-
#
|
65
|
+
#
|
66
66
|
# truncate("Once upon a time in a world far far away", :length => 8) => "Once upon..."
|
67
|
-
#
|
67
|
+
#
|
68
68
|
def truncate(text, options={})
|
69
69
|
options.reverse_merge!(:length => 30, :omission => "...")
|
70
70
|
if text
|
@@ -77,11 +77,11 @@ module Padrino
|
|
77
77
|
##
|
78
78
|
# Wraps the text into lines no longer than line_width width.
|
79
79
|
# This method breaks on the first whitespace character that does not exceed line_width (which is 80 by default).
|
80
|
-
#
|
80
|
+
#
|
81
81
|
# ==== Examples
|
82
|
-
#
|
82
|
+
#
|
83
83
|
# word_wrap('Once upon a time', :line_width => 8) => "Once upon\na time"
|
84
|
-
#
|
84
|
+
#
|
85
85
|
def word_wrap(text, *args)
|
86
86
|
options = args.extract_options!
|
87
87
|
unless args.blank?
|
@@ -96,18 +96,18 @@ module Padrino
|
|
96
96
|
|
97
97
|
##
|
98
98
|
# Highlights one or more words everywhere in text by inserting it into a :highlighter string.
|
99
|
-
#
|
100
|
-
# The highlighter can be customized by passing :+highlighter+ as a single-quoted string
|
99
|
+
#
|
100
|
+
# The highlighter can be customized by passing :+highlighter+ as a single-quoted string
|
101
101
|
# with \1 where the phrase is to be inserted (defaults to ’<strong class="highlight">\1</strong>’)
|
102
|
-
#
|
102
|
+
#
|
103
103
|
# ==== Examples
|
104
|
-
#
|
104
|
+
#
|
105
105
|
# # => Lorem ipsum <strong class="highlight">dolor</strong> sit amet
|
106
106
|
# highlight('Lorem ipsum dolor sit amet', 'dolor')
|
107
|
-
#
|
107
|
+
#
|
108
108
|
# # => Lorem ipsum <span class="custom">dolor</span> sit amet
|
109
109
|
# highlight('Lorem ipsum dolor sit amet', 'dolor', :highlighter => '<span class="custom">\1</span>')
|
110
|
-
#
|
110
|
+
#
|
111
111
|
def highlight(text, words, *args)
|
112
112
|
options = args.extract_options!
|
113
113
|
options.reverse_merge!(:highlighter => '<strong class="highlight">\1</strong>')
|
@@ -148,7 +148,7 @@ module Padrino
|
|
148
148
|
# 60-89 secs # => 1 minute
|
149
149
|
#
|
150
150
|
# ==== Examples
|
151
|
-
#
|
151
|
+
#
|
152
152
|
# from_time = Time.now
|
153
153
|
# distance_of_time_in_words(from_time, from_time + 50.minutes) # => about 1 hour
|
154
154
|
# distance_of_time_in_words(from_time, 50.minutes.from_now) # => about 1 hour
|
@@ -216,20 +216,20 @@ module Padrino
|
|
216
216
|
# Like distance_of_time_in_words, but where <tt>to_time</tt> is fixed to <tt>Time.now</tt>.
|
217
217
|
#
|
218
218
|
# ==== Examples
|
219
|
-
#
|
219
|
+
#
|
220
220
|
# time_ago_in_words(3.minutes.from_now) # => 3 minutes
|
221
221
|
# time_ago_in_words(Time.now - 15.hours) # => 15 hours
|
222
222
|
# time_ago_in_words(Time.now) # => less than a minute
|
223
223
|
#
|
224
224
|
# from_time = Time.now - 3.days - 14.minutes - 25.seconds # => 3 days
|
225
|
-
#
|
225
|
+
#
|
226
226
|
def time_ago_in_words(from_time, include_seconds = false)
|
227
227
|
distance_of_time_in_words(from_time, Time.now, include_seconds)
|
228
228
|
end
|
229
229
|
|
230
230
|
##
|
231
231
|
# Remove unsafe chars from our javascript
|
232
|
-
#
|
232
|
+
#
|
233
233
|
def escape_javascript(html_content)
|
234
234
|
return '' unless html_content
|
235
235
|
javascript_mapping = { '\\' => '\\\\', '</' => '<\/', "\r\n" => '\n', "\n" => '\n' }
|
@@ -240,12 +240,12 @@ module Padrino
|
|
240
240
|
|
241
241
|
##
|
242
242
|
# Used in xxxx.js.erb files to escape html so that it can be passed to javascript from Padrino
|
243
|
-
#
|
243
|
+
#
|
244
244
|
# js_escape_html("<h1>Hey</h1>")
|
245
|
-
#
|
245
|
+
#
|
246
246
|
def js_escape_html(html_content)
|
247
247
|
%Q["#{escape_javascript(html_content)}"]
|
248
248
|
end
|
249
249
|
end # FormatHelpers
|
250
250
|
end # Helpers
|
251
|
-
end # Padrino
|
251
|
+
end # Padrino
|