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
|
@@ -1,17 +1,11 @@
|
|
|
1
1
|
module ExpressTemplates
|
|
2
2
|
module Components
|
|
3
3
|
module Forms
|
|
4
|
-
class FormComponent <
|
|
5
|
-
include Capabilities::Configurable
|
|
6
|
-
include Capabilities::Adoptable
|
|
7
|
-
|
|
8
|
-
def compile(*args)
|
|
9
|
-
raise "#{self.class} requires a parent ExpressForm" if parent.nil? or parent_form.nil?
|
|
10
|
-
super(*args)
|
|
11
|
-
end
|
|
4
|
+
class FormComponent < Configurable
|
|
12
5
|
|
|
13
6
|
# Lookup the resource_name from the parent ExpressForm.
|
|
14
7
|
def resource_name
|
|
8
|
+
raise "FormComponent must have a parent form" unless parent_form
|
|
15
9
|
parent_form.resource_name
|
|
16
10
|
end
|
|
17
11
|
|
|
@@ -30,13 +24,13 @@ module ExpressTemplates
|
|
|
30
24
|
|
|
31
25
|
# Return the text content for the label
|
|
32
26
|
def label_text
|
|
33
|
-
|
|
27
|
+
config[:label] || field_name.titleize
|
|
34
28
|
end
|
|
35
29
|
|
|
36
30
|
# Return the field_name as a string. This taken from the first argument
|
|
37
31
|
# to the component macro in the template or fragment.
|
|
38
32
|
def field_name
|
|
39
|
-
(
|
|
33
|
+
(config[:id] || (@args.first.is_a?(String) && @args.first)).to_s
|
|
40
34
|
end
|
|
41
35
|
|
|
42
36
|
# Return the field name attribute. Currently handles only simple attributes
|
|
@@ -46,7 +40,7 @@ module ExpressTemplates
|
|
|
46
40
|
end
|
|
47
41
|
|
|
48
42
|
def field_wrapper_class
|
|
49
|
-
|
|
43
|
+
config[:wrapper_class] || 'field-wrapper'
|
|
50
44
|
end
|
|
51
45
|
|
|
52
46
|
# Search the parent graph until we find an ExpressForm. Returns nil if none found.
|
|
@@ -58,6 +52,21 @@ module ExpressTemplates
|
|
|
58
52
|
return @my_form
|
|
59
53
|
end
|
|
60
54
|
|
|
55
|
+
def default_html_options
|
|
56
|
+
(config || {}).reject {|k,v| k.eql?(:id)}
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def html_options
|
|
60
|
+
default_html_options.merge(config[:html_options] || {})
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
protected
|
|
64
|
+
|
|
65
|
+
def _process_args!(args)
|
|
66
|
+
@args = args
|
|
67
|
+
super(args)
|
|
68
|
+
end
|
|
69
|
+
|
|
61
70
|
end
|
|
62
71
|
end
|
|
63
72
|
end
|
|
@@ -28,9 +28,9 @@ module ExpressTemplates
|
|
|
28
28
|
reflection = belongs_to_association || has_many_through_association
|
|
29
29
|
if reflection && !reflection.polymorphic?
|
|
30
30
|
if cols.detect {|column| column.name.eql?('name') }
|
|
31
|
-
|
|
31
|
+
reflection.klass.select(option_value_method.to_sym, option_name_method.to_sym).order(option_name_method.to_sym)
|
|
32
32
|
else
|
|
33
|
-
|
|
33
|
+
reflection.klass.all.sort_by(&option_name_method.to_sym)
|
|
34
34
|
end
|
|
35
35
|
end
|
|
36
36
|
end
|
|
@@ -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
|
data/vendor/gems/express_templates/lib/express_templates/components/forms/select_collection.rb
CHANGED
|
@@ -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
|
|
@@ -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
|
|
@@ -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
|