trenni-formatters 0.3.3 → 0.4.0
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 813dd7a079305803edf022d92a7658a693d44ece
|
4
|
+
data.tar.gz: db77a770b99e7f978900df8f8f2c67bde1851a0c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb3a8bf65681533a7f6b33a534f7d2697e7df74f59ba28b29c5b4dd5bb469cf20b6d314207adc4decfda790968cda362cdab9451962e9c852f45d27d9c95f3e0
|
7
|
+
data.tar.gz: 5d49a158f25c5f7f0afda482419c470d5a67b9f3f39666556da293c9705fafa136c553e82dc4930ad7debfd99bfce657af9a5534b583c72ec9275ea6ef6cba6f
|
@@ -41,6 +41,19 @@ module Trenni
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
+
# An output field for the result of a computation.
|
45
|
+
def output(options = {})
|
46
|
+
options = @options.merge(options)
|
47
|
+
|
48
|
+
Builder.fragment do |builder|
|
49
|
+
builder.inline(:dt) { builder.text title_for(options) }
|
50
|
+
|
51
|
+
builder.inline(:dd) do
|
52
|
+
builder.tag :output, output_attributes_for(options)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
44
57
|
# A textarea field (multi-line text).
|
45
58
|
def textarea(options = {})
|
46
59
|
options = @options.merge(options)
|
@@ -29,9 +29,13 @@ module Trenni
|
|
29
29
|
@options[:object]
|
30
30
|
end
|
31
31
|
|
32
|
-
# The name of the field.
|
32
|
+
# The name of the field, used for the name attribute of an input.
|
33
33
|
def name_for(options)
|
34
|
-
options[:
|
34
|
+
options[:name] || options[:field]
|
35
|
+
end
|
36
|
+
|
37
|
+
def field_for(options)
|
38
|
+
options[:field]
|
35
39
|
end
|
36
40
|
|
37
41
|
# The human presentable title for the field.
|
@@ -46,7 +50,7 @@ module Trenni
|
|
46
50
|
value = options[:value]
|
47
51
|
|
48
52
|
if options[:object]
|
49
|
-
value ||= options[:object].send(
|
53
|
+
value ||= options[:object].send(field_for(options))
|
50
54
|
end
|
51
55
|
|
52
56
|
# Allow to specify a default value if the value given, usually from an object, is nil.
|
@@ -67,6 +71,8 @@ module Trenni
|
|
67
71
|
attributes = {
|
68
72
|
:type => options[:type],
|
69
73
|
:name => name_for(options),
|
74
|
+
:id => options[:id],
|
75
|
+
:class => options[:class],
|
70
76
|
:value => value_for(options),
|
71
77
|
:required => options[:required] ? true : false,
|
72
78
|
:pattern => pattern_for(options),
|
@@ -77,9 +83,17 @@ module Trenni
|
|
77
83
|
:step => options[:step],
|
78
84
|
}
|
79
85
|
|
80
|
-
|
81
|
-
|
82
|
-
|
86
|
+
return attributes
|
87
|
+
end
|
88
|
+
|
89
|
+
def output_attributes_for(options)
|
90
|
+
attributes = {
|
91
|
+
:name => name_for(options),
|
92
|
+
:id => options[:id],
|
93
|
+
:class => options[:class],
|
94
|
+
:for => options[:for],
|
95
|
+
:form => options[:form],
|
96
|
+
}
|
83
97
|
|
84
98
|
return attributes
|
85
99
|
end
|
@@ -87,6 +101,8 @@ module Trenni
|
|
87
101
|
def textarea_attributes_for(options)
|
88
102
|
return {
|
89
103
|
:name => name_for(options),
|
104
|
+
:id => options[:id],
|
105
|
+
:class => options[:class],
|
90
106
|
:required => options[:required] ? true : false,
|
91
107
|
:placeholder => placeholder_for(options),
|
92
108
|
}
|
@@ -95,6 +111,8 @@ module Trenni
|
|
95
111
|
def checkbox_attributes_for(options)
|
96
112
|
return {
|
97
113
|
:type => options[:type] || 'checkbox',
|
114
|
+
:id => options[:id],
|
115
|
+
:class => options[:class],
|
98
116
|
:checked => options[:object].send(name),
|
99
117
|
:name => name_for(options),
|
100
118
|
:required => options[:required] ? true : false,
|
@@ -105,6 +123,8 @@ module Trenni
|
|
105
123
|
def submit_attributes_for(options)
|
106
124
|
return {
|
107
125
|
:type => options[:type] || 'submit',
|
126
|
+
:id => options[:id],
|
127
|
+
:class => options[:class],
|
108
128
|
:name => name_for(options),
|
109
129
|
:value => title_for(options),
|
110
130
|
}
|
@@ -113,6 +133,8 @@ module Trenni
|
|
113
133
|
def hidden_attributes_for(options)
|
114
134
|
return {
|
115
135
|
:type => options[:type] || 'hidden',
|
136
|
+
:id => options[:id],
|
137
|
+
:class => options[:class],
|
116
138
|
:name => name_for(options),
|
117
139
|
:value => value_for(options),
|
118
140
|
}
|