temple 0.8.2 → 0.10.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/test.yml +35 -0
  3. data/.gitignore +1 -0
  4. data/CHANGES +34 -1
  5. data/Gemfile +0 -1
  6. data/README.md +1 -1
  7. data/Rakefile +4 -11
  8. data/lib/temple/engine.rb +1 -0
  9. data/lib/temple/erb/engine.rb +3 -0
  10. data/lib/temple/erb/parser.rb +2 -1
  11. data/lib/temple/erb/template.rb +1 -0
  12. data/lib/temple/erb/trimming.rb +1 -0
  13. data/lib/temple/exceptions.rb +1 -0
  14. data/lib/temple/filter.rb +1 -0
  15. data/lib/temple/filters/ambles.rb +22 -0
  16. data/lib/temple/filters/code_merger.rb +1 -0
  17. data/lib/temple/filters/control_flow.rb +1 -0
  18. data/lib/temple/filters/dynamic_inliner.rb +2 -1
  19. data/lib/temple/filters/encoding.rb +1 -0
  20. data/lib/temple/filters/eraser.rb +1 -0
  21. data/lib/temple/filters/escapable.rb +1 -0
  22. data/lib/temple/filters/multi_flattener.rb +1 -0
  23. data/lib/temple/filters/remove_bom.rb +1 -0
  24. data/lib/temple/filters/static_analyzer.rb +1 -0
  25. data/lib/temple/filters/static_merger.rb +1 -0
  26. data/lib/temple/filters/string_splitter.rb +13 -1
  27. data/lib/temple/filters/validator.rb +1 -0
  28. data/lib/temple/generator.rb +5 -2
  29. data/lib/temple/generators/array.rb +1 -0
  30. data/lib/temple/generators/array_buffer.rb +1 -0
  31. data/lib/temple/generators/erb.rb +1 -0
  32. data/lib/temple/generators/rails_output_buffer.rb +4 -4
  33. data/lib/temple/generators/string_buffer.rb +2 -1
  34. data/lib/temple/grammar.rb +1 -0
  35. data/lib/temple/html/attribute_merger.rb +1 -0
  36. data/lib/temple/html/attribute_remover.rb +1 -0
  37. data/lib/temple/html/attribute_sorter.rb +1 -0
  38. data/lib/temple/html/dispatcher.rb +1 -0
  39. data/lib/temple/html/fast.rb +1 -0
  40. data/lib/temple/html/filter.rb +1 -0
  41. data/lib/temple/html/pretty.rb +1 -0
  42. data/lib/temple/html/safe.rb +1 -0
  43. data/lib/temple/map.rb +1 -0
  44. data/lib/temple/mixins/dispatcher.rb +1 -0
  45. data/lib/temple/mixins/engine_dsl.rb +1 -0
  46. data/lib/temple/mixins/grammar_dsl.rb +4 -2
  47. data/lib/temple/mixins/options.rb +1 -0
  48. data/lib/temple/mixins/template.rb +1 -0
  49. data/lib/temple/parser.rb +1 -0
  50. data/lib/temple/static_analyzer.rb +1 -0
  51. data/lib/temple/templates/rails.rb +7 -2
  52. data/lib/temple/templates/tilt.rb +2 -9
  53. data/lib/temple/templates.rb +1 -0
  54. data/lib/temple/utils.rb +5 -15
  55. data/lib/temple/version.rb +2 -1
  56. data/lib/temple.rb +2 -0
  57. data/spec/engine_spec.rb +189 -0
  58. data/{test/test_erb.rb → spec/erb_spec.rb} +12 -12
  59. data/spec/filter_spec.rb +29 -0
  60. data/{test/filters/test_code_merger.rb → spec/filters/code_merger_spec.rb} +7 -7
  61. data/{test/filters/test_control_flow.rb → spec/filters/control_flow_spec.rb} +13 -13
  62. data/{test/filters/test_dynamic_inliner.rb → spec/filters/dynamic_inliner_spec.rb} +18 -18
  63. data/{test/filters/test_eraser.rb → spec/filters/eraser_spec.rb} +9 -9
  64. data/{test/filters/test_escapable.rb → spec/filters/escapable_spec.rb} +10 -10
  65. data/{test/filters/test_multi_flattener.rb → spec/filters/multi_flattener_spec.rb} +4 -4
  66. data/{test/filters/test_static_analyzer.rb → spec/filters/static_analyzer_spec.rb} +6 -8
  67. data/{test/filters/test_static_merger.rb → spec/filters/static_merger_spec.rb} +7 -7
  68. data/spec/filters/string_splitter_spec.rb +50 -0
  69. data/spec/generator_spec.rb +179 -0
  70. data/spec/grammar_spec.rb +47 -0
  71. data/{test/html/test_attribute_merger.rb → spec/html/attribute_merger_spec.rb} +11 -11
  72. data/{test/html/test_attribute_remover.rb → spec/html/attribute_remover_spec.rb} +7 -7
  73. data/{test/html/test_attribute_sorter.rb → spec/html/attribute_sorter_spec.rb} +7 -7
  74. data/{test/html/test_fast.rb → spec/html/fast_spec.rb} +23 -23
  75. data/{test/html/test_pretty.rb → spec/html/pretty_spec.rb} +7 -7
  76. data/spec/map_spec.rb +39 -0
  77. data/{test/mixins/test_dispatcher.rb → spec/mixins/dispatcher_spec.rb} +12 -12
  78. data/{test/mixins/test_grammar_dsl.rb → spec/mixins/grammar_dsl_spec.rb} +19 -19
  79. data/{test/helper.rb → spec/spec_helper.rb} +5 -6
  80. data/{test/test_static_analyzer.rb → spec/static_analyzer_spec.rb} +6 -6
  81. data/spec/utils_spec.rb +39 -0
  82. data/temple.gemspec +3 -4
  83. metadata +34 -59
  84. data/.travis.yml +0 -30
  85. data/test/filters/test_string_splitter.rb +0 -25
  86. data/test/test_engine.rb +0 -189
  87. data/test/test_filter.rb +0 -29
  88. data/test/test_generator.rb +0 -158
  89. data/test/test_grammar.rb +0 -47
  90. data/test/test_map.rb +0 -39
  91. data/test/test_utils.rb +0 -39
data/test/test_engine.rb DELETED
@@ -1,189 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require 'helper'
3
-
4
- class Callable1
5
- def call(exp)
6
- exp
7
- end
8
- end
9
-
10
- class Callable2
11
- def call(exp)
12
- exp
13
- end
14
- end
15
-
16
- class MySpecialFilter
17
- def initialize(opts = {})
18
- end
19
-
20
- def call(exp)
21
- exp
22
- end
23
- end
24
-
25
- class TestEngine < Temple::Engine
26
- use(:Parser) do |input|
27
- [:static, input]
28
- end
29
- use :MyFilter1, proc {|exp| exp }
30
- use :MyFilter2, proc {|exp| exp }
31
- use Temple::HTML::Pretty, pretty: true
32
- filter :MultiFlattener
33
- generator :ArrayBuffer
34
- use(:BeforeBeforeLast) { MySpecialFilter }
35
- use :BeforeLast, Callable1.new
36
- use(:Last) { Callable2.new }
37
- end
38
-
39
- describe Temple::Engine do
40
- it 'should build chain' do
41
- TestEngine.chain.size.should.equal 9
42
-
43
- TestEngine.chain[0].first.should.equal :Parser
44
- TestEngine.chain[0].size.should.equal 2
45
- TestEngine.chain[0].last.should.be.instance_of Proc
46
-
47
- TestEngine.chain[1].first.should.equal :MyFilter1
48
- TestEngine.chain[1].size.should.equal 2
49
- TestEngine.chain[1].last.should.be.instance_of Proc
50
-
51
- TestEngine.chain[2].first.should.equal :MyFilter2
52
- TestEngine.chain[2].size.should.equal 2
53
- TestEngine.chain[2].last.should.be.instance_of Proc
54
-
55
- TestEngine.chain[3].first.should.equal :'Temple::HTML::Pretty'
56
- TestEngine.chain[3].size.should.equal 2
57
- TestEngine.chain[3].last.should.be.instance_of Proc
58
-
59
- TestEngine.chain[4].first.should.equal :MultiFlattener
60
- TestEngine.chain[4].size.should.equal 2
61
- TestEngine.chain[4].last.should.be.instance_of Proc
62
-
63
- TestEngine.chain[5].first.should.equal :ArrayBuffer
64
- TestEngine.chain[5].size.should.equal 2
65
- TestEngine.chain[5].last.should.be.instance_of Proc
66
-
67
- TestEngine.chain[6].first.should.equal :BeforeBeforeLast
68
- TestEngine.chain[6].size.should.equal 2
69
- TestEngine.chain[6].last.should.be.instance_of Proc
70
-
71
- TestEngine.chain[7].first.should.equal :BeforeLast
72
- TestEngine.chain[7].size.should.equal 2
73
- TestEngine.chain[7].last.should.be.instance_of Proc
74
-
75
- TestEngine.chain[8].first.should.equal :Last
76
- TestEngine.chain[8].size.should.equal 2
77
- TestEngine.chain[8].last.should.be.instance_of Proc
78
- end
79
-
80
- it 'should instantiate chain' do
81
- call_chain = TestEngine.new.send(:call_chain)
82
- call_chain[0].should.be.instance_of Method
83
- call_chain[1].should.be.instance_of Method
84
- call_chain[2].should.be.instance_of Method
85
- call_chain[3].should.be.instance_of Temple::HTML::Pretty
86
- call_chain[4].should.be.instance_of Temple::Filters::MultiFlattener
87
- call_chain[5].should.be.instance_of Temple::Generators::ArrayBuffer
88
- call_chain[6].should.be.instance_of MySpecialFilter
89
- call_chain[7].should.be.instance_of Callable1
90
- call_chain[8].should.be.instance_of Callable2
91
- end
92
-
93
- it 'should have #append' do
94
- engine = TestEngine.new
95
- call_chain = engine.send(:call_chain)
96
- call_chain.size.should.equal 9
97
-
98
- engine.append :MyFilter3 do |exp|
99
- exp
100
- end
101
-
102
- TestEngine.chain.size.should.equal 9
103
- engine.chain.size.should.equal 10
104
- engine.chain[9].first.should.equal :MyFilter3
105
- engine.chain[9].size.should.equal 2
106
- engine.chain[9].last.should.be.instance_of Proc
107
-
108
- call_chain = engine.send(:call_chain)
109
- call_chain.size.should.equal 10
110
- call_chain[9].should.be.instance_of Method
111
- end
112
-
113
- it 'should have #prepend' do
114
- engine = TestEngine.new
115
- call_chain = engine.send(:call_chain)
116
- call_chain.size.should.equal 9
117
-
118
- engine.prepend :MyFilter0 do |exp|
119
- exp
120
- end
121
-
122
- TestEngine.chain.size.should.equal 9
123
- engine.chain.size.should.equal 10
124
- engine.chain[0].first.should.equal :MyFilter0
125
- engine.chain[0].size.should.equal 2
126
- engine.chain[0].last.should.be.instance_of Proc
127
- engine.chain[1].first.should.equal :Parser
128
-
129
- call_chain = engine.send(:call_chain)
130
- call_chain.size.should.equal 10
131
- call_chain[0].should.be.instance_of Method
132
- end
133
-
134
- it 'should have #after' do
135
- engine = TestEngine.new
136
- engine.after :Parser, :MyFilter0 do |exp|
137
- exp
138
- end
139
- TestEngine.chain.size.should.equal 9
140
- engine.chain.size.should.equal 10
141
- engine.chain[0].first.should.equal :Parser
142
- engine.chain[1].first.should.equal :MyFilter0
143
- engine.chain[2].first.should.equal :MyFilter1
144
- end
145
-
146
- it 'should have #before' do
147
- engine = TestEngine.new
148
- engine.before :MyFilter1, :MyFilter0 do |exp|
149
- exp
150
- end
151
- TestEngine.chain.size.should.equal 9
152
- engine.chain.size.should.equal 10
153
- engine.chain[0].first.should.equal :Parser
154
- engine.chain[1].first.should.equal :MyFilter0
155
- engine.chain[2].first.should.equal :MyFilter1
156
- end
157
-
158
- it 'should have #remove' do
159
- engine = TestEngine.new
160
- engine.remove :MyFilter1
161
- TestEngine.chain.size.should.equal 9
162
- engine.chain.size.should.equal 8
163
- engine.chain[0].first.should.equal :Parser
164
- engine.chain[1].first.should.equal :MyFilter2
165
-
166
- engine = TestEngine.new
167
- engine.remove /Last/
168
- engine.chain.size.should.equal 6
169
- end
170
-
171
- it 'should have #replace' do
172
- engine = TestEngine.new
173
- engine.replace :Parser, :MyParser do |exp|
174
- exp
175
- end
176
- engine.chain.size.should.equal 9
177
- engine.chain[0].first.should.equal :MyParser
178
- end
179
-
180
- it 'should work with inheritance' do
181
- inherited_engine = Class.new(TestEngine)
182
- inherited_engine.chain.size.should.equal 9
183
- inherited_engine.append :MyFilter3 do |exp|
184
- exp
185
- end
186
- inherited_engine.chain.size.should.equal 10
187
- TestEngine.chain.size.should.equal 9
188
- end
189
- end
data/test/test_filter.rb DELETED
@@ -1,29 +0,0 @@
1
- require 'helper'
2
-
3
- class SimpleFilter < Temple::Filter
4
- define_options :key
5
-
6
- def on_test(arg)
7
- [:on_test, arg]
8
- end
9
- end
10
-
11
- describe Temple::Filter do
12
- it 'should support options' do
13
- Temple::Filter.should.respond_to :default_options
14
- Temple::Filter.should.respond_to :set_default_options
15
- Temple::Filter.should.respond_to :define_options
16
- Temple::Filter.new.options.should.be.instance_of Temple::ImmutableMap
17
- SimpleFilter.new(key: 3).options[:key].should.equal 3
18
- end
19
-
20
- it 'should implement call' do
21
- Temple::Filter.new.call([:exp]).should.equal [:exp]
22
- end
23
-
24
- it 'should process expressions' do
25
- filter = SimpleFilter.new
26
- filter.call([:unhandled]).should.equal [:unhandled]
27
- filter.call([:test, 42]).should.equal [:on_test, 42]
28
- end
29
- end
@@ -1,158 +0,0 @@
1
- require 'helper'
2
-
3
- class SimpleGenerator < Temple::Generator
4
- def preamble
5
- "#{buffer} = BUFFER"
6
- end
7
-
8
- def postamble
9
- buffer
10
- end
11
-
12
- def on_static(s)
13
- concat "S:#{s}"
14
- end
15
-
16
- def on_dynamic(s)
17
- concat "D:#{s}"
18
- end
19
-
20
- def on_code(s)
21
- "C:#{s}"
22
- end
23
- end
24
-
25
- describe Temple::Generator do
26
- it 'should compile simple expressions' do
27
- gen = SimpleGenerator.new
28
-
29
- gen.call([:static, 'test']).should.equal '_buf = BUFFER; _buf << (S:test); _buf'
30
- gen.call([:dynamic, 'test']).should.equal '_buf = BUFFER; _buf << (D:test); _buf'
31
- gen.call([:code, 'test']).should.equal '_buf = BUFFER; C:test; _buf'
32
- end
33
-
34
- it 'should compile multi expression' do
35
- gen = SimpleGenerator.new(buffer: "VAR")
36
- gen.call([:multi,
37
- [:static, "static"],
38
- [:dynamic, "dynamic"],
39
- [:code, "code"]
40
- ]).should.equal 'VAR = BUFFER; VAR << (S:static); VAR << (D:dynamic); C:code; VAR'
41
- end
42
-
43
- it 'should compile capture' do
44
- gen = SimpleGenerator.new(buffer: "VAR", capture_generator: SimpleGenerator)
45
- gen.call([:capture, "foo",
46
- [:static, "test"]
47
- ]).should.equal 'VAR = BUFFER; foo = BUFFER; foo << (S:test); foo; VAR'
48
- end
49
-
50
- it 'should compile capture with multi' do
51
- gen = SimpleGenerator.new(buffer: "VAR", capture_generator: SimpleGenerator)
52
- gen.call([:multi,
53
- [:static, "before"],
54
-
55
- [:capture, "foo", [:multi,
56
- [:static, "static"],
57
- [:dynamic, "dynamic"],
58
- [:code, "code"]]],
59
-
60
- [:static, "after"]
61
- ]).should.equal 'VAR = BUFFER; VAR << (S:before); foo = BUFFER; foo << (S:static); ' +
62
- 'foo << (D:dynamic); C:code; foo; VAR << (S:after); VAR'
63
- end
64
-
65
- it 'should compile newlines' do
66
- gen = SimpleGenerator.new(buffer: "VAR")
67
- gen.call([:multi,
68
- [:static, "static"],
69
- [:newline],
70
- [:dynamic, "dynamic"],
71
- [:newline],
72
- [:code, "code"]
73
- ]).should.equal "VAR = BUFFER; VAR << (S:static); \n; " +
74
- "VAR << (D:dynamic); \n; C:code; VAR"
75
- end
76
- end
77
-
78
- describe Temple::Generators::Array do
79
- it 'should compile simple expressions' do
80
- gen = Temple::Generators::Array.new(freeze_static: false)
81
- gen.call([:static, 'test']).should.equal '_buf = []; _buf << ("test"); _buf'
82
- gen.call([:dynamic, 'test']).should.equal '_buf = []; _buf << (test); _buf'
83
- gen.call([:code, 'test']).should.equal '_buf = []; test; _buf'
84
-
85
- gen.call([:multi, [:static, 'a'], [:static, 'b']]).should.equal '_buf = []; _buf << ("a"); _buf << ("b"); _buf'
86
- gen.call([:multi, [:static, 'a'], [:dynamic, 'b']]).should.equal '_buf = []; _buf << ("a"); _buf << (b); _buf'
87
- end
88
-
89
- it 'should freeze static' do
90
- gen = Temple::Generators::Array.new(freeze_static: true)
91
- gen.call([:static, 'test']).should.equal '_buf = []; _buf << ("test".freeze); _buf'
92
- end
93
- end
94
-
95
- describe Temple::Generators::ArrayBuffer do
96
- it 'should compile simple expressions' do
97
- gen = Temple::Generators::ArrayBuffer.new(freeze_static: false)
98
- gen.call([:static, 'test']).should.equal '_buf = "test"'
99
- gen.call([:dynamic, 'test']).should.equal '_buf = (test).to_s'
100
- gen.call([:code, 'test']).should.equal '_buf = []; test; _buf = _buf.join("")'
101
-
102
- gen.call([:multi, [:static, 'a'], [:static, 'b']]).should.equal '_buf = []; _buf << ("a"); _buf << ("b"); _buf = _buf.join("")'
103
- gen.call([:multi, [:static, 'a'], [:dynamic, 'b']]).should.equal '_buf = []; _buf << ("a"); _buf << (b); _buf = _buf.join("")'
104
- end
105
-
106
- it 'should freeze static' do
107
- gen = Temple::Generators::ArrayBuffer.new(freeze_static: true)
108
- gen.call([:static, 'test']).should.equal '_buf = "test"'
109
- gen.call([:multi, [:dynamic, '1'], [:static, 'test']]).should.equal '_buf = []; _buf << (1); _buf << ("test".freeze); _buf = _buf.join("".freeze)'
110
- end
111
- end
112
-
113
- describe Temple::Generators::StringBuffer do
114
- it 'should compile simple expressions' do
115
- gen = Temple::Generators::StringBuffer.new(freeze_static: false)
116
- gen.call([:static, 'test']).should.equal '_buf = "test"'
117
- gen.call([:dynamic, 'test']).should.equal '_buf = (test).to_s'
118
- gen.call([:code, 'test']).should.equal '_buf = \'\'; test; _buf'
119
-
120
- gen.call([:multi, [:static, 'a'], [:static, 'b']]).should.equal '_buf = \'\'; _buf << ("a"); _buf << ("b"); _buf'
121
- gen.call([:multi, [:static, 'a'], [:dynamic, 'b']]).should.equal '_buf = \'\'; _buf << ("a"); _buf << ((b).to_s); _buf'
122
- end
123
-
124
- it 'should freeze static' do
125
- gen = Temple::Generators::StringBuffer.new(freeze_static: true)
126
- gen.call([:static, 'test']).should.equal '_buf = "test"'
127
- gen.call([:multi, [:dynamic, '1'], [:static, 'test']]).should.equal '_buf = \'\'; _buf << ((1).to_s); _buf << ("test".freeze); _buf'
128
- end
129
- end
130
-
131
- describe Temple::Generators::ERB do
132
- it 'should compile simple expressions' do
133
- gen = Temple::Generators::ERB.new
134
- gen.call([:static, 'test']).should.equal 'test'
135
- gen.call([:dynamic, 'test']).should.equal '<%= test %>'
136
- gen.call([:code, 'test']).should.equal '<% test %>'
137
-
138
- gen.call([:multi, [:static, 'a'], [:static, 'b']]).should.equal 'ab'
139
- gen.call([:multi, [:static, 'a'], [:dynamic, 'b']]).should.equal 'a<%= b %>'
140
- end
141
- end
142
-
143
- describe Temple::Generators::RailsOutputBuffer do
144
- it 'should compile simple expressions' do
145
- gen = Temple::Generators::RailsOutputBuffer.new(freeze_static: false)
146
- gen.call([:static, 'test']).should.equal '@output_buffer = ActiveSupport::SafeBuffer.new; ' +
147
- '@output_buffer.safe_concat(("test")); @output_buffer'
148
- gen.call([:dynamic, 'test']).should.equal '@output_buffer = ActiveSupport::SafeBuffer.new; ' +
149
- '@output_buffer.safe_concat(((test).to_s)); @output_buffer'
150
- gen.call([:code, 'test']).should.equal '@output_buffer = ActiveSupport::SafeBuffer.new; ' +
151
- 'test; @output_buffer'
152
- end
153
-
154
- it 'should freeze static' do
155
- gen = Temple::Generators::RailsOutputBuffer.new(freeze_static: true)
156
- gen.call([:static, 'test']).should.equal '@output_buffer = ActiveSupport::SafeBuffer.new; @output_buffer.safe_concat(("test".freeze)); @output_buffer'
157
- end
158
- end
data/test/test_grammar.rb DELETED
@@ -1,47 +0,0 @@
1
- require 'helper'
2
-
3
- describe Temple::Grammar do
4
- it 'should match core expressions' do
5
- Temple::Grammar.should.match [:multi]
6
- Temple::Grammar.should.match [:multi, [:multi]]
7
- Temple::Grammar.should.match [:static, 'Text']
8
- Temple::Grammar.should.match [:dynamic, 'Text']
9
- Temple::Grammar.should.match [:code, 'Text']
10
- Temple::Grammar.should.match [:capture, 'Text', [:multi]]
11
- Temple::Grammar.should.match [:newline]
12
- end
13
-
14
- it 'should not match invalid core expressions' do
15
- Temple::Grammar.should.not.match [:multi, 'String']
16
- Temple::Grammar.should.not.match [:static]
17
- Temple::Grammar.should.not.match [:dynamic, 1]
18
- Temple::Grammar.should.not.match [:code, :sym]
19
- Temple::Grammar.should.not.match [:capture, [:multi]]
20
- Temple::Grammar.should.not.match [:newline, [:multi]]
21
- end
22
-
23
- it 'should match control flow expressions' do
24
- Temple::Grammar.should.match [:if, 'Condition', [:multi]]
25
- Temple::Grammar.should.match [:if, 'Condition', [:multi], [:multi]]
26
- Temple::Grammar.should.match [:block, 'Loop', [:multi]]
27
- Temple::Grammar.should.match [:case, 'Arg', ['Cond1', [:multi]], ['Cond1', [:multi]], [:else, [:multi]]]
28
- Temple::Grammar.should.not.match [:case, 'Arg', [:sym, [:multi]]]
29
- Temple::Grammar.should.match [:cond, ['Cond1', [:multi]], ['Cond2', [:multi]], [:else, [:multi]]]
30
- Temple::Grammar.should.not.match [:cond, [:sym, [:multi]]]
31
- end
32
-
33
- it 'should match escape expression' do
34
- Temple::Grammar.should.match [:escape, true, [:multi]]
35
- Temple::Grammar.should.match [:escape, false, [:multi]]
36
- end
37
-
38
- it 'should match html expressions' do
39
- Temple::Grammar.should.match [:html, :doctype, 'Doctype']
40
- Temple::Grammar.should.match [:html, :comment, [:multi]]
41
- Temple::Grammar.should.match [:html, :tag, 'Tag', [:multi]]
42
- Temple::Grammar.should.match [:html, :tag, 'Tag', [:multi], [:multi]]
43
- Temple::Grammar.should.match [:html, :tag, 'Tag', [:multi], [:static, 'Text']]
44
- Temple::Grammar.should.match [:html, :tag, 'Tag', [:html, :attrs, [:html, :attr, 'id',
45
- [:static, 'val']]], [:static, 'Text']]
46
- end
47
- end
data/test/test_map.rb DELETED
@@ -1,39 +0,0 @@
1
- require 'helper'
2
-
3
- describe Temple::ImmutableMap do
4
- it 'has read accessor' do
5
- hash = Temple::ImmutableMap.new({a: 1},{b: 2, a: 3})
6
- hash[:a].should.equal 1
7
- hash[:b].should.equal 2
8
- end
9
-
10
- it 'has include?' do
11
- hash = Temple::ImmutableMap.new({a: 1},{b: 2, a: 3})
12
- hash.should.include :a
13
- hash.should.include :b
14
- hash.should.not.include :c
15
- end
16
-
17
- it 'has values' do
18
- Temple::ImmutableMap.new({a: 1},{b: 2, a: 3}).values.sort.should.equal [1,2]
19
- end
20
-
21
- it 'has keys' do
22
- Temple::ImmutableMap.new({a: 1},{b: 2, a: 3}).keys.should.equal [:a,:b]
23
- end
24
-
25
- it 'has to_a' do
26
- Temple::ImmutableMap.new({a: 1},{b: 2, a: 3}).to_a.should.equal [[:a, 1], [:b, 2]]
27
- end
28
- end
29
-
30
- describe Temple::MutableMap do
31
- it 'has write accessor' do
32
- parent = {a: 1}
33
- hash = Temple::MutableMap.new(parent)
34
- hash[:a].should.equal 1
35
- hash[:a] = 2
36
- hash[:a].should.equal 2
37
- parent[:a].should.equal 1
38
- end
39
- end
data/test/test_utils.rb DELETED
@@ -1,39 +0,0 @@
1
- require 'helper'
2
-
3
- class UniqueTest
4
- include Temple::Utils
5
- end
6
-
7
- describe Temple::Utils do
8
- it 'has empty_exp?' do
9
- Temple::Utils.empty_exp?([:multi]).should.be.true
10
- Temple::Utils.empty_exp?([:multi, [:multi]]).should.be.true
11
- Temple::Utils.empty_exp?([:multi, [:multi, [:newline]], [:newline]]).should.be.true
12
- Temple::Utils.empty_exp?([:multi]).should.be.true
13
- Temple::Utils.empty_exp?([:multi, [:multi, [:static, 'text']]]).should.be.false
14
- Temple::Utils.empty_exp?([:multi, [:newline], [:multi, [:dynamic, 'text']]]).should.be.false
15
- end
16
-
17
- it 'has unique_name' do
18
- u = UniqueTest.new
19
- u.unique_name.should.equal '_uniquetest1'
20
- u.unique_name.should.equal '_uniquetest2'
21
- UniqueTest.new.unique_name.should.equal '_uniquetest1'
22
- end
23
-
24
- it 'has escape_html' do
25
- Temple::Utils.escape_html('<').should.equal '&lt;'
26
- end
27
-
28
- it 'should escape unsafe html strings' do
29
- with_html_safe do
30
- Temple::Utils.escape_html_safe('<').should.equal '&lt;'
31
- end
32
- end
33
-
34
- it 'should not escape safe html strings' do
35
- with_html_safe do
36
- Temple::Utils.escape_html_safe('<'.html_safe).should.equal '<'
37
- end
38
- end
39
- end