temple 0.9.1 → 0.10.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test.yml +2 -1
  3. data/CHANGES +21 -0
  4. data/Gemfile +0 -1
  5. data/Rakefile +0 -13
  6. data/lib/temple/engine.rb +1 -0
  7. data/lib/temple/erb/engine.rb +3 -0
  8. data/lib/temple/erb/parser.rb +1 -0
  9. data/lib/temple/erb/template.rb +1 -0
  10. data/lib/temple/erb/trimming.rb +1 -0
  11. data/lib/temple/exceptions.rb +1 -0
  12. data/lib/temple/filter.rb +1 -0
  13. data/lib/temple/filters/ambles.rb +1 -0
  14. data/lib/temple/filters/code_merger.rb +1 -0
  15. data/lib/temple/filters/control_flow.rb +1 -0
  16. data/lib/temple/filters/dynamic_inliner.rb +2 -1
  17. data/lib/temple/filters/dynamic_merger.rb +69 -0
  18. data/lib/temple/filters/encoding.rb +1 -0
  19. data/lib/temple/filters/eraser.rb +1 -0
  20. data/lib/temple/filters/escapable.rb +1 -0
  21. data/lib/temple/filters/multi_flattener.rb +1 -0
  22. data/lib/temple/filters/remove_bom.rb +1 -0
  23. data/lib/temple/filters/static_analyzer.rb +1 -0
  24. data/lib/temple/filters/static_merger.rb +1 -0
  25. data/lib/temple/filters/string_splitter.rb +2 -1
  26. data/lib/temple/filters/validator.rb +1 -0
  27. data/lib/temple/generator.rb +9 -12
  28. data/lib/temple/generators/array.rb +1 -0
  29. data/lib/temple/generators/array_buffer.rb +1 -0
  30. data/lib/temple/generators/erb.rb +1 -0
  31. data/lib/temple/generators/rails_output_buffer.rb +7 -3
  32. data/lib/temple/generators/string_buffer.rb +2 -1
  33. data/lib/temple/grammar.rb +1 -0
  34. data/lib/temple/html/attribute_merger.rb +1 -0
  35. data/lib/temple/html/attribute_remover.rb +1 -0
  36. data/lib/temple/html/attribute_sorter.rb +1 -0
  37. data/lib/temple/html/dispatcher.rb +1 -0
  38. data/lib/temple/html/fast.rb +1 -0
  39. data/lib/temple/html/filter.rb +1 -0
  40. data/lib/temple/html/pretty.rb +1 -0
  41. data/lib/temple/html/safe.rb +1 -0
  42. data/lib/temple/map.rb +1 -0
  43. data/lib/temple/mixins/dispatcher.rb +1 -0
  44. data/lib/temple/mixins/engine_dsl.rb +1 -0
  45. data/lib/temple/mixins/grammar_dsl.rb +2 -1
  46. data/lib/temple/mixins/options.rb +1 -0
  47. data/lib/temple/mixins/template.rb +1 -0
  48. data/lib/temple/parser.rb +1 -0
  49. data/lib/temple/static_analyzer.rb +1 -0
  50. data/lib/temple/templates/rails.rb +3 -2
  51. data/lib/temple/templates/tilt.rb +1 -0
  52. data/lib/temple/templates.rb +1 -0
  53. data/lib/temple/utils.rb +3 -1
  54. data/lib/temple/version.rb +2 -1
  55. data/lib/temple.rb +2 -0
  56. data/temple.gemspec +1 -3
  57. metadata +4 -28
  58. data/spec/engine_spec.rb +0 -189
  59. data/spec/erb_spec.rb +0 -61
  60. data/spec/filter_spec.rb +0 -29
  61. data/spec/filters/code_merger_spec.rb +0 -38
  62. data/spec/filters/control_flow_spec.rb +0 -90
  63. data/spec/filters/dynamic_inliner_spec.rb +0 -95
  64. data/spec/filters/eraser_spec.rb +0 -55
  65. data/spec/filters/escapable_spec.rb +0 -49
  66. data/spec/filters/multi_flattener_spec.rb +0 -33
  67. data/spec/filters/static_analyzer_spec.rb +0 -35
  68. data/spec/filters/static_merger_spec.rb +0 -41
  69. data/spec/filters/string_splitter_spec.rb +0 -50
  70. data/spec/generator_spec.rb +0 -167
  71. data/spec/grammar_spec.rb +0 -47
  72. data/spec/html/attribute_merger_spec.rb +0 -76
  73. data/spec/html/attribute_remover_spec.rb +0 -43
  74. data/spec/html/attribute_sorter_spec.rb +0 -48
  75. data/spec/html/fast_spec.rb +0 -97
  76. data/spec/html/pretty_spec.rb +0 -55
  77. data/spec/map_spec.rb +0 -39
  78. data/spec/mixins/dispatcher_spec.rb +0 -70
  79. data/spec/mixins/grammar_dsl_spec.rb +0 -86
  80. data/spec/spec_helper.rb +0 -29
  81. data/spec/static_analyzer_spec.rb +0 -39
  82. data/spec/utils_spec.rb +0 -39
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: temple
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.10.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Magnus Holm
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-10-25 00:00:00.000000000 Z
12
+ date: 2023-10-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: tilt
@@ -96,6 +96,7 @@ files:
96
96
  - lib/temple/filters/code_merger.rb
97
97
  - lib/temple/filters/control_flow.rb
98
98
  - lib/temple/filters/dynamic_inliner.rb
99
+ - lib/temple/filters/dynamic_merger.rb
99
100
  - lib/temple/filters/encoding.rb
100
101
  - lib/temple/filters/eraser.rb
101
102
  - lib/temple/filters/escapable.rb
@@ -133,31 +134,6 @@ files:
133
134
  - lib/temple/templates/tilt.rb
134
135
  - lib/temple/utils.rb
135
136
  - lib/temple/version.rb
136
- - spec/engine_spec.rb
137
- - spec/erb_spec.rb
138
- - spec/filter_spec.rb
139
- - spec/filters/code_merger_spec.rb
140
- - spec/filters/control_flow_spec.rb
141
- - spec/filters/dynamic_inliner_spec.rb
142
- - spec/filters/eraser_spec.rb
143
- - spec/filters/escapable_spec.rb
144
- - spec/filters/multi_flattener_spec.rb
145
- - spec/filters/static_analyzer_spec.rb
146
- - spec/filters/static_merger_spec.rb
147
- - spec/filters/string_splitter_spec.rb
148
- - spec/generator_spec.rb
149
- - spec/grammar_spec.rb
150
- - spec/html/attribute_merger_spec.rb
151
- - spec/html/attribute_remover_spec.rb
152
- - spec/html/attribute_sorter_spec.rb
153
- - spec/html/fast_spec.rb
154
- - spec/html/pretty_spec.rb
155
- - spec/map_spec.rb
156
- - spec/mixins/dispatcher_spec.rb
157
- - spec/mixins/grammar_dsl_spec.rb
158
- - spec/spec_helper.rb
159
- - spec/static_analyzer_spec.rb
160
- - spec/utils_spec.rb
161
137
  - temple.gemspec
162
138
  homepage: https://github.com/judofyr/temple
163
139
  licenses:
@@ -178,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
178
154
  - !ruby/object:Gem::Version
179
155
  version: '0'
180
156
  requirements: []
181
- rubygems_version: 3.3.7
157
+ rubygems_version: 3.4.10
182
158
  signing_key:
183
159
  specification_version: 4
184
160
  summary: Template compilation framework in Ruby
data/spec/engine_spec.rb DELETED
@@ -1,189 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require 'spec_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
- expect(TestEngine.chain.size).to eq(9)
42
-
43
- expect(TestEngine.chain[0].first).to eq(:Parser)
44
- expect(TestEngine.chain[0].size).to eq(2)
45
- expect(TestEngine.chain[0].last).to be_a(Proc)
46
-
47
- expect(TestEngine.chain[1].first).to eq(:MyFilter1)
48
- expect(TestEngine.chain[1].size).to eq(2)
49
- expect(TestEngine.chain[1].last).to be_a(Proc)
50
-
51
- expect(TestEngine.chain[2].first).to eq(:MyFilter2)
52
- expect(TestEngine.chain[2].size).to eq(2)
53
- expect(TestEngine.chain[2].last).to be_a(Proc)
54
-
55
- expect(TestEngine.chain[3].first).to eq(:'Temple::HTML::Pretty')
56
- expect(TestEngine.chain[3].size).to eq(2)
57
- expect(TestEngine.chain[3].last).to be_a(Proc)
58
-
59
- expect(TestEngine.chain[4].first).to eq(:MultiFlattener)
60
- expect(TestEngine.chain[4].size).to eq(2)
61
- expect(TestEngine.chain[4].last).to be_a(Proc)
62
-
63
- expect(TestEngine.chain[5].first).to eq(:ArrayBuffer)
64
- expect(TestEngine.chain[5].size).to eq(2)
65
- expect(TestEngine.chain[5].last).to be_a(Proc)
66
-
67
- expect(TestEngine.chain[6].first).to eq(:BeforeBeforeLast)
68
- expect(TestEngine.chain[6].size).to eq(2)
69
- expect(TestEngine.chain[6].last).to be_a(Proc)
70
-
71
- expect(TestEngine.chain[7].first).to eq(:BeforeLast)
72
- expect(TestEngine.chain[7].size).to eq(2)
73
- expect(TestEngine.chain[7].last).to be_a(Proc)
74
-
75
- expect(TestEngine.chain[8].first).to eq(:Last)
76
- expect(TestEngine.chain[8].size).to eq(2)
77
- expect(TestEngine.chain[8].last).to be_a(Proc)
78
- end
79
-
80
- it 'should instantiate chain' do
81
- call_chain = TestEngine.new.send(:call_chain)
82
- expect(call_chain[0]).to be_a(Method)
83
- expect(call_chain[1]).to be_a(Method)
84
- expect(call_chain[2]).to be_a(Method)
85
- expect(call_chain[3]).to be_a(Temple::HTML::Pretty)
86
- expect(call_chain[4]).to be_a(Temple::Filters::MultiFlattener)
87
- expect(call_chain[5]).to be_a(Temple::Generators::ArrayBuffer)
88
- expect(call_chain[6]).to be_a(MySpecialFilter)
89
- expect(call_chain[7]).to be_a(Callable1)
90
- expect(call_chain[8]).to be_a(Callable2)
91
- end
92
-
93
- it 'should have #append' do
94
- engine = TestEngine.new
95
- call_chain = engine.send(:call_chain)
96
- expect(call_chain.size).to eq(9)
97
-
98
- engine.append :MyFilter3 do |exp|
99
- exp
100
- end
101
-
102
- expect(TestEngine.chain.size).to eq(9)
103
- expect(engine.chain.size).to eq(10)
104
- expect(engine.chain[9].first).to eq(:MyFilter3)
105
- expect(engine.chain[9].size).to eq(2)
106
- expect(engine.chain[9].last).to be_a(Proc)
107
-
108
- call_chain = engine.send(:call_chain)
109
- expect(call_chain.size).to eq(10)
110
- expect(call_chain[9]).to be_a(Method)
111
- end
112
-
113
- it 'should have #prepend' do
114
- engine = TestEngine.new
115
- call_chain = engine.send(:call_chain)
116
- expect(call_chain.size).to eq(9)
117
-
118
- engine.prepend :MyFilter0 do |exp|
119
- exp
120
- end
121
-
122
- expect(TestEngine.chain.size).to eq(9)
123
- expect(engine.chain.size).to eq(10)
124
- expect(engine.chain[0].first).to eq(:MyFilter0)
125
- expect(engine.chain[0].size).to eq(2)
126
- expect(engine.chain[0].last).to be_a(Proc)
127
- expect(engine.chain[1].first).to eq(:Parser)
128
-
129
- call_chain = engine.send(:call_chain)
130
- expect(call_chain.size).to eq(10)
131
- expect(call_chain[0]).to be_a(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
- expect(TestEngine.chain.size).to eq(9)
140
- expect(engine.chain.size).to eq(10)
141
- expect(engine.chain[0].first).to eq(:Parser)
142
- expect(engine.chain[1].first).to eq(:MyFilter0)
143
- expect(engine.chain[2].first).to eq(: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
- expect(TestEngine.chain.size).to eq(9)
152
- expect(engine.chain.size).to eq(10)
153
- expect(engine.chain[0].first).to eq(:Parser)
154
- expect(engine.chain[1].first).to eq(:MyFilter0)
155
- expect(engine.chain[2].first).to eq(:MyFilter1)
156
- end
157
-
158
- it 'should have #remove' do
159
- engine = TestEngine.new
160
- engine.remove :MyFilter1
161
- expect(TestEngine.chain.size).to eq(9)
162
- expect(engine.chain.size).to eq(8)
163
- expect(engine.chain[0].first).to eq(:Parser)
164
- expect(engine.chain[1].first).to eq(:MyFilter2)
165
-
166
- engine = TestEngine.new
167
- engine.remove /Last/
168
- expect(engine.chain.size).to eq(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
- expect(engine.chain.size).to eq(9)
177
- expect(engine.chain[0].first).to eq(:MyParser)
178
- end
179
-
180
- it 'should work with inheritance' do
181
- inherited_engine = Class.new(TestEngine)
182
- expect(inherited_engine.chain.size).to eq(9)
183
- inherited_engine.append :MyFilter3 do |exp|
184
- exp
185
- end
186
- expect(inherited_engine.chain.size).to eq(10)
187
- expect(TestEngine.chain.size).to eq(9)
188
- end
189
- end
data/spec/erb_spec.rb DELETED
@@ -1,61 +0,0 @@
1
- require 'spec_helper'
2
- require 'tilt/erubi'
3
-
4
- describe Temple::ERB::Engine do
5
- it 'should compile erb' do
6
- src = %q{
7
- %% hi
8
- = hello
9
- <% 3.times do |n| %>
10
- * <%= n %>
11
- <% end %>
12
- }
13
-
14
- expect(erb(src)).to eq(erubi(src))
15
- end
16
-
17
- it 'should recognize comments' do
18
- src = %q{
19
- hello
20
- <%# comment -- ignored -- useful in testing %>
21
- world}
22
-
23
- expect(erb(src)).to eq(erubi(src))
24
- end
25
-
26
- it 'should recognize <%% and %%>' do
27
- src = %q{
28
- <%%
29
- <% if true %>
30
- %%>
31
- <% end %>
32
- }
33
-
34
- expect(erb(src)).to eq("\n<%\n %>\n")
35
- end
36
-
37
- it 'should escape automatically' do
38
- src = '<%== "<" %>'
39
- ans = '&lt;'
40
- expect(erb(src)).to eq(ans)
41
- end
42
-
43
- it 'should support = to disable automatic escape' do
44
- src = '<%= "<" %>'
45
- ans = '<'
46
- expect(erb(src)).to eq(ans)
47
- end
48
-
49
- it 'should support trim mode' do
50
- src = %q{
51
- %% hi
52
- = hello
53
- <% 3.times do |n| %>
54
- * <%= n %>
55
- <% end %>
56
- }
57
-
58
- expect(erb(src, trim: true)).to eq(erubi(src, trim: true))
59
- expect(erb(src, trim: false)).to eq(erubi(src, trim: false))
60
- end
61
- end
data/spec/filter_spec.rb DELETED
@@ -1,29 +0,0 @@
1
- require 'spec_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
- expect(Temple::Filter).to respond_to(:default_options)
14
- expect(Temple::Filter).to respond_to(:set_default_options)
15
- expect(Temple::Filter).to respond_to(:define_options)
16
- expect(Temple::Filter.new.options).to be_a(Temple::ImmutableMap)
17
- expect(SimpleFilter.new(key: 3).options[:key]).to eq(3)
18
- end
19
-
20
- it 'should implement call' do
21
- expect(Temple::Filter.new.call([:exp])).to eq([:exp])
22
- end
23
-
24
- it 'should process expressions' do
25
- filter = SimpleFilter.new
26
- expect(filter.call([:unhandled])).to eq([:unhandled])
27
- expect(filter.call([:test, 42])).to eq([:on_test, 42])
28
- end
29
- end
@@ -1,38 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Temple::Filters::CodeMerger do
4
- before do
5
- @filter = Temple::Filters::CodeMerger.new
6
- end
7
-
8
- it 'should merge serveral codes' do
9
- expect(@filter.call([:multi,
10
- [:code, "a"],
11
- [:code, "b"],
12
- [:code, "c"]
13
- ])).to eq [:code, "a; b; c"]
14
- end
15
-
16
- it 'should merge serveral codes around static' do
17
- expect(@filter.call([:multi,
18
- [:code, "a"],
19
- [:code, "b"],
20
- [:static, "123"],
21
- [:code, "a"],
22
- [:code, "b"]
23
- ])).to eq [:multi,
24
- [:code, "a; b"],
25
- [:static, "123"],
26
- [:code, "a; b"]
27
- ]
28
- end
29
-
30
- it 'should merge serveral codes with newlines' do
31
- expect(@filter.call([:multi,
32
- [:code, "a"],
33
- [:code, "b"],
34
- [:newline],
35
- [:code, "c"]
36
- ])).to eq [:code, "a; b\nc"]
37
- end
38
- end
@@ -1,90 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Temple::Filters::ControlFlow do
4
- before do
5
- @filter = Temple::Filters::ControlFlow.new
6
- end
7
-
8
- it 'should process blocks' do
9
- expect(@filter.call([:block, 'loop do',
10
- [:static, 'Hello']
11
- ])).to eq [:multi,
12
- [:code, 'loop do'],
13
- [:static, 'Hello'],
14
- [:code, 'end']]
15
- end
16
-
17
- it 'should process if' do
18
- expect(@filter.call([:if, 'condition',
19
- [:static, 'Hello']
20
- ])).to eq [:multi,
21
- [:code, 'if condition'],
22
- [:static, 'Hello'],
23
- [:code, 'end']
24
- ]
25
- end
26
-
27
- it 'should process if with else' do
28
- expect(@filter.call([:if, 'condition',
29
- [:static, 'True'],
30
- [:static, 'False']
31
- ])).to eq [:multi,
32
- [:code, 'if condition'],
33
- [:static, 'True'],
34
- [:code, 'else'],
35
- [:static, 'False'],
36
- [:code, 'end']
37
- ]
38
- end
39
-
40
- it 'should create elsif' do
41
- expect(@filter.call([:if, 'condition1',
42
- [:static, '1'],
43
- [:if, 'condition2',
44
- [:static, '2'],
45
- [:static, '3']]
46
- ])).to eq [:multi,
47
- [:code, 'if condition1'],
48
- [:static, '1'],
49
- [:code, 'elsif condition2'],
50
- [:static, '2'],
51
- [:code, 'else'],
52
- [:static, '3'],
53
- [:code, 'end']
54
- ]
55
- end
56
-
57
- it 'should process cond' do
58
- expect(@filter.call([:cond,
59
- ['cond1', [:exp1]],
60
- ['cond2', [:exp2]],
61
- [:else, [:exp3]],
62
- ])).to eq [:multi,
63
- [:code, 'case'],
64
- [:code, 'when cond1'],
65
- [:exp1],
66
- [:code, 'when cond2'],
67
- [:exp2],
68
- [:code, 'else'],
69
- [:exp3],
70
- [:code, 'end']
71
- ]
72
- end
73
-
74
- it 'should process case' do
75
- expect(@filter.call([:case, 'var',
76
- ['Array', [:exp1]],
77
- ['String', [:exp2]],
78
- [:else, [:exp3]],
79
- ])).to eq [:multi,
80
- [:code, 'case (var)'],
81
- [:code, 'when Array'],
82
- [:exp1],
83
- [:code, 'when String'],
84
- [:exp2],
85
- [:code, 'else'],
86
- [:exp3],
87
- [:code, 'end']
88
- ]
89
- end
90
- end
@@ -1,95 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Temple::Filters::DynamicInliner do
4
- before do
5
- @filter = Temple::Filters::DynamicInliner.new
6
- end
7
-
8
- it 'should compile several statics into dynamic' do
9
- expect(@filter.call([:multi,
10
- [:static, "Hello "],
11
- [:static, "World\n "],
12
- [:static, "Have a nice day"]
13
- ])).to eq [:dynamic, '"Hello World\n Have a nice day"']
14
- end
15
-
16
- it 'should compile several dynamics into dynamic' do
17
- expect(@filter.call([:multi,
18
- [:dynamic, "@hello"],
19
- [:dynamic, "@world"],
20
- [:dynamic, "@yeah"]
21
- ])).to eq [:dynamic, '"#{@hello}#{@world}#{@yeah}"']
22
- end
23
-
24
- it 'should compile static and dynamic into dynamic' do
25
- expect(@filter.call([:multi,
26
- [:static, "Hello"],
27
- [:dynamic, "@world"],
28
- [:dynamic, "@yeah"],
29
- [:static, "Nice"]
30
- ])).to eq [:dynamic, '"Hello#{@world}#{@yeah}Nice"']
31
- end
32
-
33
- it 'should merge statics and dynamics around a code' do
34
- expect(@filter.call([:multi,
35
- [:static, "Hello "],
36
- [:dynamic, "@world"],
37
- [:code, "Oh yeah"],
38
- [:dynamic, "@yeah"],
39
- [:static, "Once more"]
40
- ])).to eq [:multi,
41
- [:dynamic, '"Hello #{@world}"'],
42
- [:code, "Oh yeah"],
43
- [:dynamic, '"#{@yeah}Once more"']
44
- ]
45
- end
46
-
47
- it 'should keep codes intact' do
48
- expect(@filter.call([:multi, [:code, 'foo']])).to eq([:code, 'foo'])
49
- end
50
-
51
- it 'should keep single statics intact' do
52
- expect(@filter.call([:multi, [:static, 'foo']])).to eq([:static, 'foo'])
53
- end
54
-
55
- it 'should keep single dynamic intact' do
56
- expect(@filter.call([:multi, [:dynamic, 'foo']])).to eq([:dynamic, 'foo'])
57
- end
58
-
59
- it 'should inline inside multi' do
60
- expect(@filter.call([:multi,
61
- [:static, "Hello "],
62
- [:dynamic, "@world"],
63
- [:multi,
64
- [:static, "Hello "],
65
- [:dynamic, "@world"]],
66
- [:static, "Hello "],
67
- [:dynamic, "@world"]
68
- ])).to eq [:multi,
69
- [:dynamic, '"Hello #{@world}"'],
70
- [:dynamic, '"Hello #{@world}"'],
71
- [:dynamic, '"Hello #{@world}"']
72
- ]
73
- end
74
-
75
- it 'should merge across newlines' do
76
- exp = expect(@filter.call([:multi,
77
- [:static, "Hello \n"],
78
- [:newline],
79
- [:dynamic, "@world"],
80
- [:newline]
81
- ])).to eq [:dynamic, ['"Hello \n"', '"#{@world}"', '""'].join("\\\n")]
82
- end
83
-
84
- it 'should compile static followed by newline' do
85
- expect(@filter.call([:multi,
86
- [:static, "Hello \n"],
87
- [:newline],
88
- [:code, "world"]
89
- ])).to eq [:multi,
90
- [:static, "Hello \n"],
91
- [:newline],
92
- [:code, "world"]
93
- ]
94
- end
95
- end
@@ -1,55 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Temple::Filters::Eraser do
4
- it 'should respect keep' do
5
- eraser = Temple::Filters::Eraser.new(keep: [:a])
6
- expect(eraser.call([:multi,
7
- [:a],
8
- [:b],
9
- [:c]
10
- ])).to eq [:multi,
11
- [:a],
12
- [:multi],
13
- [:multi]
14
- ]
15
- end
16
-
17
- it 'should respect erase' do
18
- eraser = Temple::Filters::Eraser.new(erase: [:a])
19
- expect(eraser.call([:multi,
20
- [:a],
21
- [:b],
22
- [:c]
23
- ])).to eq [:multi,
24
- [:multi],
25
- [:b],
26
- [:c]
27
- ]
28
- end
29
-
30
- it 'should choose erase over keep' do
31
- eraser = Temple::Filters::Eraser.new(keep: [:a, :b], erase: [:a])
32
- expect(eraser.call([:multi,
33
- [:a],
34
- [:b],
35
- [:c]
36
- ])).to eq [:multi,
37
- [:multi],
38
- [:b],
39
- [:multi]
40
- ]
41
- end
42
-
43
- it 'should erase nested types' do
44
- eraser = Temple::Filters::Eraser.new(erase: [[:a, :b]])
45
- expect(eraser.call([:multi,
46
- [:a, :a],
47
- [:a, :b],
48
- [:b]
49
- ])).to eq [:multi,
50
- [:a, :a],
51
- [:multi],
52
- [:b]
53
- ]
54
- end
55
- end
@@ -1,49 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Temple::Filters::Escapable do
4
- before do
5
- @filter = Temple::Filters::Escapable.new
6
- end
7
-
8
- it 'should handle escape expressions' do
9
- expect(@filter.call([:escape, true,
10
- [:multi,
11
- [:static, "a < b"],
12
- [:dynamic, "ruby_method"]]
13
- ])).to eq [:multi,
14
- [:static, "a &lt; b"],
15
- [:dynamic, "::Temple::Utils.escape_html((ruby_method))"],
16
- ]
17
- end
18
-
19
- it 'should keep codes intact' do
20
- exp = [:multi, [:code, 'foo']]
21
- expect(@filter.call(exp)).to eq(exp)
22
- end
23
-
24
- it 'should keep statics intact' do
25
- exp = [:multi, [:static, '<']]
26
- expect(@filter.call(exp)).to eq(exp)
27
- end
28
-
29
- it 'should keep dynamic intact' do
30
- exp = [:multi, [:dynamic, 'foo']]
31
- expect(@filter.call(exp)).to eq(exp)
32
- end
33
-
34
- it 'should have use_html_safe option' do
35
- with_html_safe do
36
- filter = Temple::Filters::Escapable.new(use_html_safe: true)
37
- expect(filter.call([:escape, true,
38
- [:static, Temple::HTML::SafeString.new("a < b")]
39
- ])).to eq [:static, "a < b"]
40
- end
41
- end
42
-
43
- it 'should support censoring' do
44
- filter = Temple::Filters::Escapable.new(escape_code: '(%s).gsub("Temple sucks", "Temple rocks")')
45
- expect(filter.call([:escape, true,
46
- [:static, "~~ Temple sucks ~~"]
47
- ])).to eq [:static, "~~ Temple rocks ~~"]
48
- end
49
- end
@@ -1,33 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Temple::Filters::MultiFlattener do
4
- before do
5
- @filter = Temple::Filters::MultiFlattener.new
6
- end
7
-
8
- it 'should flatten nested multi expressions' do
9
- expect(@filter.call([:multi,
10
- [:static, "a"],
11
- [:multi,
12
- [:dynamic, "aa"],
13
- [:multi,
14
- [:static, "aaa"],
15
- [:static, "aab"],
16
- ],
17
- [:dynamic, "ab"],
18
- ],
19
- [:static, "b"],
20
- ])).to eq [:multi,
21
- [:static, "a"],
22
- [:dynamic, "aa"],
23
- [:static, "aaa"],
24
- [:static, "aab"],
25
- [:dynamic, "ab"],
26
- [:static, "b"],
27
- ]
28
- end
29
-
30
- it 'should return first element' do
31
- expect(@filter.call([:multi, [:code, 'foo']])).to eq([:code, 'foo'])
32
- end
33
- end