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.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/README.rdoc +29 -29
  3. data/Rakefile +1 -1
  4. data/lib/padrino/rendering/erb_template.rb +7 -7
  5. data/lib/padrino/rendering/erubi_template.rb +4 -4
  6. data/lib/padrino/rendering/erubis_template.rb +4 -4
  7. data/lib/padrino/rendering/haml_template.rb +1 -1
  8. data/lib/padrino/rendering/hamlit_template.rb +4 -4
  9. data/lib/padrino/rendering/slim_template.rb +5 -5
  10. data/lib/padrino/rendering.rb +54 -45
  11. data/lib/padrino/safe_buffer.rb +31 -36
  12. data/lib/padrino-helpers/asset_tag_helpers.rb +48 -48
  13. data/lib/padrino-helpers/form_builder/abstract_form_builder.rb +74 -70
  14. data/lib/padrino-helpers/form_builder/standard_form_builder.rb +20 -20
  15. data/lib/padrino-helpers/form_helpers/errors.rb +14 -14
  16. data/lib/padrino-helpers/form_helpers/options.rb +25 -24
  17. data/lib/padrino-helpers/form_helpers/security.rb +5 -5
  18. data/lib/padrino-helpers/form_helpers.rb +133 -133
  19. data/lib/padrino-helpers/format_helpers.rb +61 -63
  20. data/lib/padrino-helpers/number_helpers.rb +82 -78
  21. data/lib/padrino-helpers/output_helpers/abstract_handler.rb +5 -3
  22. data/lib/padrino-helpers/output_helpers/erb_handler.rb +2 -2
  23. data/lib/padrino-helpers/output_helpers/haml_handler.rb +1 -1
  24. data/lib/padrino-helpers/output_helpers.rb +16 -17
  25. data/lib/padrino-helpers/render_helpers.rb +28 -27
  26. data/lib/padrino-helpers/tag_helpers.rb +62 -58
  27. data/lib/padrino-helpers/translation_helpers.rb +2 -2
  28. data/lib/padrino-helpers.rb +1 -2
  29. data/padrino-helpers.gemspec +17 -17
  30. data/test/fixtures/apps/render.rb +2 -2
  31. data/test/fixtures/markup_app/app.rb +9 -8
  32. data/test/fixtures/markup_app/views/button_to.erb +3 -3
  33. data/test/fixtures/markup_app/views/button_to.haml +2 -2
  34. data/test/fixtures/markup_app/views/button_to.slim +3 -3
  35. data/test/fixtures/markup_app/views/content_for.erb +4 -4
  36. data/test/fixtures/markup_app/views/content_for.haml +4 -4
  37. data/test/fixtures/markup_app/views/content_for.slim +2 -2
  38. data/test/fixtures/markup_app/views/content_tag.erb +3 -3
  39. data/test/fixtures/markup_app/views/content_tag.haml +3 -3
  40. data/test/fixtures/markup_app/views/content_tag.slim +3 -3
  41. data/test/fixtures/markup_app/views/fields_for.erb +2 -2
  42. data/test/fixtures/markup_app/views/fields_for.haml +2 -2
  43. data/test/fixtures/markup_app/views/fields_for.slim +2 -2
  44. data/test/fixtures/markup_app/views/form_for.erb +41 -41
  45. data/test/fixtures/markup_app/views/form_for.haml +41 -41
  46. data/test/fixtures/markup_app/views/form_for.slim +41 -42
  47. data/test/fixtures/markup_app/views/form_tag.erb +47 -47
  48. data/test/fixtures/markup_app/views/form_tag.haml +48 -48
  49. data/test/fixtures/markup_app/views/form_tag.slim +49 -49
  50. data/test/fixtures/markup_app/views/link_to.erb +2 -2
  51. data/test/fixtures/markup_app/views/link_to.haml +2 -2
  52. data/test/fixtures/markup_app/views/link_to.slim +2 -2
  53. data/test/fixtures/markup_app/views/meta_tag.erb +2 -2
  54. data/test/fixtures/markup_app/views/meta_tag.haml +2 -2
  55. data/test/fixtures/markup_app/views/meta_tag.slim +2 -2
  56. data/test/fixtures/markup_app/views/simple_partial.erb +1 -1
  57. data/test/fixtures/markup_app/views/simple_partial.haml +1 -1
  58. data/test/fixtures/markup_app/views/simple_partial.slim +1 -1
  59. data/test/fixtures/render_app/app.rb +13 -12
  60. data/test/fixtures/render_app/views/_unsafe.html.builder +1 -1
  61. data/test/fixtures/render_app/views/_unsafe_object.html.builder +1 -1
  62. data/test/fixtures/render_app/views/explicit_engine.haml +3 -3
  63. data/test/helper.rb +19 -19
  64. data/test/test_asset_tag_helpers.rb +133 -133
  65. data/test/test_form_builder.rb +629 -628
  66. data/test/test_form_helpers.rb +610 -610
  67. data/test/test_format_helpers.rb +66 -63
  68. data/test/test_helpers.rb +2 -2
  69. data/test/test_locale.rb +13 -11
  70. data/test/test_number_helpers.rb +65 -65
  71. data/test/test_output_helpers.rb +76 -76
  72. data/test/test_render_helpers.rb +101 -101
  73. data/test/test_rendering.rb +329 -326
  74. data/test/test_rendering_extensions.rb +4 -4
  75. data/test/test_tag_helpers.rb +55 -55
  76. metadata +6 -6
@@ -38,14 +38,14 @@ module Padrino
38
38
  #
39
39
  # @example
40
40
  # form_for :user, '/register' do |f| ... end
41
- # form_for @user, '/register', :id => 'register' do |f| ... end
42
- # form_for @user, '/register', :as => :customer do |f| ... end
41
+ # form_for @user, '/register', id: 'register' do |f| ... end
42
+ # form_for @user, '/register', as: :customer do |f| ... end
43
43
  #
44
- def form_for(object, url, options={}, &block)
44
+ def form_for(object, url, options = {}, &block)
45
45
  instance = builder_instance(object, options)
46
46
  # this can erect instance.multipart flag if the block calls instance.file_field
47
47
  html = capture_html(instance, &block)
48
- options = { :multipart => instance.multipart }.update(options.reject{ |key,_| [:namespace, :as].include?(key) })
48
+ options = { multipart: instance.multipart }.update(options.reject { |key, _| %i[namespace as].include?(key) })
49
49
  form_tag(url, options) { html }
50
50
  end
51
51
 
@@ -66,7 +66,7 @@ module Padrino
66
66
  # fields_for @user.assignment do |assignment| ... end
67
67
  # fields_for :assignment do |assigment| ... end
68
68
  #
69
- def fields_for(object, options={}, &block)
69
+ def fields_for(object, options = {}, &block)
70
70
  instance = builder_instance(object, options)
71
71
  fields_html = capture_html(instance, &block)
72
72
  fields_html << instance.hidden_field(:id) if instance.send(:nested_object_id)
@@ -86,12 +86,12 @@ module Padrino
86
86
  # @return [String] The HTML form with the specified options and input fields.
87
87
  #
88
88
  # @example
89
- # form_tag '/register', :class => "registration_form" do ... end
89
+ # form_tag '/register', class: 'registration_form' do ... end
90
90
  #
91
- def form_tag(url, options={}, &block)
91
+ def form_tag(url, options = {}, &block)
92
92
  options = {
93
- :action => escape_link(url),
94
- :protect_from_csrf => is_protected_from_csrf?,
93
+ action: escape_link(url),
94
+ protect_from_csrf: is_protected_from_csrf?,
95
95
  'accept-charset' => 'UTF-8'
96
96
  }.update(options)
97
97
  options[:enctype] = 'multipart/form-data' if options.delete(:multipart)
@@ -122,7 +122,7 @@ module Padrino
122
122
  #
123
123
  def hidden_form_method_field(desired_method)
124
124
  return SafeBuffer.new if desired_method.nil? || desired_method.to_s =~ /get|post/i
125
- hidden_field_tag(:_method, :value => desired_method)
125
+ hidden_field_tag(:_method, value: desired_method)
126
126
  end
127
127
 
128
128
  ##
@@ -139,8 +139,8 @@ module Padrino
139
139
  # @return [String] The html for the fieldset tag based on given +options+.
140
140
  #
141
141
  # @example
142
- # field_set_tag(:class => "office-set") { }
143
- # field_set_tag("Office", :class => 'office-set') { }
142
+ # field_set_tag(class: 'office-set') { }
143
+ # field_set_tag("Office", class: 'office-set') { }
144
144
  #
145
145
  def field_set_tag(*args, &block)
146
146
  options = args.last.is_a?(Hash) ? args.pop : {}
@@ -163,11 +163,11 @@ module Padrino
163
163
  # @return [String] The html for this label with the given +options+.
164
164
  #
165
165
  # @example
166
- # label_tag :username, :class => 'long-label'
167
- # label_tag :username, :class => 'long-label' do ... end
166
+ # label_tag :username, class: 'long-label'
167
+ # label_tag :username, class: 'long-label' do ... end
168
168
  #
169
- def label_tag(name, options={}, &block)
170
- options = { :caption => "#{Inflections.humanize(name)}: ", :for => name }.update(options)
169
+ def label_tag(name, options = {}, &block)
170
+ options = { caption: "#{Inflections.humanize(name)}: ", for: name }.update(options)
171
171
  caption_text = SafeBuffer.new << options.delete(:caption)
172
172
  caption_text << "<span class='required'>*</span> ".html_safe if options.delete(:required)
173
173
 
@@ -226,17 +226,17 @@ module Padrino
226
226
  # Generated HTML with specified +options+.
227
227
  #
228
228
  # @example
229
- # text_field_tag :first_name, :maxlength => 40, :required => true
229
+ # text_field_tag :first_name, maxlength: 40, required: true
230
230
  # # => <input name="first_name" maxlength="40" required type="text" />
231
231
  #
232
- # text_field_tag :last_name, :class => 'string', :size => 40
232
+ # text_field_tag :last_name, class: 'string', size: 40
233
233
  # # => <input name="last_name" class="string" size="40" type="text" />
234
234
  #
235
- # text_field_tag :username, :placeholder => 'Your Username'
235
+ # text_field_tag :username, placeholder: 'Your Username'
236
236
  # # => <input name="username" placeholder="Your Username" type="text" />
237
237
  #
238
- def text_field_tag(name, options={})
239
- input_tag(:text, { :name => name }.update(options))
238
+ def text_field_tag(name, options = {})
239
+ input_tag(:text, { name: name }.update(options))
240
240
  end
241
241
 
242
242
  ##
@@ -287,20 +287,20 @@ module Padrino
287
287
  # Generated HTML with specified +options+.
288
288
  #
289
289
  # @example
290
- # number_field_tag :quantity, :class => 'numeric'
290
+ # number_field_tag :quantity, class: 'numeric'
291
291
  # # => <input name="quantity" class="numeric" type="number" />
292
292
  #
293
- # number_field_tag :zip_code, :pattern => /[0-9]{5}/
293
+ # number_field_tag :zip_code, pattern: /[0-9]{5}/
294
294
  # # => <input name="zip_code" pattern="[0-9]{5}" type="number" />
295
295
  #
296
- # number_field_tag :credit_card, :autocomplete => :off
296
+ # number_field_tag :credit_card, autocomplete: :off
297
297
  # # => <input name="credit_card" autocomplete="off" type="number" />
298
298
  #
299
- # number_field_tag :age, :min => 18, :max => 120, :step => 1
299
+ # number_field_tag :age, min: 18, max: 120, step: 1
300
300
  # # => <input name="age" min="18" max="120" step="1" type="number" />
301
301
  #
302
- def number_field_tag(name, options={})
303
- input_tag(:number, { :name => name }.update(options))
302
+ def number_field_tag(name, options = {})
303
+ input_tag(:number, { name: name }.update(options))
304
304
  end
305
305
 
306
306
  ##
@@ -309,21 +309,21 @@ module Padrino
309
309
  # @macro text_field
310
310
  #
311
311
  # @example
312
- # telephone_field_tag :phone_number, :class => 'string'
312
+ # telephone_field_tag :phone_number, class: 'string'
313
313
  # # => <input name="phone_number" class="string" type="tel" />
314
314
  #
315
- # telephone_field_tag :cell_phone, :tabindex => 1
316
- # telephone_field_tag :work_phone, :tabindex => 2
317
- # telephone_field_tag :home_phone, :tabindex => 3
315
+ # telephone_field_tag :cell_phone, tabindex: 1
316
+ # telephone_field_tag :work_phone, tabindex: 2
317
+ # telephone_field_tag :home_phone, tabindex: 3
318
318
  #
319
319
  # # => <input name="cell_phone" tabindex="1" type="tel" />
320
320
  # # => <input name="work_phone" tabindex="2" type="tel" />
321
321
  # # => <input name="home_phone" tabindex="3" type="tel" />
322
322
  #
323
- def telephone_field_tag(name, options={})
324
- input_tag(:tel, { :name => name }.update(options))
323
+ def telephone_field_tag(name, options = {})
324
+ input_tag(:tel, { name: name }.update(options))
325
325
  end
326
- alias_method :phone_field_tag, :telephone_field_tag
326
+ alias phone_field_tag telephone_field_tag
327
327
 
328
328
  ##
329
329
  # Creates an email field input with the given name and options.
@@ -331,14 +331,14 @@ module Padrino
331
331
  # @macro text_field
332
332
  #
333
333
  # @example
334
- # email_field_tag :email, :placeholder => 'you@example.com'
334
+ # email_field_tag :email, placeholder: 'you@example.com'
335
335
  # # => <input name="email" placeholder="you@example.com" type="email" />
336
336
  #
337
- # email_field_tag :email, :value => 'padrinorb@gmail.com', :readonly => true
337
+ # email_field_tag :email, value: 'padrinorb@gmail.com', readonly: true
338
338
  # # => <input name="email" value="padrinorb@gmail.com" readonly type="email" />
339
339
  #
340
- def email_field_tag(name, options={})
341
- input_tag(:email, { :name => name }.update(options))
340
+ def email_field_tag(name, options = {})
341
+ input_tag(:email, { name: name }.update(options))
342
342
  end
343
343
 
344
344
  ##
@@ -347,20 +347,20 @@ module Padrino
347
347
  # @macro text_field
348
348
  #
349
349
  # @example
350
- # search_field_tag :search, :placeholder => 'Search this website...'
350
+ # search_field_tag :search, placeholder: 'Search this website...'
351
351
  # # => <input name="search" placeholder="Search this website..." type="search" />
352
352
  #
353
- # search_field_tag :search, :maxlength => 15, :class => ['search', 'string']
353
+ # search_field_tag :search, maxlength: 15, class: ['search', 'string']
354
354
  # # => <input name="search" maxlength="15" class="search string" />
355
355
  #
356
- # search_field_tag :search, :id => 'search'
356
+ # search_field_tag :search, id: 'search'
357
357
  # # => <input name="search" id="search" type="search" />
358
358
  #
359
- # search_field_tag :search, :autofocus => true
359
+ # search_field_tag :search, autofocus: true
360
360
  # # => <input name="search" autofocus type="search" />
361
361
  #
362
- def search_field_tag(name, options={})
363
- input_tag(:search, { :name => name }.update(options))
362
+ def search_field_tag(name, options = {})
363
+ input_tag(:search, { name: name }.update(options))
364
364
  end
365
365
 
366
366
  ##
@@ -369,78 +369,78 @@ module Padrino
369
369
  # @macro text_field
370
370
  #
371
371
  # @example
372
- # url_field_tag :favorite_website, :placeholder => 'http://padrinorb.com'
372
+ # url_field_tag :favorite_website, placeholder: 'http://padrinorb.com'
373
373
  # <input name="favorite_website" placeholder="http://padrinorb.com." type="url" />
374
374
  #
375
- # url_field_tag :home_page, :class => 'string url'
375
+ # url_field_tag :home_page, class: 'string url'
376
376
  # <input name="home_page" class="string url", type="url" />
377
377
  #
378
- def url_field_tag(name, options={})
379
- input_tag(:url, { :name => name }.update(options))
378
+ def url_field_tag(name, options = {})
379
+ input_tag(:url, { name: name }.update(options))
380
380
  end
381
381
 
382
382
  ##
383
383
  # Constructs a hidden field input from the given options.
384
384
  #
385
385
  # @example
386
- # hidden_field_tag :session_key, :value => "__secret__"
386
+ # hidden_field_tag :session_key, value: '__secret__'
387
387
  #
388
- def hidden_field_tag(name, options={})
389
- input_tag(:hidden, { :name => name }.update(options))
388
+ def hidden_field_tag(name, options = {})
389
+ input_tag(:hidden, { name: name }.update(options))
390
390
  end
391
391
 
392
392
  ##
393
393
  # Constructs a text area input from the given options.
394
394
  #
395
395
  # @example
396
- # text_area_tag :username, :class => 'long', :value => "Demo?"
396
+ # text_area_tag :username, class: 'long', value: 'Demo?'
397
397
  #
398
- def text_area_tag(name, options={})
398
+ def text_area_tag(name, options = {})
399
399
  inner_html = TagHelpers::NEWLINE + options.delete(:value).to_s
400
- content_tag(:textarea, inner_html, { :name => name }.update(options))
400
+ content_tag(:textarea, inner_html, { name: name }.update(options))
401
401
  end
402
402
 
403
403
  ##
404
404
  # Constructs a password field input from the given options.
405
405
  #
406
406
  # @example
407
- # password_field_tag :password, :class => 'long'
407
+ # password_field_tag :password, class: 'long'
408
408
  #
409
409
  # @api public
410
- def password_field_tag(name, options={})
411
- input_tag(:password, { :name => name }.update(options))
410
+ def password_field_tag(name, options = {})
411
+ input_tag(:password, { name: name }.update(options))
412
412
  end
413
413
 
414
414
  ##
415
415
  # Constructs a check_box from the given options.
416
416
  #
417
417
  # @example
418
- # check_box_tag :remember_me, :value => 'Yes'
418
+ # check_box_tag :remember_me, value: 'Yes'
419
419
  #
420
- def check_box_tag(name, options={})
421
- input_tag(:checkbox, { :name => name, :value => '1' }.update(options))
420
+ def check_box_tag(name, options = {})
421
+ input_tag(:checkbox, { name: name, value: '1' }.update(options))
422
422
  end
423
423
 
424
424
  ##
425
425
  # Constructs a radio_button from the given options.
426
426
  #
427
427
  # @example
428
- # radio_button_tag :remember_me, :value => 'true'
428
+ # radio_button_tag :remember_me, value: 'true'
429
429
  #
430
- def radio_button_tag(name, options={})
431
- input_tag(:radio, { :name => name }.update(options))
430
+ def radio_button_tag(name, options = {})
431
+ input_tag(:radio, { name: name }.update(options))
432
432
  end
433
433
 
434
434
  ##
435
435
  # Constructs a file field input from the given options.
436
436
  #
437
437
  # @example
438
- # file_field_tag :photo, :class => 'long'
438
+ # file_field_tag :photo, class: 'long'
439
439
  #
440
440
  # @api public
441
- def file_field_tag(name, options={})
441
+ def file_field_tag(name, options = {})
442
442
  name = "#{name}[]" if options[:multiple]
443
- input_tag(:file, { :name => name }.update(options))
443
+ input_tag(:file, { name: name }.update(options))
444
444
  end
445
445
 
446
446
  ##
@@ -449,20 +449,20 @@ module Padrino
449
449
  # @example
450
450
  # options = [['caption', 'value'], ['Green', 'green1'], ['Blue', 'blue1'], ['Black', "black1"]]
451
451
  # options = ['option', 'red', 'yellow' ]
452
- # select_tag(:favorite_color, :options => ['red', 'yellow'], :selected => 'green1')
453
- # select_tag(:country, :collection => @countries, :fields => [:name, :code], :include_blank => 'None')
452
+ # select_tag(:favorite_color, options: ['red', 'yellow'], selected: 'green1')
453
+ # select_tag(:country, collection: @countries, fields: [:name, :code], include_blank: 'None')
454
454
  #
455
455
  # # Optgroups can be generated using :grouped_options => (Hash or nested Array)
456
- # grouped_options = [['Friends',['Yoda',['Obiwan',1]]],['Enemies',['Palpatine',['Darth Vader',3]]]]
457
- # grouped_options = {'Friends' => ['Yoda',['Obiwan',1]],'Enemies' => ['Palpatine',['Darth Vader',3]]}
458
- # select_tag(:color, :grouped_options => [['warm',['red','yellow']],['cool',['blue', 'purple']]])
456
+ # grouped_options = [['Friends', ['Yoda', ['Obiwan', 1]]], ['Enemies', ['Palpatine', ['Darth Vader', 3]]]]
457
+ # grouped_options = {'Friends' => ['Yoda', ['Obiwan', 1]], { 'Enemies' => ['Palpatine', ['Darth Vader', 3]] }}
458
+ # select_tag(:color, grouped_options: [['warm', ['red','yellow']], ['cool', ['blue', 'purple']]])
459
459
  #
460
460
  # # Optgroups can be generated using the rails-style attribute hash.
461
461
  # grouped_options = {
462
- # "Friends" => ["Yoda", ["Obiwan", 2, {:magister => 'no'}], {:lame => 'yes'}],
463
- # "Enemies" => [["Palpatine", "Palpatine", {:scary => 'yes', :old => 'yes'}], ["Darth Vader", 3, {:disabled => true}]]
462
+ # 'Friends' => ['Yoda', ['Obiwan', 2, { magister: 'no' }], { lame: 'yes' }],
463
+ # 'Enemies' => [['Palpatine', 'Palpatine', { scary: 'yes', old: 'yes' }], ['Darth Vader', 3, { disabled: true }]]
464
464
  # }
465
- # select_tag(:name, :grouped_options => grouped_options)
465
+ # select_tag(:name, grouped_options: grouped_options)
466
466
  #
467
467
  # @param [String] name
468
468
  # The name of the input field.
@@ -485,8 +485,8 @@ module Padrino
485
485
  #
486
486
  # @return [String] The HTML input field based on the +options+ specified.
487
487
  #
488
- def select_tag(name, options={})
489
- options = { :name => name }.merge(options)
488
+ def select_tag(name, options = {})
489
+ options = { name: name }.merge(options)
490
490
  options[:name] = "#{options[:name]}[]" if options[:multiple]
491
491
  content_tag(:select, extract_option_tags!(options), options)
492
492
  end
@@ -502,10 +502,10 @@ module Padrino
502
502
  # @return [String] The html button based on the +options+ specified.
503
503
  #
504
504
  # @example
505
- # button_tag "Cancel", :class => 'clear'
505
+ # button_tag 'Cancel', class: 'clear'
506
506
  #
507
507
  def button_tag(caption, options = {})
508
- input_tag(:button, { :value => caption }.update(options))
508
+ input_tag(:button, { value: caption }.update(options))
509
509
  end
510
510
 
511
511
  ##
@@ -520,13 +520,13 @@ module Padrino
520
520
  # @return [String] The html submit button based on the +options+ specified.
521
521
  #
522
522
  # @example
523
- # submit_tag "Create", :class => 'success'
524
- # submit_tag :class => 'btn'
523
+ # submit_tag 'Create', class: 'success'
524
+ # submit_tag class: 'btn'
525
525
  #
526
526
  def submit_tag(*args)
527
527
  options = args.last.is_a?(Hash) ? args.pop : {}
528
- caption = args.length >= 1 ? args.first : "Submit"
529
- input_tag(:submit, { :value => caption }.merge(options))
528
+ caption = args.length >= 1 ? args.first : 'Submit'
529
+ input_tag(:submit, { value: caption }.merge(options))
530
530
  end
531
531
 
532
532
  ##
@@ -542,8 +542,8 @@ module Padrino
542
542
  # @example
543
543
  # image_submit_tag 'form/submit.png'
544
544
  #
545
- def image_submit_tag(source, options={})
546
- input_tag(:image, { :src => image_path(source) }.update(options))
545
+ def image_submit_tag(source, options = {})
546
+ input_tag(:image, { src: image_path(source) }.update(options))
547
547
  end
548
548
 
549
549
  ##
@@ -570,7 +570,7 @@ module Padrino
570
570
  # @return [String] Form and button html with specified +options+.
571
571
  #
572
572
  # @example
573
- # button_to 'Delete', url(:accounts_destroy, :id => account), :method => :delete, :class => :form
573
+ # button_to 'Delete', url(:accounts_destroy, id: account), method: :delete, class: :form
574
574
  # # Generates:
575
575
  # # <form class="form" action="/admin/accounts/destroy/2" method="post">
576
576
  # # <input type="hidden" value="delete" name="_method" />
@@ -595,8 +595,8 @@ module Padrino
595
595
  # Constructs a range tag from the given options.
596
596
  #
597
597
  # @example
598
- # range_field_tag('ranger_with_min_max', :min => 1, :max => 50)
599
- # range_field_tag('ranger_with_range', :range => 1..5)
598
+ # range_field_tag('ranger_with_min_max', min: 1, max: 50)
599
+ # range_field_tag('ranger_with_range', range: 1..5)
600
600
  #
601
601
  # @param [String] name
602
602
  # The name of the range field.
@@ -611,23 +611,23 @@ module Padrino
611
611
  # @return [String] The html range field
612
612
  #
613
613
  def range_field_tag(name, options = {})
614
- options = { :name => name }.update(options)
615
- if range = options.delete(:range)
616
- options[:min], options[:max] = range.min, range.max
614
+ options = { name: name }.update(options)
615
+ if (range = options.delete(:range))
616
+ options[:min], options[:max] = range.minmax
617
617
  end
618
618
  input_tag(:range, options)
619
619
  end
620
620
 
621
- DATETIME_ATTRIBUTES = [:value, :max, :min].freeze
622
- COLOR_CODE_REGEXP = /\A#([0-9a-fA-F]{3}){1,2}\z/.freeze
621
+ DATETIME_ATTRIBUTES = %i[value max min].freeze
622
+ COLOR_CODE_REGEXP = /\A#([0-9a-fA-F]{3}){1,2}\z/
623
623
 
624
624
  ##
625
625
  # Constructs a datetime tag from the given options.
626
626
  #
627
627
  # @example
628
- # datetime_field_tag('datetime_with_min_max', :min => DateTime.new(1993, 2, 24, 12, 30, 45),
629
- # :max => DateTime.new(2000, 4, 1, 12, 0, 0))
630
- # datetime_field_tag('datetime_with_value', :value => DateTime.new(2000, 4, 1, 12, 0, 0))
628
+ # datetime_field_tag('datetime_with_min_max', min: DateTime.new(1993, 2, 24, 12, 30, 45),
629
+ # max: DateTime.new(2000, 4, 1, 12, 0, 0))
630
+ # datetime_field_tag('datetime_with_value', value: DateTime.new(2000, 4, 1, 12, 0, 0))
631
631
  #
632
632
  # @param [String] name
633
633
  # The name of the datetime field.
@@ -642,8 +642,8 @@ module Padrino
642
642
  # @return [String] The html datetime field
643
643
  #
644
644
  def datetime_field_tag(name, options = {})
645
- options = { :name => name }.update(options)
646
- options = convert_attributes_into_datetime("%Y-%m-%dT%T.%L%z", options)
645
+ options = { name: name }.update(options)
646
+ options = convert_attributes_into_datetime('%Y-%m-%dT%T.%L%z', options)
647
647
  input_tag(:datetime, options)
648
648
  end
649
649
 
@@ -651,9 +651,9 @@ module Padrino
651
651
  # Constructs a datetime-local tag from the given options.
652
652
  #
653
653
  # @example
654
- # datetime_local_field_tag('datetime_local_with_min_max', :min => DateTime.new(1993, 2, 24, 12, 30, 45),
655
- # :max => DateTime.new(2000, 4, 1, 12, 0, 0))
656
- # datetime_local_field_tag('datetime_local_with_value', :value => DateTime.new(2000, 4, 1, 12, 0, 0))
654
+ # datetime_local_field_tag('datetime_local_with_min_max', min: DateTime.new(1993, 2, 24, 12, 30, 45),
655
+ # max: DateTime.new(2000, 4, 1, 12, 0, 0))
656
+ # datetime_local_field_tag('datetime_local_with_value', value: DateTime.new(2000, 4, 1, 12, 0, 0))
657
657
  #
658
658
  # @param [String] name
659
659
  # The name of the datetime local field.
@@ -668,8 +668,8 @@ module Padrino
668
668
  # @return [String] The html datetime-local field
669
669
  #
670
670
  def datetime_local_field_tag(name, options = {})
671
- options = { :name => name }.update(options)
672
- options = convert_attributes_into_datetime("%Y-%m-%dT%T", options)
671
+ options = { name: name }.update(options)
672
+ options = convert_attributes_into_datetime('%Y-%m-%dT%T', options)
673
673
  input_tag(:"datetime-local", options)
674
674
  end
675
675
 
@@ -677,9 +677,9 @@ module Padrino
677
677
  # Constructs a date tag from the given options.
678
678
  #
679
679
  # @example
680
- # date_field_tag('date_with_min_max', :min => DateTime.new(1993, 2, 24),
681
- # :max => DateTime.new(2000, 4, 1))
682
- # date_field_tag('date_with_value', :value => DateTime.new(2000, 4, 1))
680
+ # date_field_tag('date_with_min_max', min: DateTime.new(1993, 2, 24),
681
+ # max: DateTime.new(2000, 4, 1))
682
+ # date_field_tag('date_with_value', value: DateTime.new(2000, 4, 1))
683
683
  #
684
684
  # @param [String] name
685
685
  # The name of the date field.
@@ -694,8 +694,8 @@ module Padrino
694
694
  # @return [String] The html date field
695
695
  #
696
696
  def date_field_tag(name, options = {})
697
- options = { :name => name }.update(options)
698
- options = convert_attributes_into_datetime("%Y-%m-%d", options)
697
+ options = { name: name }.update(options)
698
+ options = convert_attributes_into_datetime('%Y-%m-%d', options)
699
699
  input_tag(:date, options)
700
700
  end
701
701
 
@@ -703,9 +703,9 @@ module Padrino
703
703
  # Constructs a month tag from the given options.
704
704
  #
705
705
  # @example
706
- # month_field_tag('month_with_min_max', :min => DateTime.new(1993, 2, 24),
707
- # :max => DateTime.new(2000, 4, 1))
708
- # month_field_tag('month_with_value', :value => DateTime.new(2000, 4, 1))
706
+ # month_field_tag('month_with_min_max', min: DateTime.new(1993, 2, 24),
707
+ # max: DateTime.new(2000, 4, 1))
708
+ # month_field_tag('month_with_value', value: DateTime.new(2000, 4, 1))
709
709
  #
710
710
  # @param [String] name
711
711
  # The name of the month field.
@@ -720,8 +720,8 @@ module Padrino
720
720
  # @return [String] The html month field
721
721
  #
722
722
  def month_field_tag(name, options = {})
723
- options = { :name => name }.update(options)
724
- options = convert_attributes_into_datetime("%Y-%m", options)
723
+ options = { name: name }.update(options)
724
+ options = convert_attributes_into_datetime('%Y-%m', options)
725
725
  input_tag(:month, options)
726
726
  end
727
727
 
@@ -729,9 +729,9 @@ module Padrino
729
729
  # Constructs a week tag from the given options.
730
730
  #
731
731
  # @example
732
- # week_field_tag('week_with_min_max', :min => DateTime.new(1993, 2, 24),
733
- # :max => DateTime.new(2000, 4, 1))
734
- # week_field_tag('week_with_value', :value => DateTime.new(2000, 4, 1))
732
+ # week_field_tag('week_with_min_max', min: DateTime.new(1993, 2, 24),
733
+ # max: DateTime.new(2000, 4, 1))
734
+ # week_field_tag('week_with_value', value: DateTime.new(2000, 4, 1))
735
735
  #
736
736
  # @param [String] name
737
737
  # The name of the week field.
@@ -746,8 +746,8 @@ module Padrino
746
746
  # @return [String] The html week field
747
747
  #
748
748
  def week_field_tag(name, options = {})
749
- options = { :name => name }.update(options)
750
- options = convert_attributes_into_datetime("%Y-W%W", options)
749
+ options = { name: name }.update(options)
750
+ options = convert_attributes_into_datetime('%Y-W%W', options)
751
751
  input_tag(:week, options)
752
752
  end
753
753
 
@@ -755,9 +755,9 @@ module Padrino
755
755
  # Constructs a time tag from the given options.
756
756
  #
757
757
  # @example
758
- # time_field_tag('time_with_min_max', :max => Time.new(1993, 2, 24, 1, 19, 12),
759
- # :min => Time.new(2008, 6, 21, 13, 30, 0))
760
- # time_field_tag('time_with_value', :value => Time.new(2008, 6, 21, 13, 30, 0))
758
+ # time_field_tag('time_with_min_max', max: Time.new(1993, 2, 24, 1, 19, 12),
759
+ # min: Time.new(2008, 6, 21, 13, 30, 0))
760
+ # time_field_tag('time_with_value', value: Time.new(2008, 6, 21, 13, 30, 0))
761
761
  #
762
762
  # @param [String] name
763
763
  # The name of the time field.
@@ -772,8 +772,8 @@ module Padrino
772
772
  # @return [String] The html time field
773
773
  #
774
774
  def time_field_tag(name, options = {})
775
- options = { :name => name }.update(options)
776
- options = convert_attributes_into_datetime("%T.%L", options)
775
+ options = { name: name }.update(options)
776
+ options = convert_attributes_into_datetime('%T.%L', options)
777
777
  input_tag(:time, options)
778
778
  end
779
779
 
@@ -781,8 +781,8 @@ module Padrino
781
781
  # Constructs a color tag from the given options.
782
782
  #
783
783
  # @example
784
- # color_field_tag('color', :value => "#ff0000")
785
- # color_field_tag('color', :value => "#f00")
784
+ # color_field_tag('color', value: '#ff0000')
785
+ # color_field_tag('color', value: '#f00')
786
786
  #
787
787
  # @param [String] name
788
788
  # The name of the color field.
@@ -792,7 +792,7 @@ module Padrino
792
792
  # The value of the color field. See examples for details.
793
793
  #
794
794
  def color_field_tag(name, options = {})
795
- options = { :name => name }.update(options)
795
+ options = { name: name }.update(options)
796
796
  options[:value] = adjust_color(options[:value])
797
797
  input_tag(:color, options)
798
798
  end
@@ -803,9 +803,9 @@ module Padrino
803
803
  # Returns an initialized builder instance for the given object and settings.
804
804
  #
805
805
  # @example
806
- # builder_instance(@account, :nested => { ... }) => <FormBuilder>
806
+ # builder_instance(@account, nested: { ... }) => <FormBuilder>
807
807
  #
808
- def builder_instance(object, options={})
808
+ def builder_instance(object, options = {})
809
809
  default_builder = respond_to?(:settings) && settings.default_builder || 'StandardFormBuilder'
810
810
  builder_class = options.delete(:builder) || default_builder
811
811
  builder_class = Padrino::Helpers::FormBuilder.const_get(builder_class) if builder_class.is_a?(String)
@@ -819,7 +819,7 @@ module Padrino
819
819
  # datetime_value('1993-02-24T12:30:45') #=> #<DateTime: 1993-02-24T12:30:45+00:00>
820
820
  #
821
821
  def datetime_value(value)
822
- if value.kind_of?(String)
822
+ if value.is_a?(String)
823
823
  DateTime.parse(value) rescue nil
824
824
  else
825
825
  value
@@ -830,9 +830,9 @@ module Padrino
830
830
  # Converts special attributes into datetime format strings that conforms to RFC 3399.
831
831
  #
832
832
  def convert_attributes_into_datetime(format, options)
833
- DATETIME_ATTRIBUTES.each_with_object(options) do |attribute|
834
- value = datetime_value(options[attribute])
835
- options[attribute] = value.strftime(format) if value.respond_to?(:strftime)
833
+ DATETIME_ATTRIBUTES.each_with_object(options) do |attribute, opts|
834
+ value = datetime_value(opts[attribute])
835
+ opts[attribute] = value.strftime(format) if value.respond_to?(:strftime)
836
836
  end
837
837
  end
838
838
 
@@ -845,9 +845,9 @@ module Padrino
845
845
  # adust_color("#foobar") #=> "#000000"
846
846
  #
847
847
  def adjust_color(color)
848
- return "#000000" unless color =~ COLOR_CODE_REGEXP
848
+ return '#000000' unless color =~ COLOR_CODE_REGEXP
849
849
  return color if (color_size = color.size) == 7
850
- color.slice(1, color_size - 1).each_char.with_object("#") do |chr, obj|
850
+ color.slice(1, color_size - 1).each_char.with_object('#') do |chr, obj|
851
851
  obj << chr * 2
852
852
  end
853
853
  end