express_templates 0.5.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +22 -41
  3. data/lib/arbre/patches.rb +50 -0
  4. data/lib/core_extensions/proc.rb +1 -0
  5. data/lib/express_templates/compiler.rb +2 -7
  6. data/lib/express_templates/components/base.rb +33 -37
  7. data/lib/express_templates/components/capabilities/resourceful.rb +30 -18
  8. data/lib/express_templates/components/configurable.rb +41 -0
  9. data/lib/express_templates/components/form_rails_support.rb +5 -6
  10. data/lib/express_templates/components/forms/basic_fields.rb +3 -6
  11. data/lib/express_templates/components/forms/checkbox.rb +1 -1
  12. data/lib/express_templates/components/forms/express_form.rb +15 -25
  13. data/lib/express_templates/components/forms/form_component.rb +20 -11
  14. data/lib/express_templates/components/forms/option_support.rb +2 -2
  15. data/lib/express_templates/components/forms/radio.rb +7 -8
  16. data/lib/express_templates/components/forms/select.rb +61 -37
  17. data/lib/express_templates/components/forms/select_collection.rb +2 -8
  18. data/lib/express_templates/components/forms/submit.rb +7 -6
  19. data/lib/express_templates/components/forms.rb +0 -1
  20. data/lib/express_templates/components/tree_for.rb +26 -42
  21. data/lib/express_templates/components.rb +1 -9
  22. data/lib/express_templates/version.rb +1 -1
  23. data/lib/express_templates.rb +2 -3
  24. data/test/components/base_test.rb +17 -15
  25. data/test/components/capabilities/resourceful_test.rb +3 -3
  26. data/test/components/configurable_test.rb +27 -21
  27. data/test/components/forms/basic_fields_test.rb +57 -17
  28. data/test/components/forms/checkbox_test.rb +16 -22
  29. data/test/components/forms/express_form_test.rb +23 -76
  30. data/test/components/forms/radio_test.rb +31 -27
  31. data/test/components/forms/select_test.rb +46 -71
  32. data/test/components/forms/submit_test.rb +10 -5
  33. data/test/components/tree_for_test.rb +24 -52
  34. data/test/dummy/app/views/hello/show.html.et +4 -3
  35. data/test/dummy/app/views/layouts/application.html.et +1 -1
  36. data/test/dummy/log/test.log +4794 -0
  37. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/-cDLO4NJHMndDHchOLz8KLD7QBc68WtaAbYxK2r6GsU.cache +0 -0
  38. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/0t68EIwZ96sAqQSxFka9MQyIk4viw8ZIoREMCGiJRx0.cache +0 -0
  39. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/2zt1IbQCnmzGyeZS_I4sYQzrgneSCKIJBRxcffVHlWY.cache +1 -0
  40. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/EDVlXrcn_wEfaZ5nc_4QJBT7lPiIBcX96jBo7PBz-vc.cache +1 -0
  41. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/Eso3tkb79hXQ1XdQgjbV03KyQwSeZFAHxVHImsjQ-HQ.cache +2 -0
  42. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/I8LhheC1OlOyvp_qY8kWpqKcZFiqv_BO-l5bExvDEi0.cache +1 -0
  43. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/Kf4VrP5sW-qzziYSN-m7p4nETjLiEwwwRfwUOm7rOr0.cache +0 -0
  44. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/QJ0Z8hROMfWpY6f5Chb7GSuDHE4gpabKVQTr9BCZe9s.cache +1 -0
  45. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/T1pSAx767vY7X1UDN0vdF7YGEkI5wMSVUKopsdvp7kI.cache +1 -0
  46. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/VlSPFPDK05c7ImadRiRVKzsaa6e15RwX77QR3NYabME.cache +0 -0
  47. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/Y7_BbgB9jgJIWYjDCsASySd26DTfPADAu_3DDnLlFog.cache +0 -0
  48. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/g2xQygPqA5kMmp5L3wVGWaUIhdVsxFmOel9FF6M0Fuw.cache +0 -0
  49. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/kaif59owjUr3HBharCH5GUxU6KoW_zXD9a9JiTjIYPY.cache +1 -0
  50. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/p1cwnBd8RQBm9x5HzDmiiU7RhvnxhPX8VTfi0tTElJY.cache +3 -0
  51. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/qT6_0ti_v6fAjS3wETXqvTkr6W0LP4PB942uLYQzWK8.cache +3 -0
  52. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/y8T65xpx0s3RgT_YiqWEEXIaBsgK4woCNSuZ1zjQZBk.cache +2 -0
  53. data/test/express_templates_test.rb +5 -1
  54. data/test/handler_test.rb +19 -17
  55. data/test/performance_test.rb +11 -7
  56. data/test/test_helper.rb +162 -1
  57. metadata +50 -53
  58. data/lib/express_templates/components/capabilities/adoptable.rb +0 -20
  59. data/lib/express_templates/components/capabilities/building.rb +0 -14
  60. data/lib/express_templates/components/capabilities/conditionality.rb +0 -54
  61. data/lib/express_templates/components/capabilities/configurable.rb +0 -90
  62. data/lib/express_templates/components/capabilities/iterating.rb +0 -75
  63. data/lib/express_templates/components/capabilities/parenting.rb +0 -72
  64. data/lib/express_templates/components/capabilities/rendering.rb +0 -30
  65. data/lib/express_templates/components/capabilities/templating.rb +0 -198
  66. data/lib/express_templates/components/capabilities/wrapping.rb +0 -84
  67. data/lib/express_templates/components/column.rb +0 -13
  68. data/lib/express_templates/components/container.rb +0 -7
  69. data/lib/express_templates/components/content_for.rb +0 -42
  70. data/lib/express_templates/components/for_each.rb +0 -30
  71. data/lib/express_templates/components/forms/form_support.rb +0 -13
  72. data/lib/express_templates/components/null_wrap.rb +0 -41
  73. data/lib/express_templates/components/row.rb +0 -28
  74. data/lib/express_templates/components/table_for.rb +0 -163
  75. data/lib/express_templates/components/unless_block.rb +0 -40
  76. data/lib/express_templates/expander.rb +0 -140
  77. data/lib/express_templates/macro.rb +0 -45
  78. data/lib/express_templates/markup/html_tag.rb +0 -62
  79. data/lib/express_templates/markup/tag.rb +0 -150
  80. data/lib/express_templates/markup/wrapper.rb +0 -94
  81. data/lib/express_templates/markup/yielder.rb +0 -21
  82. data/lib/express_templates/markup.rb +0 -9
  83. data/test/components/column_test.rb +0 -11
  84. data/test/components/conditionality_test.rb +0 -37
  85. data/test/components/container_test.rb +0 -66
  86. data/test/components/content_for_test.rb +0 -60
  87. data/test/components/iterating_test.rb +0 -127
  88. data/test/components/null_wrap_test.rb +0 -28
  89. data/test/components/row_test.rb +0 -16
  90. data/test/components/table_for_test.rb +0 -211
  91. data/test/expander_stack_test.rb +0 -41
  92. data/test/expander_test.rb +0 -99
  93. data/test/markup/tag_test.rb +0 -149
  94. data/test/markup/wrapper_test.rb +0 -42
  95. data/test/markup/yielder_test.rb +0 -9
@@ -1,41 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ExpanderStackTest < ActiveSupport::TestCase
4
-
5
- def new_stack
6
- ExpressTemplates::Expander::Stack.new
7
- end
8
-
9
- test "#current is empty" do
10
- assert_empty new_stack.current
11
- end
12
-
13
- test "#<< adds something to the current" do
14
- stack = new_stack
15
- stack << 'foo'
16
- assert_equal ['foo'], stack.current
17
- end
18
-
19
- test "#all returns the stack" do
20
- assert_equal [[]], new_stack.all
21
- end
22
-
23
- test "#descend! adds a level to the stack and updates current" do
24
- stack = new_stack
25
- stack << 'foo'
26
- level = stack.descend!
27
- assert_equal 2, stack.all.count
28
- assert_equal [], stack.current
29
- assert_equal 1, level
30
- end
31
-
32
- test "#ascend!" do
33
- stack = new_stack
34
- stack << 'foo'
35
- level_1 = stack.descend!
36
- level_2 = stack.descend!
37
- level = stack.ascend!
38
- assert_equal level_1, level
39
- end
40
-
41
- end
@@ -1,99 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ExpanderTest < ActiveSupport::TestCase
4
-
5
- class Foo < ExpressTemplates::Markup::Tag ; end
6
- class Bar < ExpressTemplates::Markup::Tag ; end
7
- class Baz < ExpressTemplates::Markup::Tag ; end
8
-
9
- ExpressTemplates::Expander.register_macros_for(Foo,Bar,Baz)
10
-
11
- test "#expand returns an array containing a component" do
12
- source = "foo"
13
- result = ExpressTemplates::Expander.new(nil).expand(source)
14
- assert_kind_of ExpressTemplates::Markup::Tag, result.first
15
- end
16
-
17
- test "#expand of 'foo { foo } returns a component with a child component" do
18
- source = 'foo { foo }'
19
- result = ExpressTemplates::Expander.new(nil).expand(source)
20
- assert_kind_of Foo, result.first.children.first
21
- end
22
-
23
- test "#expand of 'foo { bar ; baz } returns a component with two children" do
24
- source = 'foo { bar ; baz }'
25
- result = ExpressTemplates::Expander.new(nil).expand(source)
26
- assert_equal 2, result.first.children.size
27
- assert_kind_of Bar, result.first.children.first
28
- assert_kind_of Baz, result.first.children.last
29
- end
30
-
31
- test "#expand of macros with args returns a component with two children" do
32
- source = 'foo { bar(fiz: "buzz") ; baz }'
33
- result = ExpressTemplates::Expander.new(nil).expand(source)
34
- assert_equal 2, result.first.children.size
35
- assert_kind_of Bar, result.first.children.first
36
- assert_kind_of Baz, result.first.children.last
37
- end
38
-
39
- test "#expand correctly allocated helpers and parameters" do
40
- source = 'helper ; foo { buzz }'
41
- result = ExpressTemplates::Expander.new(nil).expand(source)
42
- assert_equal 0, result.first.children.size
43
- assert_equal 1, result[1].children.size
44
- assert_kind_of ExpressTemplates::Markup::Wrapper, result.first
45
- assert_kind_of Foo, result[1]
46
- assert_kind_of ExpressTemplates::Markup::Wrapper, result[1].children.first
47
- end
48
-
49
- test "#expand works with css class specification syntax xxx" do
50
- source = 'foo.active { baz }'
51
- result = ExpressTemplates::Expander.new(nil).expand(source)
52
- assert_equal 1, result[0].children.size
53
- end
54
-
55
- test "#expand doesn't yield [] for children" do
56
- source = %Q(ul(class: 'title-area') {
57
- li.name {
58
- a("Something", href: '#', disabled: true)
59
- }
60
- li(class:"ugly markup") {
61
- a(href: "#") { span "menu item" }
62
- }
63
- })
64
- result = ExpressTemplates::Expander.new(nil).expand(source)
65
- child_of_first_child = result.first.children.first
66
- assert_equal 1, child_of_first_child.children.size
67
- assert_kind_of ExpressTemplates::Markup::Tag, child_of_first_child.children.first
68
- end
69
-
70
- class Special
71
- def self.render(label)
72
- :dummy
73
- end
74
- end
75
-
76
- test "initializer accepts special handlers hash" do
77
- source = "render(:markup)"
78
- assert_equal [:dummy], ExpressTemplates::Expander.new(nil, render: Special).expand(source)
79
- end
80
-
81
- test "helpers can take blocks" do
82
- result = ExpressTemplates::Expander.new(nil).expand do
83
- helper do
84
- foo
85
- end
86
- end
87
- assert_equal %q(%Q(#{helper do
88
- foo
89
- end})), Interpolator.transform(result.first.compile)
90
- end
91
-
92
- # NOTE: This probably should be deleted as {{helper}} is preferred
93
- test "non-interpolated string children containing string interpolations will interpolate in context" do
94
- source = 'p %q(some text #{helper})'
95
- result = ExpressTemplates::Expander.new(nil).expand(source)
96
- assert_equal %q("<p>"+"some text #{helper}"+"</p>"), result.first.compile
97
- end
98
-
99
- end
@@ -1,149 +0,0 @@
1
- require 'test_helper'
2
-
3
- class TagTest < ActiveSupport::TestCase
4
-
5
- class Bare < ExpressTemplates::Markup::Tag ; end
6
- class Sub < ExpressTemplates::Markup::Tag ; end
7
-
8
- def bare_tag(*args)
9
- Bare.new(*args)
10
- end
11
-
12
- def sub_tag(*args)
13
- Sub.new(*args)
14
- end
15
-
16
-
17
- # NOTE: Due to formatting html leading newlines may be
18
- # required for test values. These are stripped for the
19
- # first tag during ExpressTemplates.compile
20
-
21
- test "#macro_name returns the name of the class" do
22
- assert_equal 'bare', bare_tag.macro_name
23
- end
24
-
25
- test "#compile returns a string" do
26
- assert_kind_of String, bare_tag.compile
27
- end
28
-
29
- test "has no children" do
30
- assert_empty bare_tag.children
31
- end
32
-
33
- def bare_with_2_children
34
- tag = bare_tag "child1", "child2"
35
- end
36
-
37
- test "can be created with children" do
38
- assert_equal 2, bare_with_2_children.children.size
39
- assert_equal "child2", bare_with_2_children.children.last
40
- end
41
-
42
- test "#compile on bare_with_2_children yields '\"<bare>\"+\"child1\"+\"child2\"+\"</bare>\"'" do
43
- assert_equal '"<bare>"+"child1"+"child2"+"</bare>"', bare_with_2_children.compile
44
- end
45
-
46
- test "#start_tag is my macro_name as an xml start tag" do
47
- assert_equal "<#{bare_tag.macro_name}>", bare_tag.start_tag
48
- end
49
-
50
- test "#close_tag is my macro_name as an xml close tag" do
51
- assert_equal "</#{bare_tag.macro_name}>", bare_tag.close_tag
52
- end
53
-
54
- def tag_with_subtag
55
- bare_tag sub_tag
56
- end
57
-
58
- test "#compile on tag_with_subtag returns a string which when eval'd looks like '<bare><sub /></bare>'" do
59
- assert_equal '<bare><sub /></bare>', eval(tag_with_subtag.compile)
60
- end
61
-
62
- test "#to_template on bare_tag returns 'bare'" do
63
- assert_equal 'bare', bare_tag.to_template
64
- end
65
-
66
- test "#to_template on tag_with_subtag returns 'bare {\n sub\n}\n'" do
67
- assert_equal "bare {\n sub\n}\n", tag_with_subtag.to_template
68
- end
69
-
70
- test "#to_template on nested tags indents properly'" do
71
- expected = %Q(bare {
72
- sub {
73
- sub
74
- }
75
- }
76
- )
77
- assert_equal expected, Bare.new(Sub.new(Sub.new)).to_template
78
- end
79
-
80
- test "double bracketed option values are substituted for evaluation in context" do
81
- assert_equal '"<bare should_eval_in_context=\"#{foo}\" />"',
82
- Interpolator.transform(bare_tag(should_eval_in_context: "{{foo}}").compile)
83
- end
84
-
85
- test "double bracketed child values are substituted for evaluation in context" do
86
- assert_equal '"<bare>"+"#{foo}"+"</bare>"',
87
- Interpolator.transform(bare_tag("{{foo}}").compile)
88
- end
89
-
90
- test "data option value hashes are converted to data attributes similar to haml" do
91
- assert_equal %("<bare data-one=\\"two\\" data-three=\\"four\\" />"),
92
- bare_tag(data: {one: 'two', three: 'four'}).compile
93
- end
94
-
95
- test "data option value hashes can take immediate values" do
96
- assert_equal %("<bare data-foo=\\"true\\" data-bar=\\"42\\" data-baz=\\"blah\\" />"),
97
- bare_tag(data: {foo: true, bar: 42, baz: 'blah'}).compile
98
- end
99
-
100
-
101
- # todo?
102
- # test "proc option values are evaluated in context"
103
-
104
- test "empty tags use abbreviated empty tag form" do
105
- assert_equal '"<bare />"', bare_tag.compile
106
- end
107
-
108
- test "empty i tag does does not use abbreviated form since it is used for icons" do
109
- assert_equal '"<i>"+"</i>"', ExpressTemplates::Markup::I.new.compile
110
- end
111
-
112
- test "method missing returns self" do
113
- tag = bare_tag
114
- assert_equal tag, tag.foo
115
- end
116
-
117
- # the block form of this is tested in expander
118
- test "children still evaluated after css class provided via method syntax" do
119
- assert_equal '"<bare class=\"foo\">"+"<sub />"+"</bare>"', (bare_tag.foo(sub_tag)).compile
120
- end
121
-
122
- test "CSS classes specified with underscored method get translated to dashed" do
123
- assert_equal '"<bare class=\"foo-bar\" />"', bare_tag._foo_bar.compile
124
- end
125
-
126
- test "dom ID may be passed as a symbol" do
127
- assert_equal '"<bare id=\"foo\" />"', bare_tag(:foo).compile
128
- end
129
-
130
- test "proc option values are evaluated in context" do
131
- assert_equal '"<bare id=\"#{(-> { awesome }).call}\" />"', bare_tag(id: -> { awesome }).compile
132
- end
133
-
134
- test "markup is indented" do
135
- ExpressTemplates::Markup::Tag.formatted do
136
- code = ExpressTemplates.compile &-> {ul { li { "*"*36 }}}
137
- assert_equal "\n<ul>\n <li>#{"*"*36}</li>\n</ul>\n", eval(code)
138
- end
139
- end
140
-
141
- test "print doctype for HTML5 document version" do
142
- assert_equal '"<!DOCTYPE html>"', ExpressTemplates::Markup::Doctype.new.compile
143
- end
144
-
145
- test "void tags do not have trailing slash" do
146
- assert_equal '"<img>"', ExpressTemplates::Markup::Img.new.compile
147
- end
148
-
149
- end
@@ -1,42 +0,0 @@
1
- require 'test_helper'
2
-
3
- class WrapperTest < ActiveSupport::TestCase
4
-
5
- Wrapper = ExpressTemplates::Markup::Wrapper
6
-
7
- test "name compiles to just name" do
8
- assert_equal '%Q(#{foo})', Interpolator.transform(Wrapper.new('foo').compile)
9
- end
10
-
11
- test "simple args are preserved" do
12
- wrapper = Wrapper.new('foo', "xyzzy", 'bar', "baz", 1, false, 3)
13
- assert_equal '%Q(#{foo("xyzzy", "bar", "baz", 1, false, 3)})', Interpolator.transform(wrapper.compile)
14
- end
15
-
16
- test "args are preserved" do
17
- wrapper = Wrapper.new('foo', "xyzzy", bar: "baz")
18
- assert_equal '%Q(#{foo("xyzzy", bar: "baz")})', Interpolator.transform(wrapper.compile)
19
- end
20
-
21
- test "something returning nil when wrapped and compiled, evals to an empty string" do
22
- assert_equal '', eval(Interpolator.transform(Wrapper.new('nil').compile))
23
- end
24
-
25
- test "double-braced args are evaluated in context" do
26
- wrapper = Wrapper.new('foo', "{{xyz}}", "{{zyx}}", bar: "baz")
27
- assert_equal '%Q(#{foo(xyz, zyx, bar: "baz")})', Interpolator.transform(wrapper.compile)
28
- end
29
-
30
- test "initializer block is preserved in compile" do
31
- wrapper = Wrapper.new('foo') { whatever }
32
- assert_equal '%Q(#{foo { whatever }})', Interpolator.transform(wrapper.compile)
33
- wrapper = Wrapper.new('foo', 'bar') { whatever }
34
- assert_equal '%Q(#{foo("bar") { whatever }})', Interpolator.transform(wrapper.compile)
35
- end
36
-
37
- test "lambda option values are evaluated in context" do
38
- wrapper = Wrapper.new('foo', bar: -> { something })
39
- assert_equal '%Q(#{foo(bar: (-> { something }).call)})', Interpolator.transform(wrapper.compile)
40
- end
41
-
42
- end
@@ -1,9 +0,0 @@
1
- require 'test_helper'
2
-
3
- class YielderTest < ActiveSupport::TestCase
4
-
5
- test "yielder preserves symbol args" do
6
- assert_equal 'yield(:foo)', ExpressTemplates::Markup::Yielder.new(:foo).compile
7
- end
8
-
9
- end