express_admin 1.2.1 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
data/vendor/gems/express_templates/lib/express_templates/components/capabilities/wrapping.rb
DELETED
@@ -1,84 +0,0 @@
|
|
1
|
-
module ExpressTemplates
|
2
|
-
module Components
|
3
|
-
module Capabilities
|
4
|
-
|
5
|
-
# Add the ability for a component template to wrap or decorate a fragment
|
6
|
-
# with another fragment.
|
7
|
-
#
|
8
|
-
# The insertion point for the inner fragment is marked with <tt>_yield</tt>
|
9
|
-
#
|
10
|
-
# Example:
|
11
|
-
#
|
12
|
-
# class MenuComponent < ExpressTemplates::Components::Base
|
13
|
-
#
|
14
|
-
# fragments :menu_item, -> { li { menu_link(item) } },
|
15
|
-
# :menu_wrapper, -> { ul { _yield } }
|
16
|
-
#
|
17
|
-
# for_each -> { menu_items }
|
18
|
-
#
|
19
|
-
# wrap_with :menu_wrapper
|
20
|
-
#
|
21
|
-
# end
|
22
|
-
#
|
23
|
-
# Note this example also uses Capabilities::Iterating.
|
24
|
-
#
|
25
|
-
# Provides:
|
26
|
-
#
|
27
|
-
# * Wrapping::ClassMethods
|
28
|
-
#
|
29
|
-
module Wrapping
|
30
|
-
def self.included(base)
|
31
|
-
base.class_eval do
|
32
|
-
extend ClassMethods
|
33
|
-
include InstanceMethods
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
module InstanceMethods
|
38
|
-
def compile
|
39
|
-
lookup :markup
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
module ClassMethods
|
44
|
-
|
45
|
-
# Enclose whatever the component would already generate
|
46
|
-
# inside the specified fragment wherever we encounter _yield
|
47
|
-
def wrap_with(fragment, dont_wrap_if: false )
|
48
|
-
wrapper_name(fragment)
|
49
|
-
wrapper_src = _lookup(fragment).source
|
50
|
-
inner_src = _lookup(:markup).source_body
|
51
|
-
wrapped_src = wrapper_src.gsub!(/\W_yield\W/, inner_src)
|
52
|
-
|
53
|
-
fragment_src = if dont_wrap_if
|
54
|
-
%Q(-> {
|
55
|
-
unless_block(Proc.from_source(#{dont_wrap_if.source.inspect}), alt: Proc.from_source(%q(-> {#{inner_src}}))) {
|
56
|
-
#{Proc.from_source(wrapped_src).source_body}
|
57
|
-
}
|
58
|
-
})
|
59
|
-
else
|
60
|
-
wrapped_src
|
61
|
-
end
|
62
|
-
|
63
|
-
_store :markup, Proc.from_source(fragment_src)
|
64
|
-
|
65
|
-
end
|
66
|
-
|
67
|
-
def wrapper_name(name = nil)
|
68
|
-
if name.nil?
|
69
|
-
@wrapper_name || :markup
|
70
|
-
else
|
71
|
-
@wrapper_name = name
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
def _yield(*args)
|
76
|
-
"{{_yield}}"
|
77
|
-
end
|
78
|
-
|
79
|
-
end
|
80
|
-
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
module ExpressTemplates
|
2
|
-
module Components
|
3
|
-
# Provide a wrapper for the content_for helper which
|
4
|
-
# accepts a block of express template code.
|
5
|
-
#
|
6
|
-
# Example:
|
7
|
-
#
|
8
|
-
# ```ruby
|
9
|
-
# content_for(:header) {
|
10
|
-
# h1 "Title"
|
11
|
-
# }
|
12
|
-
# ```
|
13
|
-
# Or:
|
14
|
-
# ```ruby
|
15
|
-
# content_for(:page_title), "People"
|
16
|
-
# ```
|
17
|
-
class ContentFor < Container
|
18
|
-
include Capabilities::Configurable
|
19
|
-
def compile
|
20
|
-
children_markup = compile_children
|
21
|
-
content_label = @args[0]
|
22
|
-
result = %Q|\ncontent_for(:#{content_label}|
|
23
|
-
if children_markup.empty?
|
24
|
-
if @args[1].kind_of?(String)
|
25
|
-
children_markup = @args[1]
|
26
|
-
# append children as argument
|
27
|
-
result << %Q|, "#{children_markup}".html_safe).to_s|
|
28
|
-
else
|
29
|
-
# no markup specified - must be referencing the content
|
30
|
-
result << ").to_s"
|
31
|
-
end
|
32
|
-
else
|
33
|
-
# append children in block form
|
34
|
-
result << %Q|) {
|
35
|
-
(#{children_markup.gsub(/^\s+/, '')}).html_safe
|
36
|
-
}.to_s|
|
37
|
-
end
|
38
|
-
result
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
module ExpressTemplates
|
2
|
-
module Components
|
3
|
-
class ForEach < Components::Container
|
4
|
-
attr :collection, :member
|
5
|
-
|
6
|
-
def initialize(*args)
|
7
|
-
iterator = args.shift
|
8
|
-
options = args.first.kind_of?(Hash) ? args.shift : {}
|
9
|
-
expander = args.shift
|
10
|
-
@collection, @member = nil, (options[:as]||"item")
|
11
|
-
if iterator.kind_of?(Symbol)
|
12
|
-
@collection = iterator.to_s
|
13
|
-
@member = collection.sub(/^@/, '').singularize
|
14
|
-
elsif iterator.kind_of?(Proc)
|
15
|
-
@collection = "(#{iterator.source}.call)"
|
16
|
-
elsif iterator.kind_of?(String)
|
17
|
-
@collection = "(#{iterator}.call)"
|
18
|
-
else
|
19
|
-
raise "ForEach unknown iterator: #{iterator}"
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
|
24
|
-
def compile
|
25
|
-
%Q((#{@collection}.each_with_index.map do |#{@member}, #{@member}_index|#{compile_children}\nend).join)
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
module ExpressTemplates
|
2
|
-
module Components
|
3
|
-
# NullWrap is useful for creating a node in the component tree that does
|
4
|
-
# not produce any markup. It can be used in a template fragment to
|
5
|
-
# wrap bare text or string content where such would not normally be possible.
|
6
|
-
#
|
7
|
-
# Example:
|
8
|
-
#
|
9
|
-
# ```ruby
|
10
|
-
# div {
|
11
|
-
# some_component
|
12
|
-
# null_wrap {
|
13
|
-
# "Some text"
|
14
|
-
# }
|
15
|
-
# other_component
|
16
|
-
# }
|
17
|
-
# ```
|
18
|
-
#
|
19
|
-
# Otherwise you can use it to hold already-complied code meant for
|
20
|
-
# evaluation in the view that needs to be protected from being compiled
|
21
|
-
# again. This use is largely internal to express_templates. It is not
|
22
|
-
# expected that users of this library would need this.
|
23
|
-
#
|
24
|
-
# Example:
|
25
|
-
#
|
26
|
-
# ```ruby
|
27
|
-
# null_wrap("(@collection.map do |member| \"<li>#{member.name}</li>\").join")
|
28
|
-
# ```
|
29
|
-
#
|
30
|
-
class NullWrap < Components::Container
|
31
|
-
def initialize(*args)
|
32
|
-
@already_compiled_stuff = args.shift if args.first.is_a?(String)
|
33
|
-
super(*args)
|
34
|
-
end
|
35
|
-
|
36
|
-
def compile
|
37
|
-
@already_compiled_stuff || compile_children
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
module ExpressTemplates
|
2
|
-
module Components
|
3
|
-
# A Row is a Container implemented as a div with
|
4
|
-
# a CSS class "row"
|
5
|
-
#
|
6
|
-
# An optional dom ID may be specified as a symbol.
|
7
|
-
#
|
8
|
-
# Example:
|
9
|
-
#
|
10
|
-
# row(:main) {
|
11
|
-
# p "Some content"
|
12
|
-
# }
|
13
|
-
#
|
14
|
-
# This will render as:
|
15
|
-
#
|
16
|
-
# <div id="main" class="row"><p>Some content</p></div>
|
17
|
-
#
|
18
|
-
class Row < Container
|
19
|
-
include Capabilities::Configurable
|
20
|
-
|
21
|
-
emits -> {
|
22
|
-
div.row(my[:id]) {
|
23
|
-
_yield
|
24
|
-
}
|
25
|
-
}
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,163 +0,0 @@
|
|
1
|
-
module ExpressTemplates
|
2
|
-
module Components
|
3
|
-
# Create an html table from a collection of data.
|
4
|
-
#
|
5
|
-
# Typically this will be a collection of models
|
6
|
-
# of the same type. Each member of the collection must
|
7
|
-
# respond to the column names provided.
|
8
|
-
#
|
9
|
-
# Example:
|
10
|
-
#
|
11
|
-
# ````ruby
|
12
|
-
# table_for(:people) do |t|
|
13
|
-
# t.column :name
|
14
|
-
# t.column :email
|
15
|
-
# t.column :phone
|
16
|
-
# t.column :hourly_rate, header: "Rate",
|
17
|
-
# formatter: -> (amount) {'$%0.2f' % amount rescue 'N/A'}
|
18
|
-
# end
|
19
|
-
# ````
|
20
|
-
#
|
21
|
-
# This assumes that a @people variable will exist in the
|
22
|
-
# view and that it will be a collection whose members respond to
|
23
|
-
# :name, :email, :phone, :hourly_rate
|
24
|
-
#
|
25
|
-
# This will result in markup like the following:
|
26
|
-
#
|
27
|
-
# <table id="people">
|
28
|
-
# <thead>
|
29
|
-
# <tr>
|
30
|
-
# <th class="name">Name</th>
|
31
|
-
# <th class="email">Email</th>
|
32
|
-
# <th class="phone">Phone</th>
|
33
|
-
# <th class="hourly_rate">Rate</th>
|
34
|
-
# </tr>
|
35
|
-
# </thead>
|
36
|
-
# <tbody>
|
37
|
-
# <tr id="person-1">
|
38
|
-
# <td class="name">Steven Talcott Smith</td>
|
39
|
-
# <td class="email">steve@aelogica.com</td>
|
40
|
-
# <td class="phone">415-555-1212</td>
|
41
|
-
# <td class="hourly_rate">$250.00</td>
|
42
|
-
# </tr>
|
43
|
-
# </tbody>
|
44
|
-
# </table>
|
45
|
-
#
|
46
|
-
# Note that column options include :formatter and :header.
|
47
|
-
#
|
48
|
-
# :formatter may be a stabby lambda which is passed the value to be formatted.
|
49
|
-
#
|
50
|
-
# :header may be either a string
|
51
|
-
#
|
52
|
-
class TableFor < Base
|
53
|
-
include Capabilities::Configurable
|
54
|
-
include Capabilities::Building
|
55
|
-
|
56
|
-
def initialize(*args)
|
57
|
-
super(*args)
|
58
|
-
_process_args!(args) # from Configurable
|
59
|
-
yield(self) if block_given?
|
60
|
-
end
|
61
|
-
|
62
|
-
attr :columns
|
63
|
-
|
64
|
-
def column(name, options = {})
|
65
|
-
@columns ||= []
|
66
|
-
@columns << Column.new(name, options)
|
67
|
-
end
|
68
|
-
|
69
|
-
emits -> {
|
70
|
-
table(my[:id]) {
|
71
|
-
thead {
|
72
|
-
tr {
|
73
|
-
columns.each do |column|
|
74
|
-
th.send(column.name) {
|
75
|
-
column.title
|
76
|
-
}
|
77
|
-
end
|
78
|
-
}
|
79
|
-
}
|
80
|
-
tbody {
|
81
|
-
for_each("@#{my[:id]}".to_sym) {
|
82
|
-
|
83
|
-
tr(id: "#{my[:id].to_s.singularize}-{{#{my[:id].to_s.singularize}.id}}",
|
84
|
-
class: my[:id].to_s.singularize) {
|
85
|
-
|
86
|
-
columns.each do |column|
|
87
|
-
if(column.has_actions?)
|
88
|
-
td(class: column.name) {
|
89
|
-
column.show_actions(my[:id].to_s)
|
90
|
-
}
|
91
|
-
else
|
92
|
-
td(class: column.name) {
|
93
|
-
column.format(my[:id].to_s.singularize)
|
94
|
-
}
|
95
|
-
end
|
96
|
-
end
|
97
|
-
}
|
98
|
-
}
|
99
|
-
}
|
100
|
-
}
|
101
|
-
}
|
102
|
-
|
103
|
-
def wrap_for_stack_trace(body)
|
104
|
-
"ExpressTemplates::Components::TableFor.render_in(self) {\n#{body}\n}"
|
105
|
-
end
|
106
|
-
|
107
|
-
def compile
|
108
|
-
wrap_for_stack_trace(lookup(:markup))
|
109
|
-
end
|
110
|
-
|
111
|
-
class Column
|
112
|
-
attr :name, :options
|
113
|
-
def initialize(name, options = {})
|
114
|
-
@name = name
|
115
|
-
@options = options
|
116
|
-
@formatter = options[:formatter]
|
117
|
-
@header = options[:header]
|
118
|
-
@actions = options[:actions] || []
|
119
|
-
end
|
120
|
-
|
121
|
-
def has_actions?
|
122
|
-
@actions.any?
|
123
|
-
end
|
124
|
-
|
125
|
-
def format(item_name)
|
126
|
-
if @formatter.nil?
|
127
|
-
"\#\{#{item_name}.#{name}\}"
|
128
|
-
elsif @formatter.kind_of?(Proc)
|
129
|
-
"\#\{(#{@formatter.source}).call(#{item_name}.#{name})\}"
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
def show_actions(item_name)
|
134
|
-
action_links = StringIO.new
|
135
|
-
@actions.each do |action|
|
136
|
-
action_name = action.to_s
|
137
|
-
if action_name.eql?('edit')
|
138
|
-
action_links.puts "<a href='/#{item_name}/{{#{item_name.singularize}.id}}/edit'>Edit</a>"
|
139
|
-
elsif action_name.eql?('delete')
|
140
|
-
action_links.puts "<a href='/#{item_name}/{{#{item_name.singularize}.id}}' data-method='delete' data-confirm='Are you sure?'>Delete</a>"
|
141
|
-
elsif action_name.eql?('show')
|
142
|
-
action_links.puts "<a href='/#{item_name}/{{#{item_name.singularize}.id}}'>Show</a>"
|
143
|
-
end
|
144
|
-
end
|
145
|
-
action_links.string
|
146
|
-
end
|
147
|
-
|
148
|
-
def title
|
149
|
-
case
|
150
|
-
when @header.nil?
|
151
|
-
@name.to_s.try(:titleize)
|
152
|
-
when @header.kind_of?(String)
|
153
|
-
@header
|
154
|
-
when @header.kind_of?(Proc)
|
155
|
-
"{{(#{@header.source}).call(#{@name})}}"
|
156
|
-
end
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
end
|
161
|
-
|
162
|
-
end
|
163
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
module ExpressTemplates
|
2
|
-
module Components
|
3
|
-
class UnlessBlock < Components::Container
|
4
|
-
|
5
|
-
attr :conditional
|
6
|
-
|
7
|
-
def initialize(*args)
|
8
|
-
@conditional = args.shift
|
9
|
-
@alt = args.shift[:alt] if args.first.kind_of?(Hash)
|
10
|
-
parent = args.shift
|
11
|
-
if @conditional.kind_of?(Symbol)
|
12
|
-
@conditional = @conditional.to_s
|
13
|
-
elsif @conditional.kind_of?(Proc)
|
14
|
-
@conditional = "(#{@conditional.source}.call)"
|
15
|
-
elsif iterator.kind_of?(String)
|
16
|
-
@conditional = "(#{@conditional}.call)"
|
17
|
-
else
|
18
|
-
raise "UnlessBlock unknown conditional: #{@conditional.inspect}"
|
19
|
-
end
|
20
|
-
|
21
|
-
if @alt.kind_of?(Proc)
|
22
|
-
@alt = _compile_fragment @alt
|
23
|
-
elsif @alt.nil?
|
24
|
-
@alt = "''"
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def compile
|
29
|
-
s = unless @alt
|
30
|
-
%Q((unless #{@conditional}#{compile_children}\nend))
|
31
|
-
else
|
32
|
-
%Q((unless #{@conditional}#{compile_children}\nelse #{@alt}\nend))
|
33
|
-
end
|
34
|
-
puts s if ENV['DEBUG'].eql?('true')
|
35
|
-
s
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|