padrino-helpers 0.13.3.1 → 0.13.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5dd540d3a9472d8c134bab1741faf3f69ae62166
4
- data.tar.gz: 036a523946eefb56ec7892ead4e6df2c5f200d87
3
+ metadata.gz: 0905e2192dbffe4b6b0e5a2f3d6fa8451c3f2e37
4
+ data.tar.gz: 8e65ca6a317a2ccc2512671423ea3248f275ecab
5
5
  SHA512:
6
- metadata.gz: 734ebfd2d7817d8feb9221f9037df2da53923552cc961b7a6a60573539410dab665fbcc99f40296492f8cca611147c0aef6d64b533ba27d93f974f34c0e378b8
7
- data.tar.gz: f8b6b1a10621c16c53786bc20b3494508f07e160bf94b788020a55e407ac443ebcb779e33c7282d7a1b47238e8b9f111b36c306eb1bbc8cd04d3250bfd1d5b1c
6
+ metadata.gz: ac494771259b27964318c3bc2111bd24a24a65a44fdc9246ed50ac6a5e39ec292cb599b269a60af6a512504c11b94cdf585bbddb59ff7cac060533cd4afd6bb1
7
+ data.tar.gz: 5cb1ad45218af0441a30ad84ff369c3f3ceb816704183bb87bf9df1199d27777cc8f1df297246d351845965c96ef105b6677e5d33c687e0eda1e30366c1decee
@@ -13,7 +13,7 @@ module Padrino
13
13
  fail "FormBuilder object must be present. If there's no object, use a symbol instead (i.e. :user)" unless object
14
14
  @options = options
15
15
  @namespace = options[:namespace]
16
- @model_name = options[:as] || @object.class.to_s.underscore.tr('/', '_')
16
+ @model_name = options[:as] || Inflections.underscore(@object.class).tr('/', '_')
17
17
  nested = options[:nested]
18
18
  if @is_nested = nested && (nested_parent = nested[:parent]) && nested_parent.respond_to?(:object)
19
19
  @parent_form = nested_parent
@@ -179,7 +179,7 @@ module Padrino
179
179
  # Returns the human name of the field. Look that use builtin I18n.
180
180
  #
181
181
  def field_human_name(field)
182
- I18n.translate("#{model_name}.attributes.#{field}", :count => 1, :default => field.to_s.humanize, :scope => :models)
182
+ I18n.translate("#{model_name}.attributes.#{field}", :count => 1, :default => Inflections.humanize(field), :scope => :models)
183
183
  end
184
184
 
185
185
  ##
@@ -232,7 +232,7 @@ module Padrino
232
232
  # Returns a record from template instance or create a record of specified class.
233
233
  #
234
234
  def build_object(symbol)
235
- @template.instance_variable_get("@#{symbol}") || symbol.to_s.camelize.constantize.new
235
+ @template.instance_variable_get("@#{symbol}") || Inflections.constantize(Inflections.camelize(symbol)).new
236
236
  end
237
237
 
238
238
  ##
@@ -88,7 +88,7 @@ module Padrino
88
88
  private
89
89
 
90
90
  def error_contents(objects, count, options)
91
- object_name = options[:object_name] || objects.first.class.to_s.underscore.gsub(/\//, ' ')
91
+ object_name = options[:object_name] || Inflections.underscore(objects.first.class).gsub(/\//, ' ')
92
92
 
93
93
  contents = SafeBuffer.new
94
94
  contents << error_header_tag(options, object_name, count)
@@ -99,7 +99,7 @@ module Padrino
99
99
  def error_list_tag(objects, object_name)
100
100
  errors = objects.inject({}){ |all,object| all.update(object.errors) }
101
101
  error_messages = errors.inject(SafeBuffer.new) do |all, (field, message)|
102
- field_name = I18n.t(field, :default => field.to_s.humanize, :scope => [:models, object_name, :attributes])
102
+ field_name = I18n.t(field, :default => Inflections.humanize(field), :scope => [:models, object_name, :attributes])
103
103
  all << content_tag(:li, "#{field_name} #{message}")
104
104
  end
105
105
  content_tag(:ul, error_messages)
@@ -107,7 +107,7 @@ module Padrino
107
107
 
108
108
  def error_header_tag(options, object_name, count)
109
109
  header_message = options[:header_message] || begin
110
- model_name = I18n.t(:name, :default => object_name.humanize, :scope => [:models, object_name], :count => 1)
110
+ model_name = I18n.t(:name, :default => Inflections.humanize(object_name), :scope => [:models, object_name], :count => 1)
111
111
  I18n.t :header, :count => count, :model => model_name, :locale => options[:locale], :scope => [:models, :errors, :template]
112
112
  end
113
113
  content_tag(options[:header_tag] || :h2, header_message) unless header_message.empty?
@@ -167,7 +167,7 @@ module Padrino
167
167
  # label_tag :username, :class => 'long-label' do ... end
168
168
  #
169
169
  def label_tag(name, options={}, &block)
170
- options = { :caption => "#{name.to_s.humanize}: ", :for => name }.update(options)
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
 
@@ -808,7 +808,7 @@ module Padrino
808
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
- builder_class = "Padrino::Helpers::FormBuilder::#{builder_class}".constantize if builder_class.is_a?(String)
811
+ builder_class = Padrino::Helpers::FormBuilder.const_get(builder_class) if builder_class.is_a?(String)
812
812
  builder_class.new(self, object, options)
813
813
  end
814
814
 
@@ -280,7 +280,7 @@ module Padrino
280
280
  #
281
281
  def nested_values(attribute, hash)
282
282
  hash.inject('') do |all,(key,value)|
283
- attribute_with_name = "#{attribute}-#{key.to_s.dasherize}"
283
+ attribute_with_name = "#{attribute}-#{key.to_s.tr('_', '-')}"
284
284
  all << if value.is_a?(Hash)
285
285
  nested_values(attribute_with_name, value)
286
286
  else
@@ -1,4 +1,5 @@
1
1
  require 'padrino-support'
2
+ require 'padrino-support/inflections'
2
3
  require 'i18n'
3
4
  require 'enumerator'
4
5
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: padrino-helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.3.1
4
+ version: 0.13.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Padrino Team
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2016-08-30 00:00:00.000000000 Z
14
+ date: 2016-09-06 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: padrino-support
@@ -19,14 +19,14 @@ dependencies:
19
19
  requirements:
20
20
  - - '='
21
21
  - !ruby/object:Gem::Version
22
- version: 0.13.3.1
22
+ version: 0.13.3.2
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - '='
28
28
  - !ruby/object:Gem::Version
29
- version: 0.13.3.1
29
+ version: 0.13.3.2
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: tilt
32
32
  requirement: !ruby/object:Gem::Requirement