padrino-helpers 0.11.1 → 0.11.2
Sign up to get free protection for your applications and to get access to all the features.
@@ -24,9 +24,9 @@ module Padrino
|
|
24
24
|
end
|
25
25
|
|
26
26
|
# f.label :username, :caption => "Nickname"
|
27
|
-
def label(field, options={})
|
27
|
+
def label(field, options={}, &block)
|
28
28
|
options.reverse_merge!(:caption => "#{field_human_name(field)}: ")
|
29
|
-
@template.label_tag(field_id(field), options)
|
29
|
+
@template.label_tag(field_id(field), options, &block)
|
30
30
|
end
|
31
31
|
|
32
32
|
# f.hidden_field :session_id, :value => "45"
|
@@ -271,7 +271,7 @@ module Padrino
|
|
271
271
|
else
|
272
272
|
[]
|
273
273
|
end
|
274
|
-
variants.inject('') do |html, variant|
|
274
|
+
variants.inject(''.html_safe) do |html, variant|
|
275
275
|
variant[2] = "#{field_id(field)}_#{variant[1]}"
|
276
276
|
html << @template.label_tag("#{field_name(field)}[]", :for => variant[2], :caption => "#{yield(variant)} #{variant[0]}")
|
277
277
|
end
|
@@ -248,7 +248,14 @@ module Padrino
|
|
248
248
|
def error_message_on(object, field, options={})
|
249
249
|
object = object.is_a?(Symbol) ? instance_variable_get("@#{object}") : object
|
250
250
|
error = object.errors[field] rescue nil
|
251
|
-
|
251
|
+
error = if defined?(Ohm::Model) && object.is_a?(Ohm::Model)
|
252
|
+
I18n.t("ohm.errors.messages.#{error[0]}", :default => error[0].to_s)
|
253
|
+
else
|
254
|
+
# Array(error).first is necessary because some ORMs
|
255
|
+
# give us an array others directly a value
|
256
|
+
Array(error)[0]
|
257
|
+
end
|
258
|
+
|
252
259
|
if error = Array(error)[0]
|
253
260
|
options.reverse_merge!(:tag => :span, :class => :error)
|
254
261
|
tag = options.delete(:tag)
|
data/test/helper.rb
CHANGED
@@ -27,6 +27,7 @@ class MiniTest::Spec
|
|
27
27
|
# In this case, block is the html to evaluate
|
28
28
|
def assert_has_tag(name, attributes = {}, &block)
|
29
29
|
html = block && block.call
|
30
|
+
assert html.html_safe?, 'html_safe? failed'
|
30
31
|
matcher = HaveSelector.new(name, attributes)
|
31
32
|
raise "Please specify a block!" if html.blank?
|
32
33
|
assert matcher.matches?(html), matcher.failure_message
|
data/test/test_form_builder.rb
CHANGED
@@ -256,6 +256,12 @@ describe "FormBuilder" do
|
|
256
256
|
assert_has_tag('label', :class => 'large', :for => 'user_first_name', :content => "F. Name: ") { actual_html }
|
257
257
|
end
|
258
258
|
|
259
|
+
should "set specific content inside the label if a block was provided" do
|
260
|
+
actual_html = standard_builder.label(:admin, :class => 'large') { input_tag :checkbox }
|
261
|
+
assert_has_tag('label', :class => 'large', :for => 'user_admin', :content => "Admin: ") { actual_html }
|
262
|
+
assert_has_tag('label input[type=checkbox]') { actual_html }
|
263
|
+
end
|
264
|
+
|
259
265
|
should "display correct label in haml" do
|
260
266
|
visit '/haml/form_for'
|
261
267
|
assert_have_selector '#demo label', :content => "Login: ", :class => 'user-label'
|
data/test/test_form_helpers.rb
CHANGED
@@ -200,6 +200,12 @@ describe "FormHelpers" do
|
|
200
200
|
assert_has_tag('label[for=username] span.required', :content => "*") { actual_html }
|
201
201
|
end
|
202
202
|
|
203
|
+
should "display label tag in ruby with a block" do
|
204
|
+
actual_html = label_tag(:admin, :class => 'long-label') { input_tag :checkbox }
|
205
|
+
assert_has_tag(:label, :for => 'admin', :class => 'long-label', :content => "Admin") { actual_html }
|
206
|
+
assert_has_tag('label input[type=checkbox]') { actual_html }
|
207
|
+
end
|
208
|
+
|
203
209
|
should "display label tag in erb for simple form" do
|
204
210
|
visit '/erb/form_tag'
|
205
211
|
assert_have_selector 'form.simple-form label', :count => 9
|
@@ -207,6 +213,7 @@ describe "FormHelpers" do
|
|
207
213
|
assert_have_selector 'form.simple-form label', :content => "Password", :for => 'password'
|
208
214
|
assert_have_selector 'form.simple-form label', :content => "Gender", :for => 'gender'
|
209
215
|
end
|
216
|
+
|
210
217
|
should "display label tag in erb for advanced form" do
|
211
218
|
visit '/erb/form_tag'
|
212
219
|
assert_have_selector 'form.advanced-form label', :count => 11
|
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.11.
|
4
|
+
version: 0.11.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2013-
|
15
|
+
date: 2013-05-21 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: padrino-core
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
requirements:
|
22
22
|
- - '='
|
23
23
|
- !ruby/object:Gem::Version
|
24
|
-
version: 0.11.
|
24
|
+
version: 0.11.2
|
25
25
|
type: :runtime
|
26
26
|
prerelease: false
|
27
27
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,7 +29,7 @@ dependencies:
|
|
29
29
|
requirements:
|
30
30
|
- - '='
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 0.11.
|
32
|
+
version: 0.11.2
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: i18n
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -174,7 +174,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
174
174
|
version: '0'
|
175
175
|
segments:
|
176
176
|
- 0
|
177
|
-
hash:
|
177
|
+
hash: -1875793301041170039
|
178
178
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
179
179
|
none: false
|
180
180
|
requirements:
|