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.
Files changed (159) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/express_admin.js +2 -0
  3. data/app/assets/javascripts/express_admin/admin.js +2 -0
  4. data/app/assets/stylesheets/express_admin.css +0 -5
  5. data/app/assets/stylesheets/express_admin/components/_definition.sass +8 -0
  6. data/app/assets/stylesheets/express_admin/components/_pane.sass +2 -2
  7. data/app/assets/stylesheets/express_admin/components/_sub_menu.sass +2 -2
  8. data/app/assets/stylesheets/express_admin/components/_widget_box.sass +4 -4
  9. data/app/assets/stylesheets/express_admin/globals/_foundation_overrides.sass +2 -1
  10. data/app/assets/stylesheets/express_admin/globals/_mixins.sass +0 -2
  11. data/app/assets/stylesheets/express_admin/plugins/_select2.sass +475 -68
  12. data/app/assets/stylesheets/express_admin/plugins/_tinymce.sass +2 -0
  13. data/app/assets/stylesheets/express_admin/screen.sass +6 -1
  14. data/app/assets/stylesheets/express_admin/sections/_header.sass +1 -0
  15. data/app/assets/stylesheets/express_admin/sections/_main_content.sass +6 -2
  16. data/app/assets/stylesheets/express_admin/sections/_main_region.sass +10 -7
  17. data/app/assets/stylesheets/express_admin/sections/_page_body.sass +6 -3
  18. data/app/assets/stylesheets/express_admin/sections/_page_sidebar.sass +6 -2
  19. data/app/assets/stylesheets/express_admin/sections/_sidebar_region.sass +4 -3
  20. data/app/assets/stylesheets/express_admin/shared/_buttons.sass +0 -1
  21. data/app/assets/stylesheets/express_admin/shared/_forms.sass +14 -2
  22. data/app/assets/stylesheets/express_admin/shared/_trees.sass +7 -3
  23. data/app/assets/stylesheets/ionicons/{ionicons.css.sass → ionicons.sass} +0 -0
  24. data/app/components/express_admin/addon_sidebar_component.rb +23 -34
  25. data/app/components/express_admin/definition_list.rb +38 -0
  26. data/app/components/express_admin/definition_table.rb +51 -0
  27. data/app/components/express_admin/flash_message_component.rb +5 -11
  28. data/app/components/express_admin/layout_component.rb +2 -9
  29. data/app/components/express_admin/main_region.rb +4 -4
  30. data/app/components/express_admin/mega_menu_component.rb +40 -34
  31. data/app/components/express_admin/page_header_component.rb +8 -18
  32. data/app/components/express_admin/pane.rb +13 -10
  33. data/app/components/express_admin/setting_form.rb +23 -20
  34. data/app/components/express_admin/sidebar_region.rb +6 -4
  35. data/app/components/express_admin/smart_form.rb +21 -18
  36. data/app/components/express_admin/smart_table.rb +44 -40
  37. data/app/components/express_admin/widget_box.rb +8 -8
  38. data/app/helpers/express_admin/admin_helper.rb +1 -1
  39. data/app/views/devise/sessions/new.html.et +63 -0
  40. data/app/views/layouts/express_admin/admin.html.et +8 -9
  41. data/app/views/shared/express_admin/_navigation_bar.html.et +6 -5
  42. data/config/tinymce.yml +29 -0
  43. data/lib/core_extensions/string_promptify.rb +9 -0
  44. data/lib/express_admin.rb +1 -0
  45. data/lib/express_admin/engine.rb +11 -9
  46. data/lib/express_admin/version.rb +1 -1
  47. data/lib/generators/express_admin/install/install_generator.rb +7 -0
  48. data/lib/generators/express_admin/install/templates/views/devise/sessions/new.html.et +1 -0
  49. data/test/dummy/app/views/demo/sign_in.html.et +6 -6
  50. data/test/dummy/db/test.sqlite3 +0 -0
  51. data/test/dummy/log/test.log +11361 -0
  52. data/test/dummy/test/components/smart_form_test.rb +57 -34
  53. data/test/dummy/test/components/smart_table_test.rb +35 -35
  54. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/1EoyfDwFVtgMAOjo7HPkor8TQbVaioOFx9hildx_DTQ.cache +0 -0
  55. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/4OPIkynisipUm8vKo57HUhBMWFSHBno_IH6OdpK29IA.cache +1 -0
  56. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/4hK1AdPGHbXGkebvk-nSvhxtCdOSlMYNWvA43CvQKhI.cache +0 -0
  57. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/6c0H20s6oHf45XogeDELaojxa0PX1NmirTTWV1ClcRw.cache +0 -0
  58. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/9QvwPXfTSVmgQX6tdK9GuCn0--MZ8Z8eJJbHpUEq1p8.cache +1 -0
  59. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/BoKdGhgi5NHfGTc42p9nltpEIYj_BBUxVdv7YhpBmmA.cache +0 -0
  60. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/GJGMlSyTg1AvPCV_6PaLOTVEKbHeVKY1jhCoaKuRlxM.cache +1 -0
  61. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/H0aD5KRj-4fhORkqWcWZfKPOQfu_ggvt4OmYOl4S5mw.cache +0 -0
  62. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/IBLgVNsKBbJxN8NQnh6zTc3bC_OG-8BhtA3xCNDV6ks.cache +1 -0
  63. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/Po8q4NrWy9Kymnz_HbOk-WbdGY_KuuXc6urGogTHe7U.cache +0 -0
  64. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/V1aP9G-CVtOLR5PTnHleid8WC9TSfFAT1DzAygp_5CQ.cache +1 -0
  65. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/WhePtBvZPmF1Jhdcc4glsjhxBJQo9Qw0CDgy_F8lClY.cache +0 -0
  66. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/dVokuKbK8HbOtvPIksKGBAYE8x44l372dQ0gEISqbdo.cache +0 -0
  67. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/oN1zSGeSEz4KhkAuUF_yFDsCVPkulfFjomEAjFzGdPc.cache +0 -0
  68. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/qIeSoker4TjM7JYRQTOjgRd4nN0WeHnNY1GMK7Zpe8M.cache +0 -0
  69. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/tTFLM1bjKSeg4nyH7GWbTY6JVvuYhNKFFvsOMS9h8O0.cache +0 -0
  70. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/tzX-HHF4F70o-aSB9Z_duoPxFGDv3auYnrpko9SYafU.cache +1 -0
  71. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/vMbWbI1SO5bEaiu2pRvV8NDmms_j5flYoRvCSJavhdU.cache +0 -0
  72. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/ypZCDLo54Pz2ZoUxrxSEUjT5FYMAq8Ozp8OTOYDRdAE.cache +0 -0
  73. data/test/fixtures/categories.yml +8 -0
  74. data/test/test_helper.rb +34 -0
  75. data/vendor/gems/express_templates/CHANGELOG.md +12 -0
  76. data/vendor/gems/express_templates/Gemfile.lock +4 -1
  77. data/vendor/gems/express_templates/README.md +22 -41
  78. data/vendor/gems/express_templates/express_templates.gemspec +1 -0
  79. data/vendor/gems/express_templates/lib/arbre/patches.rb +50 -0
  80. data/vendor/gems/express_templates/lib/core_extensions/proc.rb +1 -0
  81. data/vendor/gems/express_templates/lib/express_templates.rb +2 -3
  82. data/vendor/gems/express_templates/lib/express_templates/compiler.rb +2 -7
  83. data/vendor/gems/express_templates/lib/express_templates/components.rb +1 -9
  84. data/vendor/gems/express_templates/lib/express_templates/components/base.rb +33 -37
  85. data/vendor/gems/express_templates/lib/express_templates/components/capabilities/resourceful.rb +30 -18
  86. data/vendor/gems/express_templates/lib/express_templates/components/configurable.rb +41 -0
  87. data/vendor/gems/express_templates/lib/express_templates/components/form_rails_support.rb +5 -6
  88. data/vendor/gems/express_templates/lib/express_templates/components/forms.rb +0 -1
  89. data/vendor/gems/express_templates/lib/express_templates/components/forms/basic_fields.rb +3 -6
  90. data/vendor/gems/express_templates/lib/express_templates/components/forms/checkbox.rb +1 -1
  91. data/vendor/gems/express_templates/lib/express_templates/components/forms/express_form.rb +15 -25
  92. data/vendor/gems/express_templates/lib/express_templates/components/forms/form_component.rb +20 -11
  93. data/vendor/gems/express_templates/lib/express_templates/components/forms/option_support.rb +2 -2
  94. data/vendor/gems/express_templates/lib/express_templates/components/forms/radio.rb +7 -8
  95. data/vendor/gems/express_templates/lib/express_templates/components/forms/select.rb +61 -37
  96. data/vendor/gems/express_templates/lib/express_templates/components/forms/select_collection.rb +2 -8
  97. data/vendor/gems/express_templates/lib/express_templates/components/forms/submit.rb +7 -6
  98. data/vendor/gems/express_templates/lib/express_templates/components/tree_for.rb +26 -42
  99. data/vendor/gems/express_templates/lib/express_templates/version.rb +1 -1
  100. data/vendor/gems/express_templates/test/components/base_test.rb +17 -15
  101. data/vendor/gems/express_templates/test/components/capabilities/resourceful_test.rb +3 -3
  102. data/vendor/gems/express_templates/test/components/configurable_test.rb +27 -21
  103. data/vendor/gems/express_templates/test/components/forms/basic_fields_test.rb +57 -17
  104. data/vendor/gems/express_templates/test/components/forms/checkbox_test.rb +16 -22
  105. data/vendor/gems/express_templates/test/components/forms/express_form_test.rb +23 -76
  106. data/vendor/gems/express_templates/test/components/forms/radio_test.rb +31 -27
  107. data/vendor/gems/express_templates/test/components/forms/select_test.rb +46 -71
  108. data/vendor/gems/express_templates/test/components/forms/submit_test.rb +10 -5
  109. data/vendor/gems/express_templates/test/components/tree_for_test.rb +24 -52
  110. data/vendor/gems/express_templates/test/dummy/app/views/hello/show.html.et +4 -3
  111. data/vendor/gems/express_templates/test/dummy/app/views/layouts/application.html.et +1 -1
  112. data/vendor/gems/express_templates/test/dummy/log/test.log +4296 -0
  113. data/vendor/gems/express_templates/test/express_templates_test.rb +5 -1
  114. data/vendor/gems/express_templates/test/handler_test.rb +19 -17
  115. data/vendor/gems/express_templates/test/performance_test.rb +11 -7
  116. data/vendor/gems/express_templates/test/test_helper.rb +162 -1
  117. metadata +58 -47
  118. data/app/assets/stylesheets/express_admin/components/_megadropdown.sass +0 -66
  119. data/vendor/gems/express_templates/diagrams/diagram.graffle +0 -2404
  120. data/vendor/gems/express_templates/diagrams/diagram_express_templates.png +0 -0
  121. data/vendor/gems/express_templates/diagrams/diagram_haml_erb.png +0 -0
  122. data/vendor/gems/express_templates/lib/express_templates/components/capabilities/adoptable.rb +0 -20
  123. data/vendor/gems/express_templates/lib/express_templates/components/capabilities/building.rb +0 -14
  124. data/vendor/gems/express_templates/lib/express_templates/components/capabilities/conditionality.rb +0 -54
  125. data/vendor/gems/express_templates/lib/express_templates/components/capabilities/configurable.rb +0 -90
  126. data/vendor/gems/express_templates/lib/express_templates/components/capabilities/iterating.rb +0 -75
  127. data/vendor/gems/express_templates/lib/express_templates/components/capabilities/parenting.rb +0 -72
  128. data/vendor/gems/express_templates/lib/express_templates/components/capabilities/rendering.rb +0 -30
  129. data/vendor/gems/express_templates/lib/express_templates/components/capabilities/templating.rb +0 -198
  130. data/vendor/gems/express_templates/lib/express_templates/components/capabilities/wrapping.rb +0 -84
  131. data/vendor/gems/express_templates/lib/express_templates/components/column.rb +0 -13
  132. data/vendor/gems/express_templates/lib/express_templates/components/container.rb +0 -7
  133. data/vendor/gems/express_templates/lib/express_templates/components/content_for.rb +0 -42
  134. data/vendor/gems/express_templates/lib/express_templates/components/for_each.rb +0 -30
  135. data/vendor/gems/express_templates/lib/express_templates/components/forms/form_support.rb +0 -13
  136. data/vendor/gems/express_templates/lib/express_templates/components/null_wrap.rb +0 -41
  137. data/vendor/gems/express_templates/lib/express_templates/components/row.rb +0 -28
  138. data/vendor/gems/express_templates/lib/express_templates/components/table_for.rb +0 -163
  139. data/vendor/gems/express_templates/lib/express_templates/components/unless_block.rb +0 -40
  140. data/vendor/gems/express_templates/lib/express_templates/expander.rb +0 -140
  141. data/vendor/gems/express_templates/lib/express_templates/macro.rb +0 -45
  142. data/vendor/gems/express_templates/lib/express_templates/markup.rb +0 -9
  143. data/vendor/gems/express_templates/lib/express_templates/markup/html_tag.rb +0 -62
  144. data/vendor/gems/express_templates/lib/express_templates/markup/tag.rb +0 -150
  145. data/vendor/gems/express_templates/lib/express_templates/markup/wrapper.rb +0 -94
  146. data/vendor/gems/express_templates/lib/express_templates/markup/yielder.rb +0 -21
  147. data/vendor/gems/express_templates/test/components/column_test.rb +0 -11
  148. data/vendor/gems/express_templates/test/components/conditionality_test.rb +0 -37
  149. data/vendor/gems/express_templates/test/components/container_test.rb +0 -66
  150. data/vendor/gems/express_templates/test/components/content_for_test.rb +0 -60
  151. data/vendor/gems/express_templates/test/components/iterating_test.rb +0 -127
  152. data/vendor/gems/express_templates/test/components/null_wrap_test.rb +0 -28
  153. data/vendor/gems/express_templates/test/components/row_test.rb +0 -16
  154. data/vendor/gems/express_templates/test/components/table_for_test.rb +0 -211
  155. data/vendor/gems/express_templates/test/expander_stack_test.rb +0 -41
  156. data/vendor/gems/express_templates/test/expander_test.rb +0 -99
  157. data/vendor/gems/express_templates/test/markup/tag_test.rb +0 -149
  158. data/vendor/gems/express_templates/test/markup/wrapper_test.rb +0 -42
  159. data/vendor/gems/express_templates/test/markup/yielder_test.rb +0 -9
@@ -1,20 +0,0 @@
1
- module ExpressTemplates
2
- module Components
3
- module Capabilities
4
- module Adoptable
5
- # Adoptable adds the capability for a child to refer
6
- # to its parent. This is used by more complex
7
- # components which are intended to work together
8
- # such as form components where form elements may need
9
- # to use information known only to the parent.
10
-
11
- def self.included(base)
12
- base.class_eval do
13
- attr_accessor :parent
14
- end
15
- end
16
-
17
- end
18
- end
19
- end
20
- end
@@ -1,14 +0,0 @@
1
- module ExpressTemplates
2
- module Components
3
- module Capabilities
4
- module Building
5
- # commented this out because it's intercepting calls to rails helpers
6
- # TODO: fix this... I think the whole buiding approach is broken.
7
- # this class is empty and should probably go away.
8
- # def method_missing(name, *args)
9
- # raise "#{self.class.to_s} has no method '#{name}'"
10
- # end
11
- end
12
- end
13
- end
14
- end
@@ -1,54 +0,0 @@
1
- module ExpressTemplates
2
- module Components
3
- module Capabilities
4
- # Adds the capability for a component to only render
5
- # its markup when a condition to be evaluated in the
6
- # view is true.
7
- #
8
- # Example:
9
- #
10
- # class PageHeader < ExpressTemplates::Components::Base
11
- # include ExpressTemplates::Components::Capabilities::Conditionality
12
- #
13
- # emits {
14
- # h1 { content_for(:page_header) }
15
- # }
16
- #
17
- # only_if -> { content_for?(:page_header) }
18
- #
19
- # end
20
- # end
21
- #
22
- # The condition supplied to only if in the form of a proc
23
- # is evaluated in the view context.
24
- #
25
- # The component will render an empty string if the proc returns false.
26
- module Conditionality
27
- def self.included(base)
28
- base.class_eval do
29
- extend ClassMethods
30
- end
31
- end
32
-
33
- module ClassMethods
34
-
35
- def condition_proc
36
- @condition_proc
37
- end
38
-
39
- def only_if condition_proc
40
- @condition_proc = Proc.from_source "-> {!(#{condition_proc.source_body})}"
41
- inner_src = self[:markup]
42
- fragment_src = %Q(-> {
43
- unless_block(Proc.from_source(#{@condition_proc.source.inspect})) {
44
- #{inner_src.source_body}
45
- }
46
- })
47
- _store :markup, Proc.from_source(fragment_src)
48
- end
49
-
50
- end
51
- end
52
- end
53
- end
54
- end
@@ -1,90 +0,0 @@
1
- module ExpressTemplates
2
- module Components
3
- module Capabilities
4
-
5
- # Configurable components accept options which they can use to alter
6
- # their markup each time they are invoked within a template.
7
- #
8
- # They do not compile their markup fragments at load time as simpler
9
- # components do for efficiency. Rather they compile their fragments
10
- # when they are themselves undergoing compilation. This facilitates
11
- # access to arguments which were passed to the component at initialization.
12
- #
13
- # For example, if we have a Row component that is Configurable:
14
- #
15
- # row(:main)
16
- #
17
- # might process to:
18
- #
19
- # <div id="main" class="row" />
20
- #
21
-
22
- module Configurable
23
- def self.included(base)
24
- base.class_eval do
25
- extend ClassMethods
26
- include InstanceMethods
27
-
28
- # Stores arguments for later processing, eg., compile time
29
- def initialize(*args)
30
- @args = args.dup
31
- _process_args!(args)
32
- super(*args)
33
- end
34
- end
35
- end
36
-
37
- module ClassMethods
38
-
39
- protected
40
-
41
- # Override Templating._compile_fragment to delay compilation
42
- def _compile_fragment(block, options = {})
43
- if options.delete(:force_compile)
44
- super(block, options)
45
- else
46
- block
47
- end
48
- end
49
-
50
- def _lookup(name, options = {})
51
- super(name, options.merge(force_compile: true))
52
- end
53
-
54
- end
55
-
56
- module InstanceMethods
57
-
58
- def config
59
- @config ||= {}
60
- end
61
-
62
- alias :my :config
63
-
64
- def expand_locals
65
- {my: config}
66
- end
67
-
68
- # Override Templating#lookup to pass locals
69
- def lookup(fragment_name, options = {})
70
- super(fragment_name, options.merge(expand_locals))
71
- end
72
-
73
-
74
- private
75
-
76
- def _process_args!(args)
77
- if args.first.kind_of?(Symbol)
78
- config.merge!(id: args.shift)
79
- end
80
- while arg = args.shift
81
- if arg.kind_of?(Hash)
82
- config.merge!(arg)
83
- end
84
- end
85
- end
86
- end
87
- end
88
- end
89
- end
90
- end
@@ -1,75 +0,0 @@
1
- module ExpressTemplates
2
- module Components
3
- module Capabilities
4
- #
5
- # Adds the capability to iterate over a collection repeating a markup
6
- # fragment for each member.
7
- #
8
- # Example:
9
- #
10
- # class ParagraphsComponent < ExpressTemplates::Components::Base
11
- #
12
- # emits -> { p { item } } # item is the default local variable name
13
- #
14
- # for_each -> { paragraphs } # evaluated in view context
15
- #
16
- # end
17
- #
18
- # Must specify an <tt>iterator</tt> either as a proc to be evaluated in the
19
- # view context or else as a variable name in the form of a symbol which is
20
- # assumed to be available in the view context.
21
- #
22
- # Provides:
23
- #
24
- # * Iterating::ClassMethods (for_each)
25
- #
26
- module Iterating
27
- def self.included(base)
28
- base.class_eval do
29
- extend ClassMethods
30
- end
31
- end
32
-
33
- module ClassMethods
34
- # Sets the component up to use iterating logic to reproduce a fragment
35
- # for a collection.
36
- #
37
- # Parameters include an iterator that may be :@variable assumed to be
38
- # available in context or a proc that when evaluated in the context
39
- # should return a collection.
40
- #
41
- # An <tt>:emit</tt> option may specify a fragment to emit.
42
- # Defaults to <tt>:markup</tt>
43
- #
44
- # An <tt>:as</tt> option specifies the local variable name for each
45
- # item in the collection for use in the fragment. Defaults to: <tt>item</tt>
46
- #
47
- # An <tt>:empty</tt> option specifies a fragment to use for the
48
- # empty state when the iterator returns an empty collection.
49
- def for_each(iterator, as: :item, emit: :markup, empty: nil)
50
- as = as.to_sym
51
- emit = emit.to_sym
52
- iterator = iterator.kind_of?(Proc) ? iterator.source : iterator
53
- fragment_src = if empty
54
- %Q(-> {
55
- unless_block(Proc.from_source("-> {#{iterator}.call.empty?}"), alt: #{self[empty].source}) {
56
- for_each(Proc.from_source("#{iterator}"), as: #{as.inspect}) {
57
- #{self[emit].source_body}
58
- }
59
- }
60
- })
61
- else
62
- %Q(-> {
63
- for_each(Proc.from_source("#{iterator}"), as: #{as.inspect}) {
64
- #{self[emit].source_body}
65
- }
66
- })
67
- end
68
- fragment = Proc.from_source(fragment_src)
69
- _store :markup, fragment
70
- end
71
- end
72
- end
73
- end
74
- end
75
- end
@@ -1,72 +0,0 @@
1
- module ExpressTemplates
2
- module Components
3
- module Capabilities
4
- module Parenting
5
-
6
- # Parenting adds the capability for a component to have and render
7
- # children that may be specified in the template fragment which
8
- # includes the component.
9
- #
10
- # Example parenting component:
11
- #
12
- # class Line < ExpressTemplates::Components::Base
13
- # include Capabilities::Parenting
14
- #
15
- # emits { p.line { _yield } }
16
- # end
17
- #
18
- # You might then use this component like so:
19
- #
20
- # line "In", "Xanadu", "did", "Kubla", "Khan"
21
- # line { "A stately pleasure-dome decree :" }
22
- # line { "Where Alph, the sacred river, ran" }
23
- # line %q(Through caverns measureless to man)
24
- # line %q|Down to a sunless sea.|
25
- #
26
- # Provides
27
- #
28
- # * ClassMethods for rendering
29
- # * InstanceMethods for managing children
30
- #
31
- def self.included(base)
32
- base.class_eval do
33
- include InstanceMethods
34
- end
35
- end
36
-
37
- module InstanceMethods
38
- def children
39
- @children ||= []
40
- end
41
-
42
- def children=(children)
43
- @children = children
44
- children.each do |child|
45
- if child.kind_of?(Adoptable)
46
- child.parent = self
47
- end
48
- end
49
- end
50
-
51
- def compile
52
- null_wrapped_children = "null_wrap(%q(#{compile_children}))"
53
- wrap_children_src = self.class[:markup].source.gsub(/(\s)_yield(\s)/, '\1'+null_wrapped_children+'\2')
54
- _compile_fragment(Proc.from_source(wrap_children_src))
55
- end
56
-
57
- def compile_children
58
- compiled_children = nil
59
- Indenter.for(:compile) do |indent, indent_with_newline|
60
- compiled_children = children.map do |child|
61
- indent_with_newline +
62
- (child.respond_to?(:compile) ? child.compile : child.inspect) # Bare strings may be children
63
- end.join("+\n")
64
- compiled_children.gsub!('"+"', '') # avoid unnecessary string concatenation
65
- end
66
- return compiled_children
67
- end
68
- end
69
- end
70
- end
71
- end
72
- end
@@ -1,30 +0,0 @@
1
- module ExpressTemplates
2
- module Components
3
- module Capabilities
4
-
5
- # Adds the capability for a component to render itself in a context.
6
- #
7
- # Provides both:
8
- #
9
- # * Rendering::ClassMethods
10
- # * Rendering::InstanceMethods
11
- #
12
- # Used in ExpressTemplates::Components::Base.
13
- #
14
- module Rendering
15
- def self.included(base)
16
- base.class_eval do
17
- extend ClassMethods
18
- end
19
- end
20
-
21
- module ClassMethods
22
- def render_in(context, &view_code)
23
- context.instance_eval(&view_code)
24
- end
25
- end
26
-
27
- end
28
- end
29
- end
30
- end
@@ -1,198 +0,0 @@
1
- module ExpressTemplates
2
- module Components
3
- module Capabilities
4
-
5
- # The Templating capability module provides Components with the ability
6
- # to store, reference and compile template fragments.
7
- #
8
- # It extends the including class with Templating::ClassMethods.
9
- #
10
- # It also provides helpers which are snippets of code in the form of
11
- # lambdas that may be evaluated in the view context.
12
- #
13
- module Templating
14
- def self.included(base)
15
- base.class_eval do
16
- extend ClassMethods
17
- include InstanceMethods
18
- end
19
- class << base
20
- alias_method :fragments, :emits
21
- alias_method :has_markup, :emits
22
- end
23
- end
24
-
25
- module ClassMethods
26
-
27
- # Store fragments of ExpressTemplate style markup for use in
28
- # generating the HTML representation of a component.
29
- #
30
- # For example in your class, simply place the following:
31
- #
32
- # class MyComponent < ET::Components::Base
33
- # emits {
34
- # ul {
35
- # li "one"
36
- # li "two"
37
- # li "three"
38
- # }
39
- # }
40
- #
41
- # end
42
- #
43
- # By default this template code is stored under the label :markup
44
- #
45
- # You may specify several fragments with a hash containing lambdas:
46
- #
47
- # emits body: -> { li "item" },
48
- # wrapper: -> { ul { _yield } }
49
- #
50
- # This method is aliased as <tt>fragments</tt> and <tt>has_markup</tt>
51
- #
52
- def emits(*args, &template_code)
53
- if args.first.respond_to?(:call) or template_code
54
- fragment = (args.first||template_code)
55
- raise "must use stabby lambda" unless fragment.lambda?
56
- _store :markup, fragment# default fragment is named :markup
57
- else
58
- args.first.to_a.each do |name, block|
59
- raise ArgumentError unless name.is_a?(Symbol) and block.is_a?(Proc)
60
- _store(name, block)
61
- end
62
- end
63
- end
64
-
65
- def [](label)
66
- _lookup(label)
67
- end
68
-
69
- # Stores a block given for later evaluation in context.
70
- #
71
- # Example:
72
- #
73
- # class TitleComponent < ECB
74
- # helper :title_helper do
75
- # @resource.name
76
- # end
77
- #
78
- # emits {
79
- # h1 {
80
- # title_helper
81
- # }
82
- # }
83
- #
84
- # end
85
- #
86
- # In this example <tt>@resource.name</tt> is evaluated in the
87
- # provided context during page rendering and not during template
88
- # expansion or compilation.
89
- #
90
- # This is the recommended for encapsulation of "helper" type
91
- # functionality which is of concern only to the component and
92
- # used only in its own markup fragments.
93
- def helper(name, &block)
94
- _helpers[name] = block
95
- _define_helper_methods name
96
- end
97
-
98
- def special_handlers
99
- {insert: self, _yield: self}.merge(Hash[*(_helpers.keys.map {|k| [k, self] }.flatten)])
100
- end
101
-
102
- protected
103
-
104
- # Stores a fragment for use during compilation and rendering
105
- # of a component.
106
- def _store(name, fragment)
107
- @fragments ||= Hash.new
108
- @fragments[name] = fragment
109
- end
110
-
111
- # Looks up a template fragment for this component and returns
112
- # compiled template code.
113
- #
114
- # If the template fragment is not already compiled, it compiles it
115
- # with the supplied options as locals. Locals may be used within
116
- # the template during expansion.
117
- #
118
- # Returns a string containing ruby code which evaluates to markup.
119
- def _lookup(name, options = {})
120
- @fragments ||= Hash.new
121
- @fragments[name] or raise "no template fragment supplied for: #{name}"
122
- end
123
-
124
- private
125
-
126
-
127
- def _helpers
128
- @helpers ||= Hash.new
129
- end
130
-
131
- def _define_helper_methods(name)
132
- method_definition= <<-RUBY
133
- class << self
134
-
135
- # called during expansion
136
- define_method(:#{name}) do |*args|
137
- helper_args = %w(self)
138
- helper_args += args.map(&:inspect)
139
- '{{#{self.to_s}._#{name}('+_interpolate(helper_args).join(', ')+')}}'
140
- end
141
-
142
- # called during rendering in view context
143
- define_method(:_#{name}) do |context, *args|
144
- begin
145
- helper_proc = _helpers[:#{name}]
146
- helper_args = args.take(helper_proc.arity)
147
- context.instance_exec *helper_args, &helper_proc
148
- rescue => e
149
- raise "#{name} raised: \#\{e.to_s\}"
150
- end.to_s
151
- end
152
- end
153
- RUBY
154
- eval(method_definition)
155
- end
156
-
157
- def _interpolate(args)
158
- args.map do |arg|
159
- if arg.kind_of?(String) && match = arg.match(/"\{\{(.*)\}\}"/)
160
- match[1]
161
- else
162
- arg
163
- end
164
- end
165
- end
166
-
167
- end
168
-
169
- module InstanceMethods
170
-
171
- def lookup(fragment_name, options={})
172
- fragment = self.class[fragment_name]
173
- if fragment.kind_of?(Proc)
174
- _compile_fragment(fragment, options)
175
- else
176
- fragment
177
- end
178
- end
179
-
180
- # Expands and compiles the supplied block representing a
181
- # template fragment.
182
- #
183
- # Any supplied options are passed as locals for use during expansion.
184
- #
185
- # Returns a string containing ruby code which evaluates to markup.
186
- def _compile_fragment(block, options = {})
187
- initialize_expander(nil, self.class.special_handlers, options)
188
- expand(&block).map(&:compile).join("+").gsub('"+"', '')
189
- end
190
-
191
-
192
- end
193
-
194
-
195
- end
196
- end
197
- end
198
- end