express_templates 0.5.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +22 -41
- data/lib/arbre/patches.rb +50 -0
- data/lib/core_extensions/proc.rb +1 -0
- data/lib/express_templates/compiler.rb +2 -7
- data/lib/express_templates/components/base.rb +33 -37
- data/lib/express_templates/components/capabilities/resourceful.rb +30 -18
- data/lib/express_templates/components/configurable.rb +41 -0
- data/lib/express_templates/components/form_rails_support.rb +5 -6
- data/lib/express_templates/components/forms/basic_fields.rb +3 -6
- data/lib/express_templates/components/forms/checkbox.rb +1 -1
- data/lib/express_templates/components/forms/express_form.rb +15 -25
- data/lib/express_templates/components/forms/form_component.rb +20 -11
- data/lib/express_templates/components/forms/option_support.rb +2 -2
- data/lib/express_templates/components/forms/radio.rb +7 -8
- data/lib/express_templates/components/forms/select.rb +61 -37
- data/lib/express_templates/components/forms/select_collection.rb +2 -8
- data/lib/express_templates/components/forms/submit.rb +7 -6
- data/lib/express_templates/components/forms.rb +0 -1
- data/lib/express_templates/components/tree_for.rb +26 -42
- data/lib/express_templates/components.rb +1 -9
- data/lib/express_templates/version.rb +1 -1
- data/lib/express_templates.rb +2 -3
- data/test/components/base_test.rb +17 -15
- data/test/components/capabilities/resourceful_test.rb +3 -3
- data/test/components/configurable_test.rb +27 -21
- data/test/components/forms/basic_fields_test.rb +57 -17
- data/test/components/forms/checkbox_test.rb +16 -22
- data/test/components/forms/express_form_test.rb +23 -76
- data/test/components/forms/radio_test.rb +31 -27
- data/test/components/forms/select_test.rb +46 -71
- data/test/components/forms/submit_test.rb +10 -5
- data/test/components/tree_for_test.rb +24 -52
- data/test/dummy/app/views/hello/show.html.et +4 -3
- data/test/dummy/app/views/layouts/application.html.et +1 -1
- data/test/dummy/log/test.log +4794 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/-cDLO4NJHMndDHchOLz8KLD7QBc68WtaAbYxK2r6GsU.cache +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/0t68EIwZ96sAqQSxFka9MQyIk4viw8ZIoREMCGiJRx0.cache +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/2zt1IbQCnmzGyeZS_I4sYQzrgneSCKIJBRxcffVHlWY.cache +1 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/EDVlXrcn_wEfaZ5nc_4QJBT7lPiIBcX96jBo7PBz-vc.cache +1 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/Eso3tkb79hXQ1XdQgjbV03KyQwSeZFAHxVHImsjQ-HQ.cache +2 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/I8LhheC1OlOyvp_qY8kWpqKcZFiqv_BO-l5bExvDEi0.cache +1 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/Kf4VrP5sW-qzziYSN-m7p4nETjLiEwwwRfwUOm7rOr0.cache +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/QJ0Z8hROMfWpY6f5Chb7GSuDHE4gpabKVQTr9BCZe9s.cache +1 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/T1pSAx767vY7X1UDN0vdF7YGEkI5wMSVUKopsdvp7kI.cache +1 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/VlSPFPDK05c7ImadRiRVKzsaa6e15RwX77QR3NYabME.cache +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/Y7_BbgB9jgJIWYjDCsASySd26DTfPADAu_3DDnLlFog.cache +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/g2xQygPqA5kMmp5L3wVGWaUIhdVsxFmOel9FF6M0Fuw.cache +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/kaif59owjUr3HBharCH5GUxU6KoW_zXD9a9JiTjIYPY.cache +1 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/p1cwnBd8RQBm9x5HzDmiiU7RhvnxhPX8VTfi0tTElJY.cache +3 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/qT6_0ti_v6fAjS3wETXqvTkr6W0LP4PB942uLYQzWK8.cache +3 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/y8T65xpx0s3RgT_YiqWEEXIaBsgK4woCNSuZ1zjQZBk.cache +2 -0
- data/test/express_templates_test.rb +5 -1
- data/test/handler_test.rb +19 -17
- data/test/performance_test.rb +11 -7
- data/test/test_helper.rb +162 -1
- metadata +50 -53
- data/lib/express_templates/components/capabilities/adoptable.rb +0 -20
- data/lib/express_templates/components/capabilities/building.rb +0 -14
- data/lib/express_templates/components/capabilities/conditionality.rb +0 -54
- data/lib/express_templates/components/capabilities/configurable.rb +0 -90
- data/lib/express_templates/components/capabilities/iterating.rb +0 -75
- data/lib/express_templates/components/capabilities/parenting.rb +0 -72
- data/lib/express_templates/components/capabilities/rendering.rb +0 -30
- data/lib/express_templates/components/capabilities/templating.rb +0 -198
- data/lib/express_templates/components/capabilities/wrapping.rb +0 -84
- data/lib/express_templates/components/column.rb +0 -13
- data/lib/express_templates/components/container.rb +0 -7
- data/lib/express_templates/components/content_for.rb +0 -42
- data/lib/express_templates/components/for_each.rb +0 -30
- data/lib/express_templates/components/forms/form_support.rb +0 -13
- data/lib/express_templates/components/null_wrap.rb +0 -41
- data/lib/express_templates/components/row.rb +0 -28
- data/lib/express_templates/components/table_for.rb +0 -163
- data/lib/express_templates/components/unless_block.rb +0 -40
- data/lib/express_templates/expander.rb +0 -140
- data/lib/express_templates/macro.rb +0 -45
- data/lib/express_templates/markup/html_tag.rb +0 -62
- data/lib/express_templates/markup/tag.rb +0 -150
- data/lib/express_templates/markup/wrapper.rb +0 -94
- data/lib/express_templates/markup/yielder.rb +0 -21
- data/lib/express_templates/markup.rb +0 -9
- data/test/components/column_test.rb +0 -11
- data/test/components/conditionality_test.rb +0 -37
- data/test/components/container_test.rb +0 -66
- data/test/components/content_for_test.rb +0 -60
- data/test/components/iterating_test.rb +0 -127
- data/test/components/null_wrap_test.rb +0 -28
- data/test/components/row_test.rb +0 -16
- data/test/components/table_for_test.rb +0 -211
- data/test/expander_stack_test.rb +0 -41
- data/test/expander_test.rb +0 -99
- data/test/markup/tag_test.rb +0 -149
- data/test/markup/wrapper_test.rb +0 -42
- data/test/markup/yielder_test.rb +0 -9
@@ -16,8 +16,7 @@ module ExpressTemplates
|
|
16
16
|
}
|
17
17
|
|
18
18
|
def use_options_from_collection_radio_buttons_helper
|
19
|
-
|
20
|
-
collection_radio_buttons(resource_var, field_name.to_sym, "{{#{collection_from_association}}}",
|
19
|
+
collection_radio_buttons(resource_var, field_name.to_sym, collection_from_association,
|
21
20
|
option_value_method, option_name_method,
|
22
21
|
field_options, html_options) do |b|
|
23
22
|
b.label(class: "radio") {
|
@@ -31,11 +30,11 @@ module ExpressTemplates
|
|
31
30
|
end
|
32
31
|
|
33
32
|
def option_collection
|
34
|
-
@args.
|
33
|
+
@args.first
|
35
34
|
end
|
36
35
|
|
37
36
|
def wrapper_class
|
38
|
-
|
37
|
+
config[:wrapper_class] || 'wrapper-class'
|
39
38
|
end
|
40
39
|
|
41
40
|
def generate_options_from_specified_values
|
@@ -44,14 +43,14 @@ module ExpressTemplates
|
|
44
43
|
option_collection.each_with_index do |option, index|
|
45
44
|
label(class: wrapper_class) {
|
46
45
|
radio_button(resource_var, field_name.to_sym, option, class: 'radio')
|
47
|
-
|
46
|
+
current_arbre_element.add_child option
|
48
47
|
}
|
49
48
|
end
|
50
49
|
when option_collection.kind_of?(Hash)
|
51
50
|
option_collection.each_pair do |key, value|
|
52
51
|
label(class: wrapper_class) {
|
53
52
|
radio_button(resource_var, field_name.to_sym, key, class: 'radio')
|
54
|
-
|
53
|
+
current_arbre_element.add_child value
|
55
54
|
}
|
56
55
|
end
|
57
56
|
else
|
@@ -66,8 +65,8 @@ module ExpressTemplates
|
|
66
65
|
def field_options
|
67
66
|
# If field_otions is omitted the Expander will be
|
68
67
|
# in last or 3rd position and we don't want that
|
69
|
-
if @args
|
70
|
-
@args[
|
68
|
+
if @args[1] && @args[1].is_a?(Hash)
|
69
|
+
@args[1]
|
71
70
|
else
|
72
71
|
{}
|
73
72
|
end
|
@@ -26,39 +26,63 @@ module ExpressTemplates
|
|
26
26
|
}
|
27
27
|
|
28
28
|
def select_tag_args
|
29
|
-
args = [field_name_attribute, select_options,
|
30
|
-
args << html_options unless html_options.nil? or html_options.empty?
|
29
|
+
args = [field_name_attribute, select_options, select_helper_options]
|
31
30
|
args
|
32
31
|
end
|
33
32
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
if options_specified
|
38
|
-
if @args.second.respond_to?(:source) # can be a proc
|
39
|
-
options = "#{@args.second.source}.call()"
|
40
|
-
else
|
41
|
-
options = @args.second
|
42
|
-
end
|
33
|
+
def select_options_supplied?
|
34
|
+
[Array, Hash, Proc].include?(supplied_component_options[:options].class)
|
35
|
+
end
|
43
36
|
|
37
|
+
def use_supplied_options
|
38
|
+
opts = supplied_component_options[:options]
|
39
|
+
if opts.respond_to?(:call) # can be a proc
|
40
|
+
opts.call()
|
44
41
|
else
|
45
|
-
|
42
|
+
opts
|
46
43
|
end
|
44
|
+
end
|
47
45
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
46
|
+
def generate_options_from_field_values
|
47
|
+
resource.class.distinct(field_name.to_sym).pluck(field_name.to_sym)
|
48
|
+
end
|
49
|
+
|
50
|
+
def options_from_supplied_or_field_values
|
51
|
+
if select_options_supplied?
|
52
|
+
use_supplied_options
|
53
|
+
else
|
54
|
+
generate_options_from_field_values
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def options_from_belongs_to
|
59
|
+
if belongs_to_association.polymorphic?
|
60
|
+
helpers.options_for_select([[]]) # we can't really handle polymorhic yet
|
61
|
+
else
|
62
|
+
helpers.options_from_collection_for_select(related_collection, :id, option_name_method, resource.send(field_name))
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def options_from_has_many_through
|
67
|
+
helpers.options_from_collection_for_select(related_collection, :id, option_name_method, resource.send(field_name).map(&:id))
|
68
|
+
end
|
69
|
+
|
70
|
+
def simple_options_with_selection
|
71
|
+
if selection = field_options[:selected]
|
72
|
+
helpers.options_for_select(options_from_supplied_or_field_values, selection)
|
73
|
+
else
|
74
|
+
helpers.options_for_select(options_from_supplied_or_field_values, resource.send(field_name))
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# Returns the options which will be supplied to the select_tag helper.
|
79
|
+
def select_options
|
80
|
+
if belongs_to_association && !select_options_supplied?
|
81
|
+
options_from_belongs_to
|
54
82
|
elsif has_many_through_association
|
55
|
-
|
83
|
+
options_from_has_many_through
|
56
84
|
else
|
57
|
-
|
58
|
-
"{{options_for_select(#{options}, \"#{selection}\")}}"
|
59
|
-
else
|
60
|
-
"{{options_for_select(#{options}, @#{resource_name}.#{field_name})}}"
|
61
|
-
end
|
85
|
+
simple_options_with_selection
|
62
86
|
end
|
63
87
|
end
|
64
88
|
|
@@ -74,26 +98,26 @@ module ExpressTemplates
|
|
74
98
|
# If field_otions is omitted the Expander will be
|
75
99
|
# in last or 3rd position and we don't want that
|
76
100
|
defaults = {include_blank: true}
|
77
|
-
defaults.merge(
|
101
|
+
defaults.merge(supplied_component_options)
|
78
102
|
end
|
79
103
|
|
80
|
-
def
|
81
|
-
|
104
|
+
def select_helper_options
|
105
|
+
component_option_names = [:select2, :options, :selected]
|
106
|
+
add_select2_class( field_options.reject {|k,v| component_option_names.include?(k)})
|
82
107
|
end
|
83
108
|
|
84
109
|
protected
|
85
110
|
|
86
|
-
def
|
87
|
-
if
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
end
|
111
|
+
def add_select2_class(helper_options)
|
112
|
+
add_class(helper_options[:class]) if helper_options[:class]
|
113
|
+
add_class('select2') if supplied_component_options[:select2] === true
|
114
|
+
helper_options[:class] = (class_list - ["select"]).to_s
|
115
|
+
helper_options
|
92
116
|
end
|
93
117
|
|
94
|
-
def
|
95
|
-
if @args.
|
96
|
-
@args
|
118
|
+
def supplied_component_options
|
119
|
+
if @args.last && @args.last.is_a?(Hash)
|
120
|
+
@args.last
|
97
121
|
else
|
98
122
|
{}
|
99
123
|
end
|
@@ -102,4 +126,4 @@ module ExpressTemplates
|
|
102
126
|
end
|
103
127
|
end
|
104
128
|
end
|
105
|
-
end
|
129
|
+
end
|
@@ -17,7 +17,6 @@ module ExpressTemplates
|
|
17
17
|
# need this because the collection_select helper does not provide
|
18
18
|
# the hidden_field_tag trick (see rails api docs for select)
|
19
19
|
hidden_field_tag(multi_field_name, '')
|
20
|
-
|
21
20
|
collection_select(*collection_select_tag_args)
|
22
21
|
}
|
23
22
|
}
|
@@ -25,14 +24,13 @@ module ExpressTemplates
|
|
25
24
|
def collection_select_tag_args
|
26
25
|
[ resource_name,
|
27
26
|
multi_field_name,
|
28
|
-
|
27
|
+
related_collection, :id, :name,
|
29
28
|
field_options,
|
30
29
|
html_options ]
|
31
30
|
end
|
32
31
|
|
33
32
|
def field_options
|
34
|
-
|
35
|
-
super.merge(include_blank: false, selected: selected_options_ruby)
|
33
|
+
super.merge(include_blank: false)
|
36
34
|
end
|
37
35
|
|
38
36
|
def html_options
|
@@ -47,10 +45,6 @@ module ExpressTemplates
|
|
47
45
|
end
|
48
46
|
end
|
49
47
|
|
50
|
-
|
51
|
-
def select_options
|
52
|
-
"{{#{related_collection}}}"
|
53
|
-
end
|
54
48
|
end
|
55
49
|
end
|
56
50
|
end
|
@@ -3,11 +3,15 @@ module ExpressTemplates
|
|
3
3
|
module Forms
|
4
4
|
class Submit < FormComponent
|
5
5
|
|
6
|
-
|
6
|
+
def build(*args)
|
7
7
|
div(class: field_wrapper_class) {
|
8
|
-
|
8
|
+
if args.first.is_a?(String) or args.empty?
|
9
|
+
submit_tag(args.first || 'Save', (args[1]||{}))
|
10
|
+
else
|
11
|
+
submit_tag 'Save', (args[1] || {})
|
12
|
+
end
|
9
13
|
}
|
10
|
-
|
14
|
+
end
|
11
15
|
|
12
16
|
def value
|
13
17
|
if @args.first.is_a?(String)
|
@@ -17,9 +21,6 @@ module ExpressTemplates
|
|
17
21
|
end
|
18
22
|
end
|
19
23
|
|
20
|
-
def html_options
|
21
|
-
@config
|
22
|
-
end
|
23
24
|
end
|
24
25
|
end
|
25
26
|
end
|
@@ -5,7 +5,6 @@ module ExpressTemplates
|
|
5
5
|
end
|
6
6
|
end
|
7
7
|
|
8
|
-
require 'express_templates/components/forms/form_support'
|
9
8
|
require 'express_templates/components/forms/express_form'
|
10
9
|
require 'express_templates/components/forms/form_component'
|
11
10
|
require 'express_templates/components/forms/option_support'
|
@@ -11,8 +11,8 @@ module ExpressTemplates
|
|
11
11
|
# Example:
|
12
12
|
#
|
13
13
|
# ```ruby
|
14
|
-
# tree_for(:roles) {
|
15
|
-
#
|
14
|
+
# tree_for(:roles) { |role|
|
15
|
+
# role.name
|
16
16
|
# }
|
17
17
|
# ```
|
18
18
|
#
|
@@ -36,51 +36,35 @@ module ExpressTemplates
|
|
36
36
|
# </li>
|
37
37
|
# </ul>
|
38
38
|
#
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
end +
|
53
|
-
"#{wsnl}</li>"
|
54
|
-
else
|
55
|
-
"</li>"
|
56
|
-
end
|
57
|
-
end
|
58
|
-
}).source.sub(/\W_yield\W/, compile_children.lstrip)
|
39
|
+
|
40
|
+
class TreeFor < Configurable
|
41
|
+
emits -> (customize_block) {
|
42
|
+
@customize_block = customize_block
|
43
|
+
ul(id: config[:id], class: "#{config[:id]} tree") {
|
44
|
+
list_items(eval(config[:id].to_s))
|
45
|
+
}
|
46
|
+
}
|
47
|
+
|
48
|
+
def list_items(nodes)
|
49
|
+
nodes.each do |node|
|
50
|
+
list_item(node)
|
51
|
+
end
|
59
52
|
end
|
60
53
|
|
61
|
-
def
|
62
|
-
|
63
|
-
|
54
|
+
def list_item(node)
|
55
|
+
li {
|
56
|
+
if @customize_block
|
57
|
+
@customize_block.call(node)
|
64
58
|
else
|
65
|
-
|
59
|
+
text_node "#{node.name}#{"\n" if node.children.any?}"
|
66
60
|
end
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
node_renderer.call('+member+', node_renderer)
|
74
|
-
end.join +
|
75
|
-
"#{wsnl}</ul>\n"
|
76
|
-
end
|
77
|
-
}'
|
61
|
+
if node.children.any?
|
62
|
+
ul {
|
63
|
+
list_items(node.children)
|
64
|
+
}
|
65
|
+
end
|
66
|
+
}
|
78
67
|
end
|
79
|
-
|
80
|
-
private
|
81
|
-
def _variablize(sym)
|
82
|
-
"@#{sym}"
|
83
|
-
end
|
84
68
|
end
|
85
69
|
end
|
86
70
|
end
|
@@ -3,16 +3,8 @@ module ExpressTemplates
|
|
3
3
|
end
|
4
4
|
end
|
5
5
|
|
6
|
-
require 'express_templates/expander'
|
7
6
|
require 'express_templates/components/base'
|
8
|
-
require 'express_templates/components/
|
9
|
-
require 'express_templates/components/null_wrap'
|
10
|
-
require 'express_templates/components/for_each'
|
11
|
-
require 'express_templates/components/unless_block'
|
12
|
-
require 'express_templates/components/row'
|
13
|
-
require 'express_templates/components/column'
|
7
|
+
require 'express_templates/components/configurable'
|
14
8
|
require 'express_templates/components/form_rails_support'
|
15
|
-
require 'express_templates/components/content_for'
|
16
|
-
require 'express_templates/components/table_for'
|
17
9
|
require 'express_templates/components/tree_for'
|
18
10
|
require 'express_templates/components/forms'
|
data/lib/express_templates.rb
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
module ExpressTemplates
|
2
|
+
require 'arbre'
|
3
|
+
require 'arbre/patches'
|
2
4
|
require 'core_extensions/proc'
|
3
5
|
require 'core_extensions/string'
|
4
6
|
require 'express_templates/indenter'
|
5
|
-
require 'express_templates/macro'
|
6
|
-
require 'express_templates/markup'
|
7
7
|
require 'express_templates/components'
|
8
8
|
require 'express_templates/template/handler'
|
9
9
|
require 'express_templates/renderer'
|
10
|
-
require 'express_templates/expander'
|
11
10
|
require 'express_templates/compiler'
|
12
11
|
require 'express_templates/interpolator'
|
13
12
|
extend Renderer
|
@@ -2,33 +2,36 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class BaseTest < ActiveSupport::TestCase
|
4
4
|
|
5
|
+
def assigns
|
6
|
+
{}
|
7
|
+
end
|
8
|
+
|
5
9
|
class NoLogic < ExpressTemplates::Components::Base
|
6
|
-
|
10
|
+
emits {
|
7
11
|
h1 { span "Some stuff" }
|
8
12
|
}
|
9
13
|
end
|
10
14
|
|
11
15
|
test ".has_markup makes compile return the block passed through express compiled" do
|
12
|
-
assert_equal
|
16
|
+
assert_equal "<h1>\n <span>Some stuff</span>\n</h1>\n", ExpressTemplates.render(self) { no_logic }
|
13
17
|
end
|
14
18
|
|
15
|
-
test "components register themselves as
|
16
|
-
assert
|
19
|
+
test "components register themselves as arbre builder methods" do
|
20
|
+
assert Arbre::Element::BuilderMethods.instance_methods.include?(:no_logic)
|
17
21
|
end
|
18
22
|
|
19
23
|
class Context
|
20
|
-
def
|
21
|
-
|
22
|
-
|
23
|
-
test "fragments and has_markup are synonyms for emits" do
|
24
|
-
assert_equal NoLogic.method(:emits), NoLogic.method(:fragments)
|
25
|
-
assert_equal NoLogic.method(:emits), NoLogic.method(:has_markup)
|
24
|
+
def assigns
|
25
|
+
{:foo => ['bar', 'baz']}
|
26
|
+
end
|
26
27
|
end
|
27
28
|
|
28
|
-
class
|
29
|
-
|
29
|
+
class HelperExample < ECB
|
30
|
+
def title_helper
|
31
|
+
foo.first
|
32
|
+
end
|
30
33
|
|
31
|
-
emits
|
34
|
+
emits {
|
32
35
|
h1 {
|
33
36
|
title_helper
|
34
37
|
}
|
@@ -37,8 +40,7 @@ class BaseTest < ActiveSupport::TestCase
|
|
37
40
|
end
|
38
41
|
|
39
42
|
test "helpers defined in component are evaluated in context" do
|
40
|
-
|
41
|
-
assert_equal "<h1>bar</h1>", Context.new.instance_eval(Interpolator.transform(compiled))
|
43
|
+
assert_equal "<h1>bar</h1>\n", ExpressTemplates.render(Context.new) { helper_example }
|
42
44
|
end
|
43
45
|
|
44
46
|
end
|
@@ -6,7 +6,7 @@ module AdminModule
|
|
6
6
|
class SmartThing
|
7
7
|
include ExpressTemplates::Components::Capabilities::Resourceful
|
8
8
|
|
9
|
-
attr_accessor :virtual_path
|
9
|
+
attr_accessor :virtual_path, :config
|
10
10
|
|
11
11
|
def initialize(virtual_path, config = {})
|
12
12
|
@virtual_path = virtual_path
|
@@ -14,8 +14,8 @@ module AdminModule
|
|
14
14
|
@args = [self]
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
18
|
-
|
17
|
+
def template_virtual_path
|
18
|
+
@virtual_path
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
@@ -4,40 +4,46 @@ class ConfigurableTest < ActiveSupport::TestCase
|
|
4
4
|
|
5
5
|
ETC = ExpressTemplates::Components
|
6
6
|
|
7
|
-
class ConfigurableComponent < ETC::
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
}
|
12
|
-
end
|
13
|
-
|
14
|
-
test "a configurable component accepts an id argument" do
|
15
|
-
assert :foo, ConfigurableComponent.new(:foo).my[:id]
|
7
|
+
class ConfigurableComponent < ETC::Configurable
|
8
|
+
def markup
|
9
|
+
div(id: my[:id], class: 'bar')
|
10
|
+
end
|
16
11
|
end
|
17
12
|
|
18
13
|
test "renders id argument as dom id" do
|
19
|
-
compiled_src =
|
20
|
-
|
14
|
+
compiled_src = ExpressTemplates.render(self) { configurable_component(:foo) }
|
15
|
+
assert_equal "<div id=\"foo\" class=\"bar\"></div>\n", compiled_src
|
21
16
|
end
|
22
17
|
|
23
|
-
class ConfigurableContainerComponent < ETC::
|
24
|
-
include ETC::Capabilities::Configurable
|
25
|
-
include ETC::Capabilities::Parenting
|
18
|
+
class ConfigurableContainerComponent < ETC::Configurable
|
26
19
|
|
27
20
|
# make sure a helper can take arguments
|
28
|
-
helper(:name) {|name| name.to_s }
|
21
|
+
# helper(:name) {|name| name.to_s }
|
22
|
+
def name(name)
|
23
|
+
name.to_s
|
24
|
+
end
|
29
25
|
|
30
|
-
|
31
|
-
div(my[:id]) {
|
26
|
+
def markup &block
|
27
|
+
div(id: my[:id]) {
|
32
28
|
h1 { name(my[:id]) }
|
33
|
-
|
29
|
+
yield(block) if block
|
34
30
|
}
|
35
|
-
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def assigns
|
35
|
+
{}
|
36
36
|
end
|
37
37
|
|
38
38
|
test "a configurable component may have also be a container" do
|
39
|
-
html = ExpressTemplates.render { configurable_container_component(:foo) {
|
40
|
-
|
39
|
+
html = ExpressTemplates.render(self) { configurable_container_component(:foo) { |c| para 'bar'} }
|
40
|
+
expected = <<-HTML
|
41
|
+
<div id=\"foo\">
|
42
|
+
<h1>foo</h1>
|
43
|
+
<p>bar</p>
|
44
|
+
</div>
|
45
|
+
HTML
|
46
|
+
assert_equal "<div id=\"foo\">\n <h1>foo</h1>\n <p>bar</p>\n</div>\n", html
|
41
47
|
end
|
42
48
|
|
43
49
|
end
|
@@ -6,47 +6,87 @@ class BasicFieldsTest < ActiveSupport::TestCase
|
|
6
6
|
datetime_local number range
|
7
7
|
search telephone time url week)
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
9
|
+
def assigns
|
10
|
+
{resource: resource}
|
11
|
+
end
|
12
|
+
|
13
|
+
def field_type_map
|
14
|
+
Hash[BASIC_FIELDS.map {|f| [f, f]}].merge(
|
15
|
+
{'phone' => 'tel',
|
16
|
+
'telephone' => 'tel',
|
17
|
+
'datetime_local' => 'datetime-local' })
|
18
|
+
end
|
19
|
+
|
20
|
+
def label_html
|
21
|
+
'<label for="foo_bar">Bar</label>'
|
16
22
|
end
|
17
23
|
|
18
24
|
test "all fields work" do
|
19
25
|
BASIC_FIELDS.each do |type|
|
20
|
-
fragment = -> {
|
26
|
+
fragment = -> (ctx) {
|
21
27
|
express_form(:foo) {
|
22
28
|
send(type, :bar)
|
23
29
|
}
|
24
30
|
}
|
25
|
-
|
26
|
-
assert_match
|
31
|
+
html = arbre(&fragment)
|
32
|
+
assert_match label_html, html
|
33
|
+
assert_match(/input.*type="#{field_type_map[type]}"/, html)
|
34
|
+
# assert_match "#{type}_field(:foo, :bar, {})", arbre(&fragment)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
test "passing html options to fields work" do
|
39
|
+
options = {class: 'form-field'}
|
40
|
+
BASIC_FIELDS.each do |type|
|
41
|
+
html = arbre {
|
42
|
+
express_form(:foo) {
|
43
|
+
send(type, :bar, options)
|
44
|
+
}
|
45
|
+
}
|
46
|
+
assert_match label_html, html
|
47
|
+
assert_match /input.*type="#{field_type_map[type]}"/, html
|
48
|
+
assert_match /input.*class="form-field"/, html
|
27
49
|
end
|
28
50
|
end
|
29
51
|
|
30
52
|
test "textarea uses rails text_area helper" do
|
31
|
-
|
53
|
+
html = arbre {
|
32
54
|
express_form(:foo) {
|
33
55
|
textarea :bar
|
34
56
|
}
|
35
57
|
}
|
36
|
-
assert_match
|
37
|
-
assert_match "
|
58
|
+
assert_match label_html, html
|
59
|
+
assert_match /<textarea name="foo\[bar\]" id="foo_bar"><\/textarea>/, html.gsub("\n", '')
|
38
60
|
end
|
39
61
|
|
62
|
+
test "textarea passes additional html options to rails helper" do
|
63
|
+
html = arbre {
|
64
|
+
express_form(:foo) {
|
65
|
+
textarea :bar, rows: 5, class: 'tinymce form-field'
|
66
|
+
}
|
67
|
+
}
|
68
|
+
assert_match label_html, html
|
69
|
+
assert_match /<textarea rows="5" class="tinymce form-field" name="foo\[bar\]" id="foo_bar"><\/textarea>/, html.gsub("\n", '')
|
70
|
+
end
|
40
71
|
|
41
72
|
test "hidden uses rails hidden_tag helper" do
|
42
|
-
|
73
|
+
html = arbre {
|
43
74
|
express_form(:foo) {
|
44
75
|
hidden :bar
|
45
76
|
}
|
46
77
|
}
|
47
|
-
assert_no_match
|
48
|
-
assert_match
|
78
|
+
assert_no_match label_html, html
|
79
|
+
assert_match '<input type="hidden"', html
|
49
80
|
end
|
50
81
|
|
51
|
-
|
82
|
+
test "hidden field passes additional html options to rails helper" do
|
83
|
+
html = arbre {
|
84
|
+
express_form(:foo) {
|
85
|
+
hidden :bar, class: 'hidden form-field', value: 'ninja'
|
86
|
+
}
|
87
|
+
}
|
88
|
+
assert_no_match label_html, html
|
89
|
+
assert_match /<input class="hidden form-field" value="ninja" type="hidden" name="foo\[bar\]" id="foo_bar"/, html
|
90
|
+
end
|
52
91
|
|
92
|
+
end
|