express_templates 0.3.6 → 0.4.0
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/lib/core_extensions/proc.rb +1 -5
- data/lib/express_templates/compiler.rb +10 -9
- data/lib/express_templates/components.rb +1 -1
- data/lib/express_templates/components/capabilities/adoptable.rb +20 -0
- data/lib/express_templates/components/capabilities/building.rb +6 -0
- data/lib/express_templates/components/capabilities/parenting.rb +7 -2
- data/lib/express_templates/components/capabilities/templating.rb +1 -1
- data/lib/express_templates/components/for_each.rb +2 -0
- data/lib/express_templates/components/form_rails_support.rb +4 -1
- data/lib/express_templates/components/forms.rb +15 -0
- data/lib/express_templates/components/forms/basic_fields.rb +53 -0
- data/lib/express_templates/components/forms/checkbox.rb +37 -0
- data/lib/express_templates/components/forms/express_form.rb +66 -0
- data/lib/express_templates/components/forms/form_component.rb +60 -0
- data/lib/express_templates/components/forms/option_support.rb +43 -0
- data/lib/express_templates/components/forms/radio.rb +84 -0
- data/lib/express_templates/components/forms/select.rb +61 -0
- data/lib/express_templates/components/forms/submit.rb +26 -0
- data/lib/express_templates/components/null_wrap.rb +33 -1
- data/lib/express_templates/expander.rb +1 -0
- data/lib/express_templates/version.rb +1 -1
- data/test/components/container_test.rb +2 -0
- data/test/components/forms/basic_fields_test.rb +52 -0
- data/test/components/forms/checkbox_test.rb +44 -0
- data/test/components/forms/express_form_test.rb +120 -0
- data/test/components/forms/radio_test.rb +91 -0
- data/test/components/forms/select_test.rb +75 -0
- data/test/components/forms/submit_test.rb +12 -0
- data/test/components/iterating_test.rb +18 -0
- data/test/components/null_wrap_test.rb +28 -0
- data/test/components/table_for_test.rb +6 -6
- data/test/dummy/log/test.log +13758 -0
- data/test/markup/tag_test.rb +1 -1
- metadata +26 -5
- data/lib/express_templates/components/form_for.rb +0 -469
- data/test/components/form_for_test.rb +0 -246
@@ -1,246 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'ostruct'
|
3
|
-
|
4
|
-
class FormForTest < ActiveSupport::TestCase
|
5
|
-
class Context
|
6
|
-
def initialize(resource)
|
7
|
-
@resource = resource
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
def resource
|
12
|
-
OpenStruct.new(
|
13
|
-
id: 1,
|
14
|
-
name: 'Foo',
|
15
|
-
body: 'Hello world',
|
16
|
-
email: 'some@email.com',
|
17
|
-
phone: '123123123',
|
18
|
-
url: 'http://someurl.com',
|
19
|
-
number: 123,
|
20
|
-
dropdown: 'yes',
|
21
|
-
gender: 'Male'
|
22
|
-
)
|
23
|
-
end
|
24
|
-
|
25
|
-
def setup
|
26
|
-
@example_compiled = -> {
|
27
|
-
ExpressTemplates::Components::FormFor.render_in(self) {
|
28
|
-
"<form action=\"/resources/#{@resource.id}\" method=\"post\" url=\"/posts\" id=\"post_form\">
|
29
|
-
<div style=\"display:none\">
|
30
|
-
"+%Q(#{utf8_enforcer_tag})+%Q(#{method_tag(:patch)})+%Q(#{token_tag})+"
|
31
|
-
</div>
|
32
|
-
|
33
|
-
<div class=\"\">
|
34
|
-
"+%Q(#{label_tag("resource_name", "post title")})+%Q(#{text_field_tag("resource[name]", @resource.name, {})})+"
|
35
|
-
</div>
|
36
|
-
|
37
|
-
<div class=\"\">
|
38
|
-
"+%Q(#{label_tag("resource_body", "Body")})+%Q(#{text_field_tag("resource[body]", @resource.body, class: "string")})+"
|
39
|
-
</div>
|
40
|
-
|
41
|
-
<div class=\"field input\">
|
42
|
-
"+%Q(#{label_tag("resource_email", "Email")})+%Q(#{email_field_tag("resource[email]", @resource.email, {})})+"
|
43
|
-
</div>
|
44
|
-
|
45
|
-
<div class=\"\">
|
46
|
-
"+%Q(#{label_tag("resource_mobile_phone", "Mobile Phone")})+%Q(#{phone_field_tag("resource[mobile_phone]", @resource.mobile_phone, {})})+"
|
47
|
-
</div>
|
48
|
-
|
49
|
-
<div class=\"\">
|
50
|
-
"+%Q(#{label_tag("resource_url", "Url")})+%Q(#{url_field_tag("resource[url]", @resource.url, {})})+"
|
51
|
-
</div>
|
52
|
-
|
53
|
-
<div class=\"\">
|
54
|
-
"+%Q(#{label_tag("resource_number", "Number")})+%Q(#{number_field_tag("resource[number]", @resource.number, {})})+"
|
55
|
-
</div>
|
56
|
-
|
57
|
-
<div class=\"\">"+%Q(#{submit_tag("Save it!", {})})+"</div>
|
58
|
-
</form>
|
59
|
-
"
|
60
|
-
}
|
61
|
-
}
|
62
|
-
end
|
63
|
-
|
64
|
-
def example_compiled_src
|
65
|
-
# necessary because the #source method is not perfect yet
|
66
|
-
# ideally we would have #source_body
|
67
|
-
@example_compiled.source_body
|
68
|
-
end
|
69
|
-
|
70
|
-
def simple_form(resource)
|
71
|
-
ctx = Context.new(resource)
|
72
|
-
fragment = -> {
|
73
|
-
form_for(:resource, method: :put, url: '/posts', html_options: {id: 'post_form'}) do |f|
|
74
|
-
f.text_field :name, label: 'post title'
|
75
|
-
f.text_field :body, class: 'string'
|
76
|
-
f.email_field :email, wrapper_class: 'field input'
|
77
|
-
f.phone_field :mobile_phone
|
78
|
-
f.url_field :url
|
79
|
-
f.number_field :number
|
80
|
-
f.submit 'Save it!'
|
81
|
-
end
|
82
|
-
}
|
83
|
-
return ctx, fragment
|
84
|
-
end
|
85
|
-
|
86
|
-
def select_form(resource)
|
87
|
-
ctx = Context.new(resource)
|
88
|
-
fragment = -> {
|
89
|
-
form_for(:resource, method: :put) do |f|
|
90
|
-
f.select :dropdown, ['yes', 'no'], selected: 'yes'
|
91
|
-
f.select :dropdown, '{{ options_from_collection_for_select(@choices, "id", "name") }}'
|
92
|
-
end
|
93
|
-
}
|
94
|
-
return ctx, fragment
|
95
|
-
end
|
96
|
-
|
97
|
-
def radio_form(resource)
|
98
|
-
ctx = Context.new(resource)
|
99
|
-
fragment = -> {
|
100
|
-
form_for(:resource) do |f|
|
101
|
-
f.radio :age, [[1, 'One'],[2, 'Two']], :first, :last
|
102
|
-
f.radio :enable_something, :boolean
|
103
|
-
end
|
104
|
-
}
|
105
|
-
return ctx, fragment
|
106
|
-
end
|
107
|
-
|
108
|
-
def checkbox_form(resource)
|
109
|
-
ctx = Context.new(resource)
|
110
|
-
fragment = -> {
|
111
|
-
form_for(:resource, method: :put) do |f|
|
112
|
-
f.checkbox :age, [[1, 'One'], [2, 'Two']], :first, :last
|
113
|
-
end
|
114
|
-
}
|
115
|
-
return ctx, fragment
|
116
|
-
end
|
117
|
-
|
118
|
-
def advanced_form(resource)
|
119
|
-
ctx = Context.new(resource)
|
120
|
-
fragment = -> {
|
121
|
-
form_for(:resource, method: :put, url: '/posts') do |f|
|
122
|
-
f.text_field :name, label: 'post title'
|
123
|
-
f.text_field :body, class: 'string'
|
124
|
-
f.actions({submit: ['Save', {class: 'submit primary'}], cancel: ['Cancel it', class: 'cancel secondary']}, wrapper_class: 'form-group widget-buttons')
|
125
|
-
end
|
126
|
-
}
|
127
|
-
return ctx, fragment
|
128
|
-
end
|
129
|
-
|
130
|
-
test "fields compiled source is legible and transparent" do
|
131
|
-
ExpressTemplates::Markup::Tag.formatted do
|
132
|
-
ctx, fragment = simple_form(resource)
|
133
|
-
assert_equal example_compiled_src, ExpressTemplates.compile(&fragment)
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
test 'advanced form can have additional actions' do
|
138
|
-
@example_compiled = -> {
|
139
|
-
ExpressTemplates::Components::FormFor.render_in(self) {
|
140
|
-
"<form action=\"/resources/#{@resource.id}\" method=\"post\" url=\"/posts\">
|
141
|
-
<div style=\"display:none\">
|
142
|
-
"+%Q(#{utf8_enforcer_tag})+%Q(#{method_tag(:patch)})+%Q(#{token_tag})+"
|
143
|
-
</div>
|
144
|
-
|
145
|
-
<div class=\"\">
|
146
|
-
"+%Q(#{label_tag("resource_name", "post title")})+%Q(#{text_field_tag("resource[name]", @resource.name, {})})+"
|
147
|
-
</div>
|
148
|
-
|
149
|
-
<div class=\"\">
|
150
|
-
"+%Q(#{label_tag("resource_body", "Body")})+%Q(#{text_field_tag("resource[body]", @resource.body, class: "string")})+"
|
151
|
-
</div>
|
152
|
-
|
153
|
-
<div class=\"form-group widget-buttons\">
|
154
|
-
"+%Q(#{submit_tag("Save", class: "submit primary")})+"
|
155
|
-
<a href=\"#\" onclick=\"return false;\" class=\"cancel secondary\">Cancel it</a>
|
156
|
-
</div>
|
157
|
-
</form>
|
158
|
-
"
|
159
|
-
}
|
160
|
-
}
|
161
|
-
ExpressTemplates::Markup::Tag.formatted do
|
162
|
-
ctx, fragment = advanced_form(resource)
|
163
|
-
assert_equal example_compiled_src, ExpressTemplates.compile(&fragment)
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
test "select compiled source is legible and transparent" do
|
168
|
-
@example_compiled = -> {
|
169
|
-
ExpressTemplates::Components::FormFor.render_in(self) {
|
170
|
-
"<form action=\"/resources/#{@resource.id}\" method=\"post\">
|
171
|
-
<div style=\"display:none\">
|
172
|
-
"+%Q(#{utf8_enforcer_tag})+%Q(#{method_tag(:patch)})+%Q(#{token_tag})+"
|
173
|
-
</div>
|
174
|
-
|
175
|
-
<div class=\"\">
|
176
|
-
"+%Q(#{label_tag("resource_dropdown", "Dropdown")})+%Q(#{select_tag("resource[dropdown]", '<option selected=selected>yes</option><option >no</option>'.html_safe, {})})+"
|
177
|
-
</div>
|
178
|
-
|
179
|
-
<div class=\"\">
|
180
|
-
"+%Q(#{label_tag("resource_dropdown", "Dropdown")})+%Q(#{select_tag("resource[dropdown]", options_from_collection_for_select(@choices, "id", "name") , {})})+"
|
181
|
-
</div>
|
182
|
-
</form>
|
183
|
-
"
|
184
|
-
}
|
185
|
-
}
|
186
|
-
ExpressTemplates::Markup::Tag.formatted do
|
187
|
-
ctx, fragment = select_form(resource)
|
188
|
-
assert_equal example_compiled_src, ExpressTemplates.compile(&fragment)
|
189
|
-
end
|
190
|
-
end
|
191
|
-
|
192
|
-
test "radio compiled source is legible and transparent" do
|
193
|
-
@example_compiled = -> {
|
194
|
-
ExpressTemplates::Components::FormFor.render_in(self) {
|
195
|
-
"<form action=\"/resources\" method=\"post\">
|
196
|
-
<div style=\"display:none\">
|
197
|
-
"+%Q(#{utf8_enforcer_tag})+%Q(#{method_tag(:post)})+%Q(#{token_tag})+"
|
198
|
-
</div>
|
199
|
-
|
200
|
-
<div class=\"\">
|
201
|
-
"+%Q(#{label_tag("resource_age", "Age")})+%Q(#{collection_radio_buttons(:resource, :age, [[1, "One"], [2, "Two"]], :first, :last, {}) do |b|
|
202
|
-
b.label(class: 'radio') { b.radio_button + b.text }
|
203
|
-
end})+"
|
204
|
-
</div>
|
205
|
-
|
206
|
-
<div class=\"\">
|
207
|
-
"+%Q(#{label_tag("resource_enable_something", "Enable Something")})+%Q(#{collection_radio_buttons(:resource, :enable_something, [[true, "True"], [false, "False"]], :first, :last, {}) do |b|
|
208
|
-
b.label(class: 'radio') { b.radio_button + b.text }
|
209
|
-
end})+"
|
210
|
-
</div>
|
211
|
-
</form>
|
212
|
-
"
|
213
|
-
}
|
214
|
-
}
|
215
|
-
|
216
|
-
ExpressTemplates::Markup::Tag.formatted do
|
217
|
-
ctx, fragment = radio_form(resource)
|
218
|
-
assert_equal example_compiled_src, ExpressTemplates.compile(&fragment)
|
219
|
-
end
|
220
|
-
end
|
221
|
-
|
222
|
-
test "checkbox compiled source is legible and transparent" do
|
223
|
-
@example_compiled = -> {
|
224
|
-
ExpressTemplates::Components::FormFor.render_in(self) {
|
225
|
-
"<form action=\"/resources/#{@resource.id}\" method=\"post\">
|
226
|
-
<div style=\"display:none\">
|
227
|
-
"+%Q(#{utf8_enforcer_tag})+%Q(#{method_tag(:patch)})+%Q(#{token_tag})+"
|
228
|
-
</div>
|
229
|
-
|
230
|
-
<div class=\"\">
|
231
|
-
"+%Q(#{label_tag("resource_age", "Age")})+%Q(#{collection_check_boxes(:resource, :age, [[1, "One"], [2, "Two"]], :first, :last, {}) do |b|
|
232
|
-
b.label(class: 'checkbox') { b.check_box + b.text }
|
233
|
-
end})+"
|
234
|
-
</div>
|
235
|
-
</form>
|
236
|
-
"
|
237
|
-
}
|
238
|
-
}
|
239
|
-
|
240
|
-
ExpressTemplates::Markup::Tag.formatted do
|
241
|
-
ctx, fragment = checkbox_form(resource)
|
242
|
-
assert_equal example_compiled_src, ExpressTemplates.compile(&fragment)
|
243
|
-
end
|
244
|
-
|
245
|
-
end
|
246
|
-
end
|