temple 0.8.2 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/test.yml +34 -0
  3. data/.gitignore +1 -0
  4. data/CHANGES +25 -1
  5. data/Gemfile +0 -1
  6. data/README.md +1 -1
  7. data/Rakefile +4 -11
  8. data/lib/temple/erb/engine.rb +2 -0
  9. data/lib/temple/erb/parser.rb +1 -1
  10. data/lib/temple/filters/ambles.rb +21 -0
  11. data/lib/temple/filters/string_splitter.rb +12 -1
  12. data/lib/temple/generator.rb +1 -1
  13. data/lib/temple/generators/rails_output_buffer.rb +3 -4
  14. data/lib/temple/mixins/grammar_dsl.rb +2 -1
  15. data/lib/temple/templates/rails.rb +6 -2
  16. data/lib/temple/templates/tilt.rb +1 -9
  17. data/lib/temple/utils.rb +4 -15
  18. data/lib/temple/version.rb +1 -1
  19. data/lib/temple.rb +1 -0
  20. data/spec/engine_spec.rb +189 -0
  21. data/{test/test_erb.rb → spec/erb_spec.rb} +12 -12
  22. data/spec/filter_spec.rb +29 -0
  23. data/{test/filters/test_code_merger.rb → spec/filters/code_merger_spec.rb} +7 -7
  24. data/{test/filters/test_control_flow.rb → spec/filters/control_flow_spec.rb} +13 -13
  25. data/{test/filters/test_dynamic_inliner.rb → spec/filters/dynamic_inliner_spec.rb} +18 -18
  26. data/{test/filters/test_eraser.rb → spec/filters/eraser_spec.rb} +9 -9
  27. data/{test/filters/test_escapable.rb → spec/filters/escapable_spec.rb} +10 -10
  28. data/{test/filters/test_multi_flattener.rb → spec/filters/multi_flattener_spec.rb} +4 -4
  29. data/{test/filters/test_static_analyzer.rb → spec/filters/static_analyzer_spec.rb} +6 -8
  30. data/{test/filters/test_static_merger.rb → spec/filters/static_merger_spec.rb} +7 -7
  31. data/spec/filters/string_splitter_spec.rb +50 -0
  32. data/spec/generator_spec.rb +158 -0
  33. data/spec/grammar_spec.rb +47 -0
  34. data/{test/html/test_attribute_merger.rb → spec/html/attribute_merger_spec.rb} +11 -11
  35. data/{test/html/test_attribute_remover.rb → spec/html/attribute_remover_spec.rb} +7 -7
  36. data/{test/html/test_attribute_sorter.rb → spec/html/attribute_sorter_spec.rb} +7 -7
  37. data/{test/html/test_fast.rb → spec/html/fast_spec.rb} +23 -23
  38. data/{test/html/test_pretty.rb → spec/html/pretty_spec.rb} +7 -7
  39. data/spec/map_spec.rb +39 -0
  40. data/{test/mixins/test_dispatcher.rb → spec/mixins/dispatcher_spec.rb} +12 -12
  41. data/{test/mixins/test_grammar_dsl.rb → spec/mixins/grammar_dsl_spec.rb} +19 -19
  42. data/{test/helper.rb → spec/spec_helper.rb} +5 -6
  43. data/{test/test_static_analyzer.rb → spec/static_analyzer_spec.rb} +6 -6
  44. data/spec/utils_spec.rb +39 -0
  45. data/temple.gemspec +3 -4
  46. metadata +34 -59
  47. data/.travis.yml +0 -30
  48. data/test/filters/test_string_splitter.rb +0 -25
  49. data/test/test_engine.rb +0 -189
  50. data/test/test_filter.rb +0 -29
  51. data/test/test_generator.rb +0 -158
  52. data/test/test_grammar.rb +0 -47
  53. data/test/test_map.rb +0 -39
  54. data/test/test_utils.rb +0 -39
data/temple.gemspec CHANGED
@@ -1,4 +1,3 @@
1
- # -*- encoding: utf-8 -*-
2
1
  require File.dirname(__FILE__) + '/lib/temple/version'
3
2
  require 'date'
4
3
 
@@ -18,12 +17,12 @@ Gem::Specification.new do |s|
18
17
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
18
  s.license = 'MIT'
20
19
 
21
- s.required_ruby_version = '>=1.9.2'
20
+ s.required_ruby_version = '>= 2.5.0'
22
21
 
23
22
  # Tilt is only development dependency because most parts of Temple
24
23
  # can be used without it.
25
24
  s.add_development_dependency('tilt')
26
- s.add_development_dependency('bacon')
25
+ s.add_development_dependency('rspec')
27
26
  s.add_development_dependency('rake')
28
- s.add_development_dependency('erubis')
27
+ s.add_development_dependency('erubi')
29
28
  end
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.8.2
4
+ version: 0.10.0
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: 2019-09-12 00:00:00.000000000 Z
12
+ date: 2023-01-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: tilt
@@ -26,7 +26,7 @@ dependencies:
26
26
  - !ruby/object:Gem::Version
27
27
  version: '0'
28
28
  - !ruby/object:Gem::Dependency
29
- name: bacon
29
+ name: rspec
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
32
  - - ">="
@@ -54,7 +54,7 @@ dependencies:
54
54
  - !ruby/object:Gem::Version
55
55
  version: '0'
56
56
  - !ruby/object:Gem::Dependency
57
- name: erubis
57
+ name: erubi
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
60
  - - ">="
@@ -75,8 +75,8 @@ executables: []
75
75
  extensions: []
76
76
  extra_rdoc_files: []
77
77
  files:
78
+ - ".github/workflows/test.yml"
78
79
  - ".gitignore"
79
- - ".travis.yml"
80
80
  - ".yardopts"
81
81
  - CHANGES
82
82
  - EXPRESSIONS.md
@@ -92,6 +92,7 @@ files:
92
92
  - lib/temple/erb/trimming.rb
93
93
  - lib/temple/exceptions.rb
94
94
  - lib/temple/filter.rb
95
+ - lib/temple/filters/ambles.rb
95
96
  - lib/temple/filters/code_merger.rb
96
97
  - lib/temple/filters/control_flow.rb
97
98
  - lib/temple/filters/dynamic_inliner.rb
@@ -132,32 +133,32 @@ files:
132
133
  - lib/temple/templates/tilt.rb
133
134
  - lib/temple/utils.rb
134
135
  - 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
135
161
  - temple.gemspec
136
- - test/filters/test_code_merger.rb
137
- - test/filters/test_control_flow.rb
138
- - test/filters/test_dynamic_inliner.rb
139
- - test/filters/test_eraser.rb
140
- - test/filters/test_escapable.rb
141
- - test/filters/test_multi_flattener.rb
142
- - test/filters/test_static_analyzer.rb
143
- - test/filters/test_static_merger.rb
144
- - test/filters/test_string_splitter.rb
145
- - test/helper.rb
146
- - test/html/test_attribute_merger.rb
147
- - test/html/test_attribute_remover.rb
148
- - test/html/test_attribute_sorter.rb
149
- - test/html/test_fast.rb
150
- - test/html/test_pretty.rb
151
- - test/mixins/test_dispatcher.rb
152
- - test/mixins/test_grammar_dsl.rb
153
- - test/test_engine.rb
154
- - test/test_erb.rb
155
- - test/test_filter.rb
156
- - test/test_generator.rb
157
- - test/test_grammar.rb
158
- - test/test_map.rb
159
- - test/test_static_analyzer.rb
160
- - test/test_utils.rb
161
162
  homepage: https://github.com/judofyr/temple
162
163
  licenses:
163
164
  - MIT
@@ -170,41 +171,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
170
171
  requirements:
171
172
  - - ">="
172
173
  - !ruby/object:Gem::Version
173
- version: 1.9.2
174
+ version: 2.5.0
174
175
  required_rubygems_version: !ruby/object:Gem::Requirement
175
176
  requirements:
176
177
  - - ">="
177
178
  - !ruby/object:Gem::Version
178
179
  version: '0'
179
180
  requirements: []
180
- rubyforge_project:
181
- rubygems_version: 2.6.11
181
+ rubygems_version: 3.2.5
182
182
  signing_key:
183
183
  specification_version: 4
184
184
  summary: Template compilation framework in Ruby
185
- test_files:
186
- - test/filters/test_code_merger.rb
187
- - test/filters/test_control_flow.rb
188
- - test/filters/test_dynamic_inliner.rb
189
- - test/filters/test_eraser.rb
190
- - test/filters/test_escapable.rb
191
- - test/filters/test_multi_flattener.rb
192
- - test/filters/test_static_analyzer.rb
193
- - test/filters/test_static_merger.rb
194
- - test/filters/test_string_splitter.rb
195
- - test/helper.rb
196
- - test/html/test_attribute_merger.rb
197
- - test/html/test_attribute_remover.rb
198
- - test/html/test_attribute_sorter.rb
199
- - test/html/test_fast.rb
200
- - test/html/test_pretty.rb
201
- - test/mixins/test_dispatcher.rb
202
- - test/mixins/test_grammar_dsl.rb
203
- - test/test_engine.rb
204
- - test/test_erb.rb
205
- - test/test_filter.rb
206
- - test/test_generator.rb
207
- - test/test_grammar.rb
208
- - test/test_map.rb
209
- - test/test_static_analyzer.rb
210
- - test/test_utils.rb
185
+ test_files: []
data/.travis.yml DELETED
@@ -1,30 +0,0 @@
1
- language: ruby
2
- dist: trusty
3
-
4
- cache: bundler
5
-
6
- rvm:
7
- - 1.9.3
8
- - 2.0.0
9
- - 2.1.10
10
- - 2.2.6
11
- - 2.3.3
12
- - ruby-head
13
- - jruby-19mode
14
- - rbx-3
15
-
16
- sudo: false
17
-
18
- env:
19
- - ESCAPE_UTILS=1
20
- - ""
21
-
22
- matrix:
23
- allow_failures:
24
- - rvm: ruby-head
25
- - rvm: rbx-3
26
- exclude:
27
- - rvm: jruby-19mode
28
- env: ESCAPE_UTILS=1
29
- - rvm: rbx-3
30
- env: ESCAPE_UTILS=1
@@ -1,25 +0,0 @@
1
- require 'helper'
2
- begin
3
- require 'ripper'
4
- rescue LoadError
5
- end
6
-
7
- if defined?(Ripper) && RUBY_VERSION >= "2.0.0"
8
- describe Temple::Filters::StringSplitter do
9
- before do
10
- @filter = Temple::Filters::StringSplitter.new
11
- end
12
-
13
- it 'should split :dynamic with string literal' do
14
- @filter.call([:dynamic, '"static#{dynamic}"']
15
- ).should.equal [:multi, [:static, 'static'], [:dynamic, 'dynamic']]
16
- end
17
-
18
- describe '.compile' do
19
- it 'should raise CompileError for non-string literals' do
20
- lambda { Temple::Filters::StringSplitter.compile('1') }.
21
- should.raise(Temple::FilterError)
22
- end
23
- end
24
- end
25
- end
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