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,140 +0,0 @@
1
- require 'express_templates/components'
2
- module ExpressTemplates
3
- class Expander
4
-
5
- cattr_accessor :module_search_space
6
-
7
- attr_accessor :stack, :handlers, :locals, :template
8
-
9
- def initialize(*args)
10
- initialize_expander(*args)
11
- end
12
-
13
- def initialize_expander(template, handlers = {}, locals = {})
14
- @template = template
15
- @stack = Stack.new
16
- @handlers = handlers
17
- @locals = locals
18
- self
19
- end
20
-
21
- def expand(source=nil, &block)
22
- case
23
- when block.nil? && source
24
- modified = _replace_yield_with_yielder(source)
25
- instance_eval(modified, @template.inspect)
26
- when block
27
- instance_exec &block
28
- else
29
- raise ArgumentError
30
- end
31
- stack.current
32
- end
33
-
34
- def process_children!(parent, &block)
35
- begin
36
- stack.descend!
37
- result = instance_exec &block
38
- if stack.current.empty? && result.is_a?(String)
39
- stack << result
40
- end
41
- parent.children += stack.current
42
- stack.ascend!
43
- end
44
- stack.current
45
- end
46
-
47
- # define a "macro" method for a component
48
- # these methods accept args which are passed to the
49
- # initializer for the component
50
- # blocks supplied are evaluated and children added to the "stack"
51
- # are added as children to the component
52
- def self.register_macros_for(*components)
53
- components.each do |component|
54
- define_method(component.macro_name.to_sym) do |*args, &block|
55
- new_component = nil
56
- # this is a code smell here.
57
- if component.ancestors.include?(Components::Capabilities::Building)
58
- new_component = component.new(*(args.push(self)), &block)
59
- else
60
- new_component = component.new(*(args.push(self)))
61
- process_children!(new_component, &block) unless block.nil?
62
- end
63
- stack << new_component
64
- end
65
- end
66
- end
67
-
68
-
69
- @module_search_space = [ExpressTemplates::Markup, ExpressTemplates::Components]
70
-
71
- @module_search_space.each do |mod|
72
- register_macros_for(*
73
- mod.constants.map { |const| [mod.to_s, const.to_s].join("::").constantize }.
74
- select { |klass| klass.ancestors.include? (ExpressTemplates::Markup::Tag) }
75
- )
76
- end
77
-
78
- def method_missing(name, *args, &block)
79
- raise "#{self.class} unexpected macro: \"#{name}\"." if locals.nil?
80
- return locals[name] if locals.keys.include?(name)
81
-
82
- if handlers.keys.include?(name)
83
- stack << handlers[name].send(name, *args, &block)
84
- else
85
- stack << ExpressTemplates::Markup::Wrapper.new(name.to_s, *args, &block)
86
- end
87
- nil
88
- end
89
-
90
- private
91
-
92
- def _replace_yield_with_yielder(source)
93
- source.gsub(/(\W)(yield)(\([^\)]*\))?/, '\1 (stack << ExpressTemplates::Markup::Yielder.new\3)')
94
- end
95
-
96
- class Stack
97
- def initialize
98
- @stack = [[]]
99
- @frame = 0
100
- end
101
-
102
- def all
103
- @stack
104
- end
105
-
106
- def dump
107
- puts "Current frame: #{@frame}"
108
- require 'pp'
109
- pp all
110
- end
111
-
112
- def <<(child)
113
- current << child
114
- child
115
- end
116
-
117
- def current
118
- @stack[@frame]
119
- end
120
-
121
- def next
122
- @stack[@frame+1] ||= []
123
- end
124
-
125
- def descend!
126
- @frame += 1
127
- @stack[@frame] ||= []
128
- @stack[@frame].clear
129
- @frame
130
- end
131
-
132
- def ascend!
133
- raise "Cannot ascend" if @frame <= 0
134
- current.clear ;
135
- self.next.clear
136
- @frame -= 1
137
- end
138
- end
139
- end
140
- end
@@ -1,45 +0,0 @@
1
- module ExpressTemplates
2
- module Macro
3
-
4
- def self.included(base)
5
- base.class_eval do
6
- extend ClassMethods
7
- include InstanceMethods
8
- end
9
- end
10
-
11
- module ClassMethods
12
- def macro_name
13
- to_s.split('::').last.underscore
14
- end
15
- end
16
- module InstanceMethods
17
- def macro_name ; self.class.macro_name end
18
-
19
- def initialize(*children_or_options)
20
- @children = []
21
- @options = {}.with_indifferent_access
22
- # expander passes itself as last arg
23
- @expander = children_or_options.pop if children_or_options.last.kind_of?(ExpressTemplates::Expander)
24
- _process(*children_or_options)
25
- end
26
-
27
- private
28
-
29
- def _process(*children_or_options)
30
- children_or_options.each do |child_or_option|
31
- case
32
- when child_or_option.kind_of?(Hash)
33
- @options.merge!(child_or_option)
34
- when child_or_option.kind_of?(Symbol)
35
- @options.merge!(id: child_or_option.to_s)
36
- when child_or_option.nil?
37
- else
38
- @children << child_or_option
39
- end
40
- end
41
- end
42
-
43
- end
44
- end
45
- end
@@ -1,9 +0,0 @@
1
- module ExpressTemplates
2
- module Markup
3
- end
4
- end
5
-
6
- require 'express_templates/markup/tag'
7
- require 'express_templates/markup/html_tag'
8
- require 'express_templates/markup/wrapper'
9
- require 'express_templates/markup/yielder'
@@ -1,62 +0,0 @@
1
- module ExpressTemplates
2
- module Markup
3
- class HtmlTag < Tag
4
- NON_VOID_TAGS = [:a, :abbr, :address, :article, :aside, :audio,
5
- :b, :bdi, :bdo, :blockquote, :body, :button,
6
- :canvas, :caption, :cite, :code, :colgroup,
7
- :data, :datalist, :dd, :del, :details, :dfn, :div, :dl, :dt,
8
- :em,
9
- :fieldset, :figcaption, :figure, :footer, :form,
10
- :h1, :h2, :h3, :h4, :h5, :h6, :head, :header, :html,
11
- :i, :iframe, :ins,
12
- :kbd,
13
- :label, :legend, :li,
14
- :main, :map, :mark, :math, :menu, :menuitem, :meter,
15
- :nav, :noscript,
16
- :object, :ol, :optgroup, :option, :output,
17
- :p, :pre, :progress,
18
- :q,
19
- :rp, :rt, :ruby,
20
- :s, :samp, :script, :section, :select, :small,
21
- :span, :strong, :style, :sub, :sup, :summary, :svg,
22
- :table, :tbody, :td, :textarea, :tfoot, :th, :thead, :time, :title, :tr,
23
- :u, :ul,
24
- :var, :video]
25
-
26
- VOID_TAGS = [:area, :base, :br, :col, :command, :doctype, :embed, :hr, :img, :input,
27
- :keygen, :link, :meta, :param, :source, :track, :wbr]
28
-
29
- ALL_TAGS = NON_VOID_TAGS + VOID_TAGS
30
- end
31
-
32
- HtmlTag::ALL_TAGS.each do |tag|
33
- klass = tag.to_s.titleize
34
- ExpressTemplates::Markup.module_eval "class #{klass} < ExpressTemplates::Markup::HtmlTag ; end"
35
- end
36
-
37
- HtmlTag::VOID_TAGS.each do |tag|
38
- klass = "ExpressTemplates::Markup::#{tag.to_s.titleize}"
39
- klass.constantize.class_eval do
40
- def close_tag
41
- ''
42
- end
43
-
44
- def transform_close_tag?
45
- false
46
- end
47
- end
48
- end
49
-
50
- Doctype.class_eval do
51
- def start_tag
52
- "<!DOCTYPE html>"
53
- end
54
- end
55
-
56
- I.class_eval do
57
- def should_not_abbreviate?
58
- true
59
- end
60
- end
61
- end
62
- end
@@ -1,150 +0,0 @@
1
- module ExpressTemplates
2
- module Markup
3
- class Tag
4
- include ExpressTemplates::Macro
5
-
6
- attr_accessor :children
7
-
8
- INDENT = ' '
9
-
10
- # These come from Macro but must remain overridden here for performance reasons.
11
- # To verify, comment these two methods and
12
- # run rake test and observe the performance hit. Why?
13
- def self.macro_name
14
- @macro_name ||= to_s.split('::').last.underscore
15
- end
16
-
17
- def macro_name ; self.class.macro_name end
18
-
19
-
20
- def html_options
21
- @options.each_pair.map do |name, value|
22
- case
23
- when name.to_sym.eql?(:data) && value.kind_of?(Hash)
24
- value.each_pair.map {|k,v| %Q(data-#{k}=\\"#{v}\\") }.join(" ")
25
- when value.kind_of?(Proc)
26
- %Q(#{name}=\\"\#{(#{value.source}).call}\\")
27
- else
28
- %Q(#{name}=\\"#{value}\\")
29
- end
30
- end.join(" ")
31
- end
32
-
33
- def start_tag
34
- "<#{macro_name}#{html_options.empty? ? '' : ' '+html_options}>"
35
- end
36
-
37
- def close_tag
38
- "</#{macro_name}>"
39
- end
40
-
41
- def add_css_class(css_class)
42
- @options['class'] ||= ''
43
- css_class = css_class.to_s.gsub('_', '-').gsub(/^-/,'') if css_class.to_s.match /^_.*_/
44
- @options['class'] = (@options['class'].split + [css_class]).uniq.join(" ")
45
- end
46
-
47
- def method_missing(name, *args, &children)
48
- add_css_class(name)
49
- _process(*args) unless args.empty?
50
- if children # in the case where CSS classes are specified via method
51
- unless @expander.nil?
52
- @expander.process_children! self, &children
53
- else
54
- raise "block passed without expander"
55
- end
56
- end
57
- return self
58
- end
59
-
60
- def should_not_abbreviate?
61
- false
62
- end
63
-
64
- def transform_close_tag?
65
- true
66
- end
67
-
68
- def compile
69
- ExpressTemplates::Indenter.for(:markup) do |whitespace|
70
- ruby_fragments = @children.map do |child|
71
- if child.respond_to?(:compile)
72
- child.compile
73
- else
74
- %Q("#{child}")
75
- end
76
- end
77
- unless ruby_fragments.empty?
78
- _wrap_with_tags(ruby_fragments, whitespace)
79
- else
80
- if should_not_abbreviate?
81
- _wrap_with_tags(ruby_fragments, whitespace)
82
- elsif transform_close_tag?
83
- %Q("#{start_tag.gsub(/>$/, ' />')}")
84
- else
85
- %Q("#{start_tag}")
86
- end
87
- end
88
- end
89
- end
90
-
91
- def to_template
92
- # ExpressTemplates::Indenter.for(:template) do
93
- template_fragments = @children.map do |child|
94
- if child.respond_to?(:to_template)
95
- child.to_template
96
- else
97
- child
98
- end
99
- end
100
- macro_name + _blockify(template_fragments.join("\n"))
101
- # end
102
- end
103
-
104
- def self.formatted
105
- old_setting = Thread.current[:formatted]
106
- begin
107
- Thread.current[:formatted] = true
108
- yield if block_given?
109
- ensure
110
- Thread.current[:formatted] = old_setting
111
- end
112
- end
113
-
114
- private
115
-
116
- def _wrap_with_tags(ruby_fragments, whitespace)
117
- opening, closing = nil, nil
118
- if !ENV['ET_NO_INDENT_MARKUP'].eql?('true') || #TODO: change to setting
119
- Thread.current[:formatted]
120
- child_code = ruby_fragments.join
121
- should_format = ruby_fragments.size > 1 ||
122
- (child_code.size > 40 && !child_code.match(/^"\#\{.*\}"$/)) ||
123
- child_code.match(/\n/)
124
-
125
- nl = should_format ? "\n" : nil
126
- nl_after_start = !ruby_fragments.first.try(:match, /^"\n/) ? nl : nil
127
- # binding.pry
128
- nl_before_end = !ruby_fragments.last.try(:match, /\n"$/) ? nl : nil
129
- opening = %Q("\n#{whitespace}#{start_tag}#{nl_after_start}")
130
- closing = %Q("#{nl_before_end}#{should_format && whitespace}#{close_tag}#{nl}")
131
- else
132
- opening = %Q("#{start_tag}")
133
- closing = %Q("#{close_tag}")
134
- end
135
- ruby_fragments.unshift opening
136
- ruby_fragments.push closing
137
- ruby_fragments.reject {|frag| frag.empty? }.join("+")
138
- end
139
-
140
- def _indent(code)
141
- code.split("\n").map {|line| ExpressTemplates::Indenter::WHITESPACE + line }.join("\n")
142
- end
143
-
144
- def _blockify(code)
145
- code.empty? ? code : " {\n#{_indent(code)}\n}\n"
146
- end
147
-
148
- end
149
- end
150
- end
@@ -1,94 +0,0 @@
1
- module ExpressTemplates
2
- module Markup
3
- # wrap locals and helpers for evaluation during render
4
- class Wrapper
5
-
6
- attr_accessor :name, :args
7
-
8
- def initialize(name, *args, &block)
9
- @name = name
10
- @args = args
11
- @block_src = block ? block.source : nil
12
- end
13
-
14
- def compile
15
- # insure nils do not blow up view
16
- %Q(%Q({{#{_compile}}}))
17
- end
18
-
19
- def to_template
20
- _compile
21
- end
22
-
23
- def children
24
- []
25
- end
26
-
27
- private
28
- def _compile
29
- string = "#{name}"
30
-
31
- if !@args.empty?
32
-
33
- args_string = args.slice(0..-2).map do |arg|
34
- if arg.respond_to?(:gsub) && arg.match(/^\{\{(.*)\}\}$/)
35
- # strip double braces because otherwise these will be converted
36
- # to "#{arg}" during final interpolation which is generally not
37
- # the intention for arguments to helpers as these are ruby expressions
38
- # not necessarily returning strings
39
- $1
40
- else
41
- arg.inspect # 'value' or :value or ['a', 'b', 'c'] or {:key => 'value'}
42
- end
43
- end.join(', ')
44
-
45
- last_arg = ''
46
- if args.last.is_a?(Hash) # expand a hash
47
- last_arg = _convert_hash_to_argument_string(args.last)
48
- else
49
- last_arg = args.last.inspect
50
- end
51
- args_string << (args_string.empty? ? last_arg : ", #{last_arg}")
52
- string << "(#{args_string})"
53
- end
54
-
55
- if @block_src
56
- string << " #{@block_src}"
57
- end
58
-
59
- return string
60
- end
61
-
62
- def _convert_hash_to_argument_string(hash)
63
- use_hashrockets = hash.keys.any? {|key| key.to_s.match /-/}
64
- unless hash.empty?
65
- return hash.map do |key, value|
66
- s = if use_hashrockets
67
- if key.to_s.match /-/
68
- "'#{key}' => "
69
- else
70
- ":#{key} => "
71
- end
72
- else
73
- "#{key}: "
74
- end
75
-
76
- case
77
- when value.is_a?(String)
78
- s << '"'+value+'"'
79
- when value.is_a?(Hash)
80
- s << value.inspect
81
- when value.is_a?(Proc)
82
- s << "(#{value.source}).call"
83
- else
84
- s << value.inspect # immediate values 1, 2.0, true etc
85
- end
86
- s
87
- end.join(", ")
88
- else
89
- "{}" # empty hash
90
- end
91
- end
92
- end
93
- end
94
- end