attributes_for 0.3.1 → 0.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 +4 -4
- data/CHANGELOG.md +4 -0
- data/app/helpers/attributes_for/attributes_for_helper.rb +36 -53
- data/lib/attributes_for/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 24cac71563fed75d672dc6bfc93c1126ba39060b
|
|
4
|
+
data.tar.gz: c3da138c954270275ce2a2f36210e6d3969abd2b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0d7c590348937bae74c81560f490d52b59e5483d7ab9a5cf59bdbebce090a7443b7ba958e96dd1d1f21c4bdf735a3c04f292738bb3babce826b37e2771ab1264
|
|
7
|
+
data.tar.gz: 7aac3470f57f602bd38284643ae72e20c790bf00ba47ac0cbfbef9490feeb33cfc82e62dd45db5ac646803bd3b74a215e68fc615e2a2e4950bc231cbad433df1
|
data/CHANGELOG.md
CHANGED
|
@@ -15,71 +15,44 @@ module AttributesFor
|
|
|
15
15
|
@object, @template = object, template
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
-
def boolean(attribute_name, options = {}, &block)
|
|
19
|
-
options[:class] ||= 'fa fa-check'
|
|
20
|
-
content(attribute_name, __method__, options, &block)
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def phone(attribute_name, options = {}, &block)
|
|
24
|
-
options[:class] ||= 'fa fa-phone'
|
|
25
|
-
content(attribute_name, __method__, options, &block)
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def email(attribute_name, options = {}, &block)
|
|
29
|
-
options[:class] ||= 'fa fa-envelope'
|
|
30
|
-
content(attribute_name, __method__, options, &block)
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def url(attribute_name, options = {}, &block)
|
|
34
|
-
options[:class] ||= 'fa fa-globe'
|
|
35
|
-
content(attribute_name, __method__, options, &block)
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def date(attribute_name, options = {}, &block)
|
|
39
|
-
options[:class] ||= 'fa fa-clock-o'
|
|
40
|
-
content(attribute_name, __method__, options, &block)
|
|
41
|
-
end
|
|
42
|
-
|
|
43
18
|
def string(content, options = {})
|
|
44
19
|
wrap_content(" #{content}", options)
|
|
45
20
|
end
|
|
46
21
|
|
|
47
|
-
def
|
|
48
|
-
|
|
22
|
+
def method_missing(m, *args, &block)
|
|
23
|
+
build_content(m, *args, &block)
|
|
49
24
|
end
|
|
50
25
|
|
|
51
26
|
private
|
|
52
27
|
|
|
53
|
-
def
|
|
54
|
-
wrap_content(label(attribute_name, options) + build_content(attribute_name, method, options, &block), options)
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def build_content(attribute_name, method, options = {}, &block)
|
|
58
|
-
return template.capture(&block) if block_given?
|
|
59
|
-
|
|
28
|
+
def build_content(method, attribute_name, options = {}, &block)
|
|
60
29
|
value = attribute_value(attribute_name)
|
|
61
30
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
31
|
+
content = if block_given?
|
|
32
|
+
template.capture(&block)
|
|
33
|
+
elsif value.to_s.empty?
|
|
34
|
+
I18n.t "attributes_for.not_set"
|
|
35
|
+
else
|
|
36
|
+
case method.to_sym
|
|
37
|
+
when :boolean
|
|
38
|
+
I18n.t("attributes_for.#{value.to_s}")
|
|
39
|
+
when :date
|
|
40
|
+
I18n.l(value, format: options[:format])
|
|
41
|
+
when :email
|
|
42
|
+
mail_to(" #{value}", value, title: human_name(attribute_name))
|
|
43
|
+
when :phone
|
|
44
|
+
link_to(" #{number_to_phone(value)}", "tel:#{value}", title: human_name(attribute_name))
|
|
45
|
+
when :url
|
|
46
|
+
link_to(" #{value}", value, title: human_name(attribute_name))
|
|
47
|
+
else
|
|
48
|
+
value
|
|
49
|
+
end
|
|
77
50
|
end
|
|
78
|
-
end
|
|
79
51
|
|
|
80
|
-
|
|
81
|
-
options[:id]
|
|
82
|
-
|
|
52
|
+
options[:class] ||= icon_map(method)
|
|
53
|
+
options[:id] ||= attribute_name.to_s
|
|
54
|
+
|
|
55
|
+
wrap_content(label(attribute_name, options) + content, options)
|
|
83
56
|
end
|
|
84
57
|
|
|
85
58
|
def wrap_content(content, options = {})
|
|
@@ -103,6 +76,16 @@ module AttributesFor
|
|
|
103
76
|
object.class.human_attribute_name(attribute)
|
|
104
77
|
end
|
|
105
78
|
|
|
79
|
+
def icon_map(method)
|
|
80
|
+
{
|
|
81
|
+
boolean: 'fa fa-check',
|
|
82
|
+
date: 'fa fa-clock-o',
|
|
83
|
+
email: 'fa fa-envelope',
|
|
84
|
+
phone: 'fa fa-phone',
|
|
85
|
+
url: 'fa fa-globe',
|
|
86
|
+
}[method]
|
|
87
|
+
end
|
|
88
|
+
|
|
106
89
|
end
|
|
107
90
|
end
|
|
108
91
|
end
|