express_templates 0.7.1 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/express_templates/compiler.rb +0 -9
- data/lib/express_templates/components/base.rb +62 -10
- data/lib/express_templates/components/capabilities/resourceful.rb +12 -0
- data/lib/express_templates/components/configurable.rb +143 -16
- data/lib/express_templates/components/forms/basic_fields.rb +11 -16
- data/lib/express_templates/components/forms/checkbox.rb +6 -6
- data/lib/express_templates/components/forms/express_form.rb +18 -26
- data/lib/express_templates/components/forms/form_component.rb +17 -16
- data/lib/express_templates/components/forms/radio.rb +14 -32
- data/lib/express_templates/components/forms/select.rb +18 -35
- data/lib/express_templates/components/forms/select_collection.rb +11 -17
- data/lib/express_templates/components/forms/submit.rb +18 -14
- data/lib/express_templates/components/tree_for.rb +11 -4
- data/lib/express_templates/components.rb +0 -1
- data/lib/express_templates/renderer.rb +1 -3
- data/lib/express_templates/version.rb +1 -1
- data/test/components/base_test.rb +45 -24
- data/test/components/capabilities/resourceful_test.rb +1 -1
- data/test/components/configurable_test.rb +108 -30
- data/test/components/forms/basic_fields_test.rb +3 -3
- data/test/components/forms/express_form_test.rb +4 -1
- data/test/components/forms/radio_test.rb +3 -3
- data/test/components/forms/submit_test.rb +3 -3
- data/test/components/tree_for_test.rb +1 -1
- data/test/core_extensions/proc_test.rb +10 -0
- data/test/test_helper.rb +3 -0
- metadata +2 -69
- data/lib/express_templates/components/form_rails_support.rb +0 -21
- data/test/dummy/log/test.log +0 -21858
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/-1ax0k6FO5drSUN6jbogg4G0JliUHLffvQUvzSePKxA.cache +0 -1
- 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/28LzLLDYjhr3jmu0GxjZ-ms5Bol6JilDRXpg8Zgbjqs.cache +0 -1
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/2zt1IbQCnmzGyeZS_I4sYQzrgneSCKIJBRxcffVHlWY.cache +0 -1
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/5AeGDyXQbv_BTj3PD4MJpNnGVwUxLsA8H1VcwB69_wE.cache +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/B0RgtiEmqwrCQuw4AnDa3fdENtJeBtO_TqtGJuWOeNs.cache +0 -3
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/D-tMNp19G2zWOPPhnQRUm4K8DPa8SpKPfGALkkofTeE.cache +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/EDVlXrcn_wEfaZ5nc_4QJBT7lPiIBcX96jBo7PBz-vc.cache +0 -1
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/Eso3tkb79hXQ1XdQgjbV03KyQwSeZFAHxVHImsjQ-HQ.cache +0 -2
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/I8LhheC1OlOyvp_qY8kWpqKcZFiqv_BO-l5bExvDEi0.cache +0 -1
- 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/Pd5YOD1DAL7QtTnwETZYBCabg5DkCFgbjt4iuBOcSoY.cache +0 -1
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/QJ0Z8hROMfWpY6f5Chb7GSuDHE4gpabKVQTr9BCZe9s.cache +0 -1
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/T1pSAx767vY7X1UDN0vdF7YGEkI5wMSVUKopsdvp7kI.cache +0 -1
- 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/bSfZQxeyghTF4WIVnzGavxlg9afmSNuqcW6bA1Bm1OA.cache +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/fvD_ZNFRzd8Sc4PoTjyHPnkg4f7WMietFunnKqNjlvc.cache +0 -2
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/g2xQygPqA5kMmp5L3wVGWaUIhdVsxFmOel9FF6M0Fuw.cache +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/hKbgrf5CbMO8pe9fCHc-rI5mp1ejAhivBfvfDxBNhQA.cache +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/kaif59owjUr3HBharCH5GUxU6KoW_zXD9a9JiTjIYPY.cache +0 -1
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/kpvKX5UlhhoLJv-faeq7Ibv2KQh4ROjTiarh13gHuWI.cache +0 -2
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/lfyrNtbNtwuTXAWlmPCKTS-D3FHoPTY6h53wnUN36-A.cache +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/lyDRhWNhfDw_YCCSbxQw_iOIV3eTfeAoX6mTREuVZSA.cache +0 -3
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/p17lC0HAHCtk1ds_NHl9xhEyMtRjfQInw1c6fmFWguc.cache +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/p1cwnBd8RQBm9x5HzDmiiU7RhvnxhPX8VTfi0tTElJY.cache +0 -3
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/qT6_0ti_v6fAjS3wETXqvTkr6W0LP4PB942uLYQzWK8.cache +0 -3
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/qzU7DVwQZ7z6i6pYUpssYsAj0y33GN83B4O1bLvkW_4.cache +0 -1
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/r56eI1z7iFKeySym_9zw5hVOPjb0d6IQPn5pAYTKk04.cache +0 -2
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/rGWvoeLyiyqb813IXgfDpDxks23JQoLLZOa69bzKPE8.cache +0 -1
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/y8T65xpx0s3RgT_YiqWEEXIaBsgK4woCNSuZ1zjQZBk.cache +0 -2
@@ -2,13 +2,11 @@ module ExpressTemplates
|
|
2
2
|
module Components
|
3
3
|
module Forms
|
4
4
|
# Provides a form Select component based on the Rails *select_tag* helper.
|
5
|
-
# Parameters:
|
6
|
-
# field_name, select_options, helper_options
|
7
5
|
#
|
8
|
-
#
|
6
|
+
# The :options may be specified as an Array or Hash which will be
|
9
7
|
# supplied to the *options_for_select* helper.
|
10
8
|
#
|
11
|
-
# If the
|
9
|
+
# If the :options are omitted, the component attempts to check
|
12
10
|
# whether the field is an association. If an association exists,
|
13
11
|
# the options will be generated using *options_from_collection_for_select*
|
14
12
|
# with the assumption that :id and :name are the value and name fields
|
@@ -18,24 +16,26 @@ module ExpressTemplates
|
|
18
16
|
class Select < FormComponent
|
19
17
|
include OptionSupport
|
20
18
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
19
|
+
has_option :options, 'Select options. Can be Array, Hash, or Proc.'
|
20
|
+
has_option :selected, 'The currently selected value; Used when options are supplied. Otherwise the value is taken from the resource.'
|
21
|
+
has_option :include_blank, 'Whether or not to include a blank option.', default: true
|
22
|
+
has_option :select2, 'Use select2 enhanced select box.', default: true
|
23
|
+
|
24
|
+
contains -> {
|
25
|
+
label_tag(label_name, label_text)
|
26
|
+
select_tag(*select_tag_args)
|
26
27
|
}
|
27
28
|
|
28
29
|
def select_tag_args
|
29
|
-
|
30
|
-
args
|
30
|
+
[field_name_attribute, select_options, select_helper_options]
|
31
31
|
end
|
32
32
|
|
33
33
|
def select_options_supplied?
|
34
|
-
[Array, Hash, Proc].include?(
|
34
|
+
[Array, Hash, Proc].include?(config[:options].class)
|
35
35
|
end
|
36
36
|
|
37
37
|
def use_supplied_options
|
38
|
-
opts =
|
38
|
+
opts = config[:options]
|
39
39
|
if opts.respond_to?(:call) # can be a proc
|
40
40
|
opts.call(resource)
|
41
41
|
else
|
@@ -55,7 +55,7 @@ module ExpressTemplates
|
|
55
55
|
end
|
56
56
|
|
57
57
|
def selected_value
|
58
|
-
|
58
|
+
config[:selected]||resource.send(field_name)
|
59
59
|
end
|
60
60
|
|
61
61
|
def options_from_supplied_or_field_values
|
@@ -104,33 +104,16 @@ module ExpressTemplates
|
|
104
104
|
end
|
105
105
|
end
|
106
106
|
|
107
|
-
def field_options
|
108
|
-
# If field_otions is omitted the Expander will be
|
109
|
-
# in last or 3rd position and we don't want that
|
110
|
-
defaults = {include_blank: true}
|
111
|
-
defaults.merge(supplied_component_options)
|
112
|
-
end
|
113
|
-
|
114
107
|
def select_helper_options
|
115
|
-
|
116
|
-
add_select2_class( field_options.reject {|k,v| component_option_names.include?(k)})
|
108
|
+
add_select2_class( input_attributes.merge(include_blank: !!config[:include_blank]) )
|
117
109
|
end
|
118
110
|
|
119
111
|
protected
|
120
112
|
|
121
113
|
def add_select2_class(helper_options)
|
122
|
-
|
123
|
-
|
124
|
-
helper_options
|
125
|
-
helper_options
|
126
|
-
end
|
127
|
-
|
128
|
-
def supplied_component_options
|
129
|
-
if @args.last && @args.last.is_a?(Hash)
|
130
|
-
@args.last
|
131
|
-
else
|
132
|
-
{}
|
133
|
-
end
|
114
|
+
classes = (helper_options[:class]||'').split(' ')
|
115
|
+
classes << 'select2' if config[:select2] === true
|
116
|
+
helper_options.merge(:class => classes.join(' '))
|
134
117
|
end
|
135
118
|
|
136
119
|
end
|
@@ -1,24 +1,18 @@
|
|
1
1
|
module ExpressTemplates
|
2
2
|
module Components
|
3
3
|
module Forms
|
4
|
-
# Provides a form Select component based on the Rails *
|
5
|
-
# Parameters:
|
6
|
-
# field_name, select_options, helper_options
|
7
|
-
#
|
8
|
-
# Select options may be specified as an Array or Hash which will be
|
9
|
-
# supplied to the *options_for_select* helper.
|
10
|
-
#
|
4
|
+
# Provides a form Select component based on the Rails *collection_select* helper.
|
11
5
|
class SelectCollection < Select
|
12
6
|
|
13
|
-
|
14
|
-
div(class: field_wrapper_class) {
|
15
|
-
label_tag(label_name, label_text)
|
7
|
+
has_option :multiple, "Allow multiple selections.", default: true
|
16
8
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
9
|
+
contains -> {
|
10
|
+
label_tag(label_name, label_text)
|
11
|
+
|
12
|
+
# need this because the collection_select helper does not provide
|
13
|
+
# the hidden_field_tag trick (see rails api docs for select)
|
14
|
+
hidden_field_tag(multi_field_name, '')
|
15
|
+
collection_select(*collection_select_tag_args)
|
22
16
|
}
|
23
17
|
|
24
18
|
def collection_select_tag_args
|
@@ -30,11 +24,11 @@ module ExpressTemplates
|
|
30
24
|
end
|
31
25
|
|
32
26
|
def field_options
|
33
|
-
|
27
|
+
{include_blank: !!input_attributes.delete(:include_blank)}
|
34
28
|
end
|
35
29
|
|
36
30
|
def html_options
|
37
|
-
(
|
31
|
+
input_attributes.reject {|k,v| k.eql?(:include_blank)}.merge(multiple: config[:multiple])
|
38
32
|
end
|
39
33
|
|
40
34
|
def multi_field_name
|
@@ -3,22 +3,26 @@ module ExpressTemplates
|
|
3
3
|
module Forms
|
4
4
|
class Submit < FormComponent
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
submit_tag(args.first || 'Save', (args[1]||{}))
|
10
|
-
else
|
11
|
-
submit_tag 'Save', (args.first || {})
|
12
|
-
end
|
13
|
-
}
|
14
|
-
end
|
6
|
+
has_option :button_class, 'The css class of the input button.'
|
7
|
+
has_option :value, 'The value of the submit tag. Text show in button.',
|
8
|
+
default: 'Save'
|
15
9
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
10
|
+
contains -> {
|
11
|
+
submit_tag(value, input_attributes)
|
12
|
+
}
|
13
|
+
|
14
|
+
before_build -> {
|
15
|
+
# if we are not part of a form, we don't get a default id
|
16
|
+
begin
|
17
|
+
super()
|
18
|
+
rescue
|
19
|
+
add_class(config[:class])
|
20
|
+
remove_class('submit')
|
21
21
|
end
|
22
|
+
}
|
23
|
+
|
24
|
+
def value
|
25
|
+
config[:value]
|
22
26
|
end
|
23
27
|
|
24
28
|
end
|
@@ -38,11 +38,18 @@ module ExpressTemplates
|
|
38
38
|
#
|
39
39
|
|
40
40
|
class TreeFor < Configurable
|
41
|
-
|
41
|
+
|
42
|
+
tag :ul
|
43
|
+
|
44
|
+
has_attributes :class => 'tree'
|
45
|
+
|
46
|
+
contains -> (&customize_block) {
|
42
47
|
@customize_block = customize_block
|
43
|
-
|
44
|
-
|
45
|
-
|
48
|
+
list_items(eval(config[:id].to_s))
|
49
|
+
}
|
50
|
+
|
51
|
+
before_build -> {
|
52
|
+
add_class config[:id]
|
46
53
|
}
|
47
54
|
|
48
55
|
def list_items(nodes)
|
@@ -1,8 +1,6 @@
|
|
1
1
|
module ExpressTemplates
|
2
2
|
module Renderer
|
3
|
-
# render accepts source or block,
|
4
|
-
# compiles the resulting macros
|
5
|
-
# and then evaluates the resulting string of ruby in the context provided
|
3
|
+
# render accepts source or block, evaluates the resulting string of ruby in the context provided
|
6
4
|
def render context=nil, template_or_src=nil, &block
|
7
5
|
compiled_template = compile(template_or_src, &block)
|
8
6
|
context.instance_eval compiled_template
|
@@ -2,45 +2,66 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class BaseTest < ActiveSupport::TestCase
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
class Context
|
6
|
+
def assigns
|
7
|
+
{}
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def render(&block)
|
12
|
+
ExpressTemplates.render(Context.new, &block)
|
7
13
|
end
|
8
14
|
|
9
|
-
class
|
10
|
-
|
11
|
-
|
15
|
+
class UnorderedList < ExpressTemplates::Components::Base
|
16
|
+
tag :ul
|
17
|
+
|
18
|
+
has_attributes :class => 'something',
|
19
|
+
'data-foo' => 'something-else'
|
20
|
+
|
21
|
+
contains {
|
22
|
+
li { "Some stuff" }
|
12
23
|
}
|
13
24
|
end
|
14
25
|
|
15
|
-
test ".
|
16
|
-
|
26
|
+
test ".tag_name determines the enclosing tag" do
|
27
|
+
assert_match /^\<ul/, render { unordered_list }
|
17
28
|
end
|
18
29
|
|
19
|
-
test "
|
20
|
-
|
30
|
+
test ".has_attributes creates default attributes" do
|
31
|
+
assert_match /class="[^"]*something[^"]*"/, render { unordered_list }
|
32
|
+
assert_match /data-foo="[^"]*something-else[^"]*"/, render { unordered_list }
|
21
33
|
end
|
22
34
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
35
|
+
test ".contains places fragment inside the enclosing tag" do
|
36
|
+
markup = render { unordered_list }
|
37
|
+
assert_match /\<ul.*\<li.*\/li\>.*\/ul\>/, markup.gsub("\n", '')
|
27
38
|
end
|
28
39
|
|
29
|
-
class
|
30
|
-
|
31
|
-
|
32
|
-
end
|
40
|
+
test "class name is dasherized instead of underscored" do
|
41
|
+
assert_match /class="[^"]*unordered-list[^"]*"/, render { unordered_list }
|
42
|
+
end
|
33
43
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
}
|
38
|
-
}
|
44
|
+
test "options are passed to html attributes" do
|
45
|
+
assert_match /rows="5"/, render { unordered_list(rows: 5) }
|
46
|
+
end
|
39
47
|
|
48
|
+
test "class option adds a class, does not override" do
|
49
|
+
markup = render { unordered_list(class: 'extra') }
|
50
|
+
assert_match /class="[^"]*something[^"]*"/, markup
|
51
|
+
assert_match /class="[^"]*unordered-list[^"]*"/, markup
|
52
|
+
assert_match /class="[^"]*extra[^"]*"/, markup
|
53
|
+
end
|
54
|
+
|
55
|
+
class BeforeBuildHook < ExpressTemplates::Components::Base
|
56
|
+
before_build :add_my_foo
|
57
|
+
|
58
|
+
def add_my_foo
|
59
|
+
set_attribute('data-foo', 'bar')
|
60
|
+
end
|
40
61
|
end
|
41
62
|
|
42
|
-
test "
|
43
|
-
|
63
|
+
test "before_build hook runs before build" do
|
64
|
+
assert_match /data-foo="bar"/, render { before_build_hook }
|
44
65
|
end
|
45
66
|
|
46
67
|
end
|
@@ -2,48 +2,126 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class ConfigurableTest < ActiveSupport::TestCase
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
def markup
|
9
|
-
div(id: my[:id], class: 'bar')
|
5
|
+
class Context
|
6
|
+
def assigns
|
7
|
+
{}
|
10
8
|
end
|
11
9
|
end
|
12
10
|
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
def render(&block)
|
12
|
+
ExpressTemplates.render(Context.new, &block)
|
13
|
+
end
|
14
|
+
|
15
|
+
ETCC = ExpressTemplates::Components::Configurable
|
16
|
+
|
17
|
+
class ConfigurableComponent < ETCC
|
18
|
+
end
|
19
|
+
|
20
|
+
test "renders first argument as dom id" do
|
21
|
+
assert_match /id="foo"/, render { configurable_component(:foo) }
|
16
22
|
end
|
17
23
|
|
18
|
-
|
24
|
+
test "has no id attribute if not specified" do
|
25
|
+
assert_no_match /id="foo"/, render { configurable_component }
|
26
|
+
end
|
19
27
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
28
|
+
class ConfigWithOption < ETCC
|
29
|
+
has_option :thing, 'Something about things'
|
30
|
+
end
|
31
|
+
|
32
|
+
test "supports option declaration" do
|
33
|
+
markup = render { config_with_option }
|
34
|
+
assert_equal %Q(<div class="config-with-option"></div>\n), markup
|
35
|
+
end
|
36
|
+
|
37
|
+
test "does not pass declared options as html attributes" do
|
38
|
+
markup = render { config_with_option(thing: 'whatever') }
|
39
|
+
assert_equal %Q(<div class="config-with-option"></div>\n), markup
|
40
|
+
end
|
41
|
+
|
42
|
+
test "unrecognized options raises an exception" do
|
43
|
+
assert_raises(ArgumentError) do
|
44
|
+
class ConfigWithUnrecognizedOptions < ETCC
|
45
|
+
has_option :title, 'asdfasdf', something_unrecognized: 'whatever'
|
46
|
+
end
|
24
47
|
end
|
48
|
+
end
|
25
49
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
50
|
+
class ConfigWithDefaultOption < ETCC
|
51
|
+
has_option :rows, 'Number of rows', type: :integer, default: 5, attribute: true
|
52
|
+
end
|
53
|
+
|
54
|
+
test "default values are supported" do
|
55
|
+
markup = render { config_with_default_option }
|
56
|
+
assert_equal %Q(<div class="config-with-default-option" rows="5"></div>\n), markup
|
57
|
+
end
|
58
|
+
|
59
|
+
test "default values for attributes can be overridden" do
|
60
|
+
markup = render { config_with_default_option(rows: 999) }
|
61
|
+
assert_equal %Q(<div class="config-with-default-option" rows="999"></div>\n), markup
|
62
|
+
end
|
63
|
+
|
64
|
+
class ConfigWithRequiredOptions < ETCC
|
65
|
+
has_option :title, 'adds a title', required: true
|
66
|
+
end
|
67
|
+
|
68
|
+
test "required options are required" do
|
69
|
+
assert_raises(RuntimeError) do
|
70
|
+
render { config_with_required_options }
|
31
71
|
end
|
72
|
+
assert render { config_with_required_options(title: 'foo') }
|
73
|
+
end
|
74
|
+
|
75
|
+
class ConfigSubclass < ConfigWithRequiredOptions
|
76
|
+
has_option :status, 'something'
|
77
|
+
end
|
78
|
+
|
79
|
+
test "options are inherited" do
|
80
|
+
assert_equal [:title, :status], ConfigSubclass.supported_options.keys
|
81
|
+
end
|
82
|
+
|
83
|
+
class ConfigArgument < ETCC
|
84
|
+
has_argument :name, "The name.", type: :string
|
85
|
+
|
86
|
+
has_option :something, "else"
|
87
|
+
|
88
|
+
contains {
|
89
|
+
text_node config[:name]
|
90
|
+
}
|
32
91
|
end
|
33
92
|
|
34
|
-
|
35
|
-
|
93
|
+
test ".has_argument adds a positional configuration argument" do
|
94
|
+
assert_equal :name, ConfigArgument.new.supported_arguments.keys.last
|
95
|
+
assert_equal "The name.", ConfigArgument.new.supported_arguments.values.last[:description]
|
36
96
|
end
|
37
97
|
|
38
|
-
test "
|
39
|
-
html =
|
40
|
-
|
41
|
-
|
42
|
-
|
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
|
98
|
+
test ".has_argument makes builder arguments accessible by name according to position" do
|
99
|
+
html = render &-> {
|
100
|
+
config_argument :bar, 'Foo'
|
101
|
+
}
|
102
|
+
assert_match />Foo</, html
|
47
103
|
end
|
48
104
|
|
49
|
-
|
105
|
+
class ConfigAnotherArgument < ConfigArgument
|
106
|
+
has_argument :title, "comes after name", type: :string
|
107
|
+
end
|
108
|
+
|
109
|
+
test ".has_argument appends supported arguments in order of inheritence" do
|
110
|
+
assert_equal [:id, :name, :title], ConfigAnotherArgument.new.supported_arguments.keys
|
111
|
+
end
|
112
|
+
|
113
|
+
class ConfigOverwriteId < ConfigArgument
|
114
|
+
has_argument :id, 'Should overwrite :id',
|
115
|
+
as: :foo, type: :symbol
|
116
|
+
contains -> {
|
117
|
+
text_node config[:foo]
|
118
|
+
}
|
119
|
+
end
|
120
|
+
|
121
|
+
test ".has_argument as: allows overwrite of inherited argument" do
|
122
|
+
html = render {
|
123
|
+
config_overwrite_id(:whatever, 'Ignore me')
|
124
|
+
}
|
125
|
+
assert_match /div.*>whatever/, html
|
126
|
+
end
|
127
|
+
end
|
@@ -36,8 +36,8 @@ class BasicFieldsTest < ActiveSupport::TestCase
|
|
36
36
|
end
|
37
37
|
|
38
38
|
test "passing html options to fields work" do
|
39
|
-
options = {
|
40
|
-
|
39
|
+
options = {style: 'width: 10em;'}
|
40
|
+
['email'].each do |type|
|
41
41
|
html = arbre {
|
42
42
|
express_form(:foo) {
|
43
43
|
send(type, :bar, options)
|
@@ -45,7 +45,7 @@ class BasicFieldsTest < ActiveSupport::TestCase
|
|
45
45
|
}
|
46
46
|
assert_match label_html, html
|
47
47
|
assert_match /input.*type="#{field_type_map[type]}"/, html
|
48
|
-
assert_match /input.*
|
48
|
+
assert_match /input.*style="width: 10em;"/, html
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'test_helper'
|
2
|
-
require 'ostruct'
|
3
2
|
|
4
3
|
class Foo
|
5
4
|
def self.columns ; [] ; end
|
@@ -23,6 +22,10 @@ class ExpressFormTest < ActiveSupport::TestCase
|
|
23
22
|
assert simplest_form
|
24
23
|
end
|
25
24
|
|
25
|
+
test "simplest form will have the proper id" do
|
26
|
+
assert_match /<form.*id="resource_1"/, simplest_form
|
27
|
+
end
|
28
|
+
|
26
29
|
test "simplest form contains form tag" do
|
27
30
|
assert_match "<form", simplest_form
|
28
31
|
end
|
@@ -9,7 +9,7 @@ class RadioTest < ActiveSupport::TestCase
|
|
9
9
|
test "radio requires a parent component" do
|
10
10
|
assert_raises(RuntimeError) {
|
11
11
|
html = arbre {
|
12
|
-
radio :preferred_email_format, ['HTML', 'Text']
|
12
|
+
radio :preferred_email_format, options: ['HTML', 'Text']
|
13
13
|
}
|
14
14
|
}
|
15
15
|
end
|
@@ -17,7 +17,7 @@ class RadioTest < ActiveSupport::TestCase
|
|
17
17
|
def radio_with_array_options
|
18
18
|
html = arbre {
|
19
19
|
express_form(:person) {
|
20
|
-
radio :preferred_email_format, ['HTML', 'Text']
|
20
|
+
radio :preferred_email_format, options: ['HTML', 'Text']
|
21
21
|
}
|
22
22
|
}
|
23
23
|
end
|
@@ -35,7 +35,7 @@ class RadioTest < ActiveSupport::TestCase
|
|
35
35
|
def radio_with_hash_options
|
36
36
|
html = arbre {
|
37
37
|
express_form(:person) {
|
38
|
-
radio :subscribed, {1 => 'Yes', 0 => 'No'},
|
38
|
+
radio :subscribed, options: {1 => 'Yes', 0 => 'No'}, label_wrapper_class: 'my-wrapper'
|
39
39
|
}
|
40
40
|
}
|
41
41
|
end
|
@@ -9,7 +9,7 @@ end
|
|
9
9
|
class SubmitTest < ActiveSupport::TestCase
|
10
10
|
test "submit takes string param for value" do
|
11
11
|
fragment = -> (ctx) {
|
12
|
-
submit "Save it!"
|
12
|
+
submit value: "Save it!"
|
13
13
|
}
|
14
14
|
assert_match '<div class="field-wrapper"><input type="submit" name="commit" value="Save it!" /></div>',
|
15
15
|
arbre(&fragment)
|
@@ -21,9 +21,9 @@ class SubmitTest < ActiveSupport::TestCase
|
|
21
21
|
assert_match '<div class="field-wrapper"><input type="submit" name="commit" value="Save" class="button" /></div>',
|
22
22
|
arbre(&fragment)
|
23
23
|
end
|
24
|
-
test "submit accepts a class option
|
24
|
+
test "submit accepts a value and class option" do
|
25
25
|
fragment = -> (ctx) {
|
26
|
-
submit 'XYZ', class: 'button'
|
26
|
+
submit value: 'XYZ', class: 'button'
|
27
27
|
}
|
28
28
|
assert_match '<div class="field-wrapper"><input type="submit" name="commit" value="XYZ" class="button" /></div>',
|
29
29
|
arbre(&fragment)
|
@@ -68,4 +68,14 @@ class ProcTest < ActiveSupport::TestCase
|
|
68
68
|
assert_equal 'foo', Proc.from_source(src).call
|
69
69
|
end
|
70
70
|
|
71
|
+
test ".source_body captures full body when parens around parameters not provided" do
|
72
|
+
block = return_block { something(:one, "two") }
|
73
|
+
assert_equal 'something(:one, "two")', block.source_body
|
74
|
+
block = return_block -> { something :one, "two" }
|
75
|
+
assert_equal 'something :one, "two"', block.source_body
|
76
|
+
# TODO: Fix this
|
77
|
+
# block = return_block { something :one, "two" }
|
78
|
+
# assert_equal 'something :one, "two"', block.source_body
|
79
|
+
end
|
80
|
+
|
71
81
|
end
|