express_admin 1.2.1 → 1.3.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/app/assets/javascripts/express_admin.js +2 -0
- data/app/assets/javascripts/express_admin/admin.js +2 -0
- data/app/assets/stylesheets/express_admin.css +0 -5
- data/app/assets/stylesheets/express_admin/components/_definition.sass +8 -0
- data/app/assets/stylesheets/express_admin/components/_pane.sass +2 -2
- data/app/assets/stylesheets/express_admin/components/_sub_menu.sass +2 -2
- data/app/assets/stylesheets/express_admin/components/_widget_box.sass +4 -4
- data/app/assets/stylesheets/express_admin/globals/_foundation_overrides.sass +2 -1
- data/app/assets/stylesheets/express_admin/globals/_mixins.sass +0 -2
- data/app/assets/stylesheets/express_admin/plugins/_select2.sass +475 -68
- data/app/assets/stylesheets/express_admin/plugins/_tinymce.sass +2 -0
- data/app/assets/stylesheets/express_admin/screen.sass +6 -1
- data/app/assets/stylesheets/express_admin/sections/_header.sass +1 -0
- data/app/assets/stylesheets/express_admin/sections/_main_content.sass +6 -2
- data/app/assets/stylesheets/express_admin/sections/_main_region.sass +10 -7
- data/app/assets/stylesheets/express_admin/sections/_page_body.sass +6 -3
- data/app/assets/stylesheets/express_admin/sections/_page_sidebar.sass +6 -2
- data/app/assets/stylesheets/express_admin/sections/_sidebar_region.sass +4 -3
- data/app/assets/stylesheets/express_admin/shared/_buttons.sass +0 -1
- data/app/assets/stylesheets/express_admin/shared/_forms.sass +14 -2
- data/app/assets/stylesheets/express_admin/shared/_trees.sass +7 -3
- data/app/assets/stylesheets/ionicons/{ionicons.css.sass → ionicons.sass} +0 -0
- data/app/components/express_admin/addon_sidebar_component.rb +23 -34
- data/app/components/express_admin/definition_list.rb +38 -0
- data/app/components/express_admin/definition_table.rb +51 -0
- data/app/components/express_admin/flash_message_component.rb +5 -11
- data/app/components/express_admin/layout_component.rb +2 -9
- data/app/components/express_admin/main_region.rb +4 -4
- data/app/components/express_admin/mega_menu_component.rb +40 -34
- data/app/components/express_admin/page_header_component.rb +8 -18
- data/app/components/express_admin/pane.rb +13 -10
- data/app/components/express_admin/setting_form.rb +23 -20
- data/app/components/express_admin/sidebar_region.rb +6 -4
- data/app/components/express_admin/smart_form.rb +21 -18
- data/app/components/express_admin/smart_table.rb +44 -40
- data/app/components/express_admin/widget_box.rb +8 -8
- data/app/helpers/express_admin/admin_helper.rb +1 -1
- data/app/views/devise/sessions/new.html.et +63 -0
- data/app/views/layouts/express_admin/admin.html.et +8 -9
- data/app/views/shared/express_admin/_navigation_bar.html.et +6 -5
- data/config/tinymce.yml +29 -0
- data/lib/core_extensions/string_promptify.rb +9 -0
- data/lib/express_admin.rb +1 -0
- data/lib/express_admin/engine.rb +11 -9
- data/lib/express_admin/version.rb +1 -1
- data/lib/generators/express_admin/install/install_generator.rb +7 -0
- data/lib/generators/express_admin/install/templates/views/devise/sessions/new.html.et +1 -0
- data/test/dummy/app/views/demo/sign_in.html.et +6 -6
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/test.log +11361 -0
- data/test/dummy/test/components/smart_form_test.rb +57 -34
- data/test/dummy/test/components/smart_table_test.rb +35 -35
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/1EoyfDwFVtgMAOjo7HPkor8TQbVaioOFx9hildx_DTQ.cache +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/4OPIkynisipUm8vKo57HUhBMWFSHBno_IH6OdpK29IA.cache +1 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/4hK1AdPGHbXGkebvk-nSvhxtCdOSlMYNWvA43CvQKhI.cache +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/6c0H20s6oHf45XogeDELaojxa0PX1NmirTTWV1ClcRw.cache +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/9QvwPXfTSVmgQX6tdK9GuCn0--MZ8Z8eJJbHpUEq1p8.cache +1 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/BoKdGhgi5NHfGTc42p9nltpEIYj_BBUxVdv7YhpBmmA.cache +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/GJGMlSyTg1AvPCV_6PaLOTVEKbHeVKY1jhCoaKuRlxM.cache +1 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/H0aD5KRj-4fhORkqWcWZfKPOQfu_ggvt4OmYOl4S5mw.cache +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/IBLgVNsKBbJxN8NQnh6zTc3bC_OG-8BhtA3xCNDV6ks.cache +1 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/Po8q4NrWy9Kymnz_HbOk-WbdGY_KuuXc6urGogTHe7U.cache +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/V1aP9G-CVtOLR5PTnHleid8WC9TSfFAT1DzAygp_5CQ.cache +1 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/WhePtBvZPmF1Jhdcc4glsjhxBJQo9Qw0CDgy_F8lClY.cache +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/dVokuKbK8HbOtvPIksKGBAYE8x44l372dQ0gEISqbdo.cache +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/oN1zSGeSEz4KhkAuUF_yFDsCVPkulfFjomEAjFzGdPc.cache +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/qIeSoker4TjM7JYRQTOjgRd4nN0WeHnNY1GMK7Zpe8M.cache +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/tTFLM1bjKSeg4nyH7GWbTY6JVvuYhNKFFvsOMS9h8O0.cache +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/tzX-HHF4F70o-aSB9Z_duoPxFGDv3auYnrpko9SYafU.cache +1 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/vMbWbI1SO5bEaiu2pRvV8NDmms_j5flYoRvCSJavhdU.cache +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/ypZCDLo54Pz2ZoUxrxSEUjT5FYMAq8Ozp8OTOYDRdAE.cache +0 -0
- data/test/fixtures/categories.yml +8 -0
- data/test/test_helper.rb +34 -0
- data/vendor/gems/express_templates/CHANGELOG.md +12 -0
- data/vendor/gems/express_templates/Gemfile.lock +4 -1
- data/vendor/gems/express_templates/README.md +22 -41
- data/vendor/gems/express_templates/express_templates.gemspec +1 -0
- data/vendor/gems/express_templates/lib/arbre/patches.rb +50 -0
- data/vendor/gems/express_templates/lib/core_extensions/proc.rb +1 -0
- data/vendor/gems/express_templates/lib/express_templates.rb +2 -3
- data/vendor/gems/express_templates/lib/express_templates/compiler.rb +2 -7
- data/vendor/gems/express_templates/lib/express_templates/components.rb +1 -9
- data/vendor/gems/express_templates/lib/express_templates/components/base.rb +33 -37
- data/vendor/gems/express_templates/lib/express_templates/components/capabilities/resourceful.rb +30 -18
- data/vendor/gems/express_templates/lib/express_templates/components/configurable.rb +41 -0
- data/vendor/gems/express_templates/lib/express_templates/components/form_rails_support.rb +5 -6
- data/vendor/gems/express_templates/lib/express_templates/components/forms.rb +0 -1
- data/vendor/gems/express_templates/lib/express_templates/components/forms/basic_fields.rb +3 -6
- data/vendor/gems/express_templates/lib/express_templates/components/forms/checkbox.rb +1 -1
- data/vendor/gems/express_templates/lib/express_templates/components/forms/express_form.rb +15 -25
- data/vendor/gems/express_templates/lib/express_templates/components/forms/form_component.rb +20 -11
- data/vendor/gems/express_templates/lib/express_templates/components/forms/option_support.rb +2 -2
- data/vendor/gems/express_templates/lib/express_templates/components/forms/radio.rb +7 -8
- data/vendor/gems/express_templates/lib/express_templates/components/forms/select.rb +61 -37
- data/vendor/gems/express_templates/lib/express_templates/components/forms/select_collection.rb +2 -8
- data/vendor/gems/express_templates/lib/express_templates/components/forms/submit.rb +7 -6
- data/vendor/gems/express_templates/lib/express_templates/components/tree_for.rb +26 -42
- data/vendor/gems/express_templates/lib/express_templates/version.rb +1 -1
- data/vendor/gems/express_templates/test/components/base_test.rb +17 -15
- data/vendor/gems/express_templates/test/components/capabilities/resourceful_test.rb +3 -3
- data/vendor/gems/express_templates/test/components/configurable_test.rb +27 -21
- data/vendor/gems/express_templates/test/components/forms/basic_fields_test.rb +57 -17
- data/vendor/gems/express_templates/test/components/forms/checkbox_test.rb +16 -22
- data/vendor/gems/express_templates/test/components/forms/express_form_test.rb +23 -76
- data/vendor/gems/express_templates/test/components/forms/radio_test.rb +31 -27
- data/vendor/gems/express_templates/test/components/forms/select_test.rb +46 -71
- data/vendor/gems/express_templates/test/components/forms/submit_test.rb +10 -5
- data/vendor/gems/express_templates/test/components/tree_for_test.rb +24 -52
- data/vendor/gems/express_templates/test/dummy/app/views/hello/show.html.et +4 -3
- data/vendor/gems/express_templates/test/dummy/app/views/layouts/application.html.et +1 -1
- data/vendor/gems/express_templates/test/dummy/log/test.log +4296 -0
- data/vendor/gems/express_templates/test/express_templates_test.rb +5 -1
- data/vendor/gems/express_templates/test/handler_test.rb +19 -17
- data/vendor/gems/express_templates/test/performance_test.rb +11 -7
- data/vendor/gems/express_templates/test/test_helper.rb +162 -1
- metadata +58 -47
- data/app/assets/stylesheets/express_admin/components/_megadropdown.sass +0 -66
- data/vendor/gems/express_templates/diagrams/diagram.graffle +0 -2404
- data/vendor/gems/express_templates/diagrams/diagram_express_templates.png +0 -0
- data/vendor/gems/express_templates/diagrams/diagram_haml_erb.png +0 -0
- data/vendor/gems/express_templates/lib/express_templates/components/capabilities/adoptable.rb +0 -20
- data/vendor/gems/express_templates/lib/express_templates/components/capabilities/building.rb +0 -14
- data/vendor/gems/express_templates/lib/express_templates/components/capabilities/conditionality.rb +0 -54
- data/vendor/gems/express_templates/lib/express_templates/components/capabilities/configurable.rb +0 -90
- data/vendor/gems/express_templates/lib/express_templates/components/capabilities/iterating.rb +0 -75
- data/vendor/gems/express_templates/lib/express_templates/components/capabilities/parenting.rb +0 -72
- data/vendor/gems/express_templates/lib/express_templates/components/capabilities/rendering.rb +0 -30
- data/vendor/gems/express_templates/lib/express_templates/components/capabilities/templating.rb +0 -198
- data/vendor/gems/express_templates/lib/express_templates/components/capabilities/wrapping.rb +0 -84
- data/vendor/gems/express_templates/lib/express_templates/components/column.rb +0 -13
- data/vendor/gems/express_templates/lib/express_templates/components/container.rb +0 -7
- data/vendor/gems/express_templates/lib/express_templates/components/content_for.rb +0 -42
- data/vendor/gems/express_templates/lib/express_templates/components/for_each.rb +0 -30
- data/vendor/gems/express_templates/lib/express_templates/components/forms/form_support.rb +0 -13
- data/vendor/gems/express_templates/lib/express_templates/components/null_wrap.rb +0 -41
- data/vendor/gems/express_templates/lib/express_templates/components/row.rb +0 -28
- data/vendor/gems/express_templates/lib/express_templates/components/table_for.rb +0 -163
- data/vendor/gems/express_templates/lib/express_templates/components/unless_block.rb +0 -40
- data/vendor/gems/express_templates/lib/express_templates/expander.rb +0 -140
- data/vendor/gems/express_templates/lib/express_templates/macro.rb +0 -45
- data/vendor/gems/express_templates/lib/express_templates/markup.rb +0 -9
- data/vendor/gems/express_templates/lib/express_templates/markup/html_tag.rb +0 -62
- data/vendor/gems/express_templates/lib/express_templates/markup/tag.rb +0 -150
- data/vendor/gems/express_templates/lib/express_templates/markup/wrapper.rb +0 -94
- data/vendor/gems/express_templates/lib/express_templates/markup/yielder.rb +0 -21
- data/vendor/gems/express_templates/test/components/column_test.rb +0 -11
- data/vendor/gems/express_templates/test/components/conditionality_test.rb +0 -37
- data/vendor/gems/express_templates/test/components/container_test.rb +0 -66
- data/vendor/gems/express_templates/test/components/content_for_test.rb +0 -60
- data/vendor/gems/express_templates/test/components/iterating_test.rb +0 -127
- data/vendor/gems/express_templates/test/components/null_wrap_test.rb +0 -28
- data/vendor/gems/express_templates/test/components/row_test.rb +0 -16
- data/vendor/gems/express_templates/test/components/table_for_test.rb +0 -211
- data/vendor/gems/express_templates/test/expander_stack_test.rb +0 -41
- data/vendor/gems/express_templates/test/expander_test.rb +0 -99
- data/vendor/gems/express_templates/test/markup/tag_test.rb +0 -149
- data/vendor/gems/express_templates/test/markup/wrapper_test.rb +0 -42
- data/vendor/gems/express_templates/test/markup/yielder_test.rb +0 -9
|
@@ -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
|
|
@@ -1,43 +1,37 @@
|
|
|
1
1
|
require 'test_helper'
|
|
2
2
|
|
|
3
3
|
class CheckboxTest < ActiveSupport::TestCase
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
fragment = -> {
|
|
7
|
-
checkbox :permission_granted
|
|
8
|
-
}
|
|
9
|
-
assert_raises(RuntimeError) {
|
|
10
|
-
ExpressTemplates.compile(&fragment)
|
|
11
|
-
}
|
|
4
|
+
def assigns
|
|
5
|
+
{resource: resource}
|
|
12
6
|
end
|
|
13
7
|
|
|
14
8
|
test "checkbox places the label before the input" do
|
|
15
|
-
|
|
9
|
+
html = arbre {
|
|
16
10
|
express_form(:account) {
|
|
17
11
|
checkbox :eula
|
|
18
12
|
}
|
|
19
13
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
assert_match
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
field_idx = compiled.index(field_helper)
|
|
14
|
+
label = '<label for="account_eula"'
|
|
15
|
+
field = 'input type="checkbox" value="1" name="account\[eula\]"'
|
|
16
|
+
assert_match /#{label}/, html
|
|
17
|
+
assert_match /#{field}/, html
|
|
18
|
+
label_idx = html.index(label)
|
|
19
|
+
field_idx = html.index(field.gsub('\\', ''))
|
|
27
20
|
assert (field_idx > label_idx), "label must come first"
|
|
28
21
|
end
|
|
29
22
|
|
|
30
23
|
test "checkbox respects label_after: true " do
|
|
31
|
-
|
|
24
|
+
html = arbre {
|
|
32
25
|
express_form(:account) {
|
|
33
26
|
checkbox :eula, label_after: true
|
|
34
27
|
}
|
|
35
28
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
29
|
+
label = '<label for="account_eula"'
|
|
30
|
+
field = 'input type="checkbox" value="1" name="account\[eula\]"'
|
|
31
|
+
assert_match /#{label}/, html
|
|
32
|
+
assert_match /#{field}/, html
|
|
33
|
+
label_idx = html.index(label)
|
|
34
|
+
field_idx = html.index(field.gsub('\\', ''))
|
|
41
35
|
assert (field_idx < label_idx), "label must come after when label_after: true"
|
|
42
36
|
end
|
|
43
37
|
|
|
@@ -1,108 +1,55 @@
|
|
|
1
1
|
require 'test_helper'
|
|
2
2
|
require 'ostruct'
|
|
3
3
|
|
|
4
|
-
class
|
|
5
|
-
|
|
6
|
-
def initialize(resource)
|
|
7
|
-
@resource = resource
|
|
8
|
-
end
|
|
4
|
+
class Foo
|
|
5
|
+
def self.columns ; [] ; end
|
|
9
6
|
end
|
|
10
7
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
)
|
|
8
|
+
class ExpressFormTest < ActiveSupport::TestCase
|
|
9
|
+
|
|
10
|
+
def assigns
|
|
11
|
+
{resource: resource}
|
|
23
12
|
end
|
|
24
13
|
|
|
25
|
-
def simplest_form
|
|
26
|
-
|
|
27
|
-
fragment = -> {
|
|
14
|
+
def simplest_form
|
|
15
|
+
arbre {
|
|
28
16
|
express_form(:resource) {
|
|
29
17
|
submit value: 'Save it!'
|
|
30
18
|
}
|
|
31
19
|
}
|
|
32
|
-
return ctx, fragment
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def express_form
|
|
36
|
-
"ExpressTemplates::Components::Forms::ExpressForm".constantize
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
test "express_form component exists" do
|
|
40
|
-
assert express_form
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def compile_simplest_form
|
|
44
|
-
ctx, fragment = simplest_form(resource)
|
|
45
|
-
ExpressTemplates.compile(&fragment)
|
|
46
20
|
end
|
|
47
21
|
|
|
48
22
|
test "simplest form renders" do
|
|
49
|
-
assert
|
|
23
|
+
assert simplest_form
|
|
50
24
|
end
|
|
51
25
|
|
|
52
26
|
test "simplest form contains form tag" do
|
|
53
|
-
assert_match "<form",
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
test "simplest form contains rails form helpers" do
|
|
57
|
-
compiled_src = compile_simplest_form
|
|
58
|
-
assert_match "utf8_enforcer_tag", compiled_src
|
|
59
|
-
assert_match "method_tag(", compiled_src
|
|
60
|
-
assert_match "token_tag", compiled_src
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
test "simplest_form contains submit" do
|
|
64
|
-
assert_match 'submit_tag', compile_simplest_form
|
|
27
|
+
assert_match "<form", simplest_form
|
|
65
28
|
end
|
|
66
29
|
|
|
67
|
-
test "
|
|
68
|
-
|
|
69
|
-
expanded_nodes = ExpressTemplates::Expander.new(nil).expand(fragment.source_body)
|
|
70
|
-
assert_instance_of ExpressTemplates::Components::Forms::ExpressForm,
|
|
71
|
-
expanded_nodes.first.children.last.parent
|
|
30
|
+
test "express_form contents are inside the form" do
|
|
31
|
+
assert_match /<form.*submit.*\/form>/, simplest_form.gsub("\n",'')
|
|
72
32
|
end
|
|
73
33
|
|
|
74
|
-
test "
|
|
75
|
-
|
|
34
|
+
test "simplest form contains rails form helpers" do
|
|
35
|
+
compiled_src = simplest_form
|
|
36
|
+
assert_match "input name=\"utf8\" type=\"hidden\"", compiled_src
|
|
37
|
+
assert_match "input type=\"hidden\" name=\"_method\"", compiled_src
|
|
38
|
+
assert_match "name=\"authenticity_token\" value=\"AUTH_TOKEN\"", compiled_src
|
|
39
|
+
assert_match /<form.*authenticity_token.*\/form>/, compiled_src.gsub("\n",'')
|
|
76
40
|
end
|
|
77
41
|
|
|
78
|
-
test "
|
|
79
|
-
|
|
42
|
+
test "simplest_form contains submit" do
|
|
43
|
+
assert_match '<input type="submit" name="commit" value="Save" />', simplest_form
|
|
80
44
|
end
|
|
81
45
|
|
|
82
46
|
test "simplest_form uses form_action for the action" do
|
|
83
|
-
form_open_tag =
|
|
84
|
-
assert_match 'action
|
|
47
|
+
form_open_tag = simplest_form.match(/<form[^>]*>/)[0]
|
|
48
|
+
assert_match 'action="/resources"', form_open_tag
|
|
85
49
|
end
|
|
86
50
|
|
|
87
51
|
test "express_form default method is POST" do
|
|
88
|
-
|
|
89
|
-
assert_match 'method=\"POST\"', form_open_tag
|
|
52
|
+
assert_match 'method="POST"', simplest_form
|
|
90
53
|
end
|
|
91
54
|
|
|
92
|
-
test "express_form accepts :resource_name for removing namespace" do
|
|
93
|
-
fragment = -> {
|
|
94
|
-
express_form(:admin_foo, resource_name: 'foo') {
|
|
95
|
-
submit "Save!"
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
expanded_nodes = ExpressTemplates::Expander.new(nil).expand(fragment.source_body)
|
|
99
|
-
assert_equal 'foo', expanded_nodes.first.resource_name
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
# test "express_form has a namespace option with nil default" do
|
|
103
|
-
# form = ExpressTemplates::Components::Forms::ExpressForm
|
|
104
|
-
# assert_nil form.new(:person).namespace
|
|
105
|
-
# assert_equal 'express_engine', form.new(:person, namespace: 'express_engine').namespace
|
|
106
|
-
# end
|
|
107
|
-
|
|
108
55
|
end
|
|
@@ -2,17 +2,20 @@ require 'test_helper'
|
|
|
2
2
|
|
|
3
3
|
class RadioTest < ActiveSupport::TestCase
|
|
4
4
|
|
|
5
|
+
def assigns
|
|
6
|
+
{resource: resource}
|
|
7
|
+
end
|
|
8
|
+
|
|
5
9
|
test "radio requires a parent component" do
|
|
6
|
-
fragment = -> {
|
|
7
|
-
radio :preferred_email_format, ['HTML', 'Text']
|
|
8
|
-
}
|
|
9
10
|
assert_raises(RuntimeError) {
|
|
10
|
-
|
|
11
|
+
html = arbre {
|
|
12
|
+
radio :preferred_email_format, ['HTML', 'Text']
|
|
13
|
+
}
|
|
11
14
|
}
|
|
12
15
|
end
|
|
13
16
|
|
|
14
17
|
def radio_with_array_options
|
|
15
|
-
|
|
18
|
+
html = arbre {
|
|
16
19
|
express_form(:person) {
|
|
17
20
|
radio :preferred_email_format, ['HTML', 'Text']
|
|
18
21
|
}
|
|
@@ -20,18 +23,17 @@ class RadioTest < ActiveSupport::TestCase
|
|
|
20
23
|
end
|
|
21
24
|
|
|
22
25
|
test "radio has correct label field name and text" do
|
|
23
|
-
assert_match
|
|
24
|
-
|
|
26
|
+
assert_match /<label for="person_preferred_email_format"/,
|
|
27
|
+
radio_with_array_options
|
|
25
28
|
end
|
|
26
29
|
|
|
27
30
|
test "radio options present with class 'radio'" do
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
assert_match '_format, "HTML", class: "radio"', compiled
|
|
31
|
+
assert_match /<input.*class="radio"/,
|
|
32
|
+
radio_with_array_options
|
|
31
33
|
end
|
|
32
34
|
|
|
33
35
|
def radio_with_hash_options
|
|
34
|
-
|
|
36
|
+
html = arbre {
|
|
35
37
|
express_form(:person) {
|
|
36
38
|
radio :subscribed, {1 => 'Yes', 0 => 'No'}, wrapper_class: 'my-wrapper'
|
|
37
39
|
}
|
|
@@ -39,34 +41,36 @@ class RadioTest < ActiveSupport::TestCase
|
|
|
39
41
|
end
|
|
40
42
|
|
|
41
43
|
test "radio options may be specified with a hash" do
|
|
42
|
-
compiled =
|
|
43
|
-
assert_match '<label class
|
|
44
|
-
assert_match '
|
|
45
|
-
assert_match '
|
|
44
|
+
compiled = radio_with_hash_options
|
|
45
|
+
assert_match '<label class="my-wrapper">', compiled
|
|
46
|
+
assert_match 'input class="radio" type="radio" value="0" name="person[subscribed]" id="person_subscribed_0" />No', compiled
|
|
47
|
+
assert_match 'input class="radio" type="radio" value="1" name="person[subscribed]" id="person_subscribed_1" />Yes', compiled
|
|
46
48
|
end
|
|
47
49
|
|
|
48
50
|
test "radio throws error if given improper options" do
|
|
49
|
-
fragment = -> {
|
|
50
|
-
express_form(:person) {
|
|
51
|
-
radio :subscribed, "Garbage options"
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
51
|
assert_raises(RuntimeError) {
|
|
55
|
-
|
|
52
|
+
html = arbre {
|
|
53
|
+
express_form(:person) {
|
|
54
|
+
radio :subscribed, "Garbage options"
|
|
55
|
+
}
|
|
56
|
+
}
|
|
56
57
|
}
|
|
57
58
|
end
|
|
58
59
|
|
|
59
60
|
def radio_with_options_omitted
|
|
60
|
-
|
|
61
|
+
html = arbre {
|
|
61
62
|
express_form(:employee) {
|
|
62
63
|
radio :department_id
|
|
63
64
|
}
|
|
64
65
|
}
|
|
65
66
|
end
|
|
66
67
|
|
|
67
|
-
class ::Department
|
|
68
|
-
def self.
|
|
69
|
-
|
|
68
|
+
class ::Department < ::Gender
|
|
69
|
+
def self.order(*)
|
|
70
|
+
all
|
|
71
|
+
end
|
|
72
|
+
def self.all
|
|
73
|
+
return [new(1, 'Accounting'), new(2, 'Marketing')]
|
|
70
74
|
end
|
|
71
75
|
end
|
|
72
76
|
class ::Employee
|
|
@@ -84,8 +88,8 @@ class RadioTest < ActiveSupport::TestCase
|
|
|
84
88
|
end
|
|
85
89
|
|
|
86
90
|
test "radio options from collection when options omitted" do
|
|
87
|
-
assert_match
|
|
88
|
-
|
|
91
|
+
assert_match /input type="radio" value="1" name="employee\[department_id\]" id="employee_department_id_1"/,
|
|
92
|
+
radio_with_options_omitted
|
|
89
93
|
end
|
|
90
94
|
|
|
91
95
|
# test "radio supports html options"
|