padrino-helpers 0.13.3.1 → 0.13.3.2
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.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0905e2192dbffe4b6b0e5a2f3d6fa8451c3f2e37
|
4
|
+
data.tar.gz: 8e65ca6a317a2ccc2512671423ea3248f275ecab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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 =>
|
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}") ||
|
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.
|
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 =>
|
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 =>
|
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 => "#{
|
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 =
|
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.
|
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
|
data/lib/padrino-helpers.rb
CHANGED
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.
|
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-
|
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.
|
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.
|
29
|
+
version: 0.13.3.2
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: tilt
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|