temple 0.6.7 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/test.yml +34 -0
  3. data/.gitignore +1 -0
  4. data/CHANGES +106 -1
  5. data/EXPRESSIONS.md +3 -2
  6. data/Gemfile +0 -1
  7. data/README.md +14 -10
  8. data/Rakefile +4 -11
  9. data/lib/temple/engine.rb +7 -3
  10. data/lib/temple/erb/engine.rb +5 -3
  11. data/lib/temple/erb/parser.rb +1 -1
  12. data/lib/temple/erb/trimming.rb +11 -26
  13. data/lib/temple/filters/ambles.rb +21 -0
  14. data/lib/temple/filters/encoding.rb +1 -1
  15. data/lib/temple/filters/eraser.rb +1 -1
  16. data/lib/temple/filters/escapable.rb +2 -2
  17. data/lib/temple/filters/remove_bom.rb +2 -9
  18. data/lib/temple/filters/static_analyzer.rb +30 -0
  19. data/lib/temple/filters/string_splitter.rb +141 -0
  20. data/lib/temple/filters/validator.rb +1 -1
  21. data/lib/temple/generator.rb +32 -6
  22. data/lib/temple/generators/array.rb +2 -2
  23. data/lib/temple/generators/array_buffer.rb +6 -5
  24. data/lib/temple/generators/erb.rb +1 -5
  25. data/lib/temple/generators/rails_output_buffer.rb +7 -8
  26. data/lib/temple/generators/string_buffer.rb +2 -2
  27. data/lib/temple/html/attribute_merger.rb +6 -11
  28. data/lib/temple/html/attribute_remover.rb +1 -1
  29. data/lib/temple/html/attribute_sorter.rb +1 -1
  30. data/lib/temple/html/fast.rb +49 -44
  31. data/lib/temple/html/pretty.rb +34 -43
  32. data/lib/temple/html/safe.rb +23 -0
  33. data/lib/temple/map.rb +105 -0
  34. data/lib/temple/mixins/dispatcher.rb +10 -7
  35. data/lib/temple/mixins/engine_dsl.rb +42 -67
  36. data/lib/temple/mixins/grammar_dsl.rb +10 -8
  37. data/lib/temple/mixins/options.rb +26 -24
  38. data/lib/temple/mixins/template.rb +3 -3
  39. data/lib/temple/static_analyzer.rb +77 -0
  40. data/lib/temple/templates/rails.rb +17 -36
  41. data/lib/temple/templates/tilt.rb +7 -13
  42. data/lib/temple/utils.rb +27 -29
  43. data/lib/temple/version.rb +1 -1
  44. data/lib/temple.rb +8 -4
  45. data/spec/engine_spec.rb +189 -0
  46. data/{test/test_erb.rb → spec/erb_spec.rb} +12 -13
  47. data/spec/filter_spec.rb +29 -0
  48. data/{test/filters/test_code_merger.rb → spec/filters/code_merger_spec.rb} +7 -7
  49. data/{test/filters/test_control_flow.rb → spec/filters/control_flow_spec.rb} +13 -13
  50. data/{test/filters/test_dynamic_inliner.rb → spec/filters/dynamic_inliner_spec.rb} +18 -18
  51. data/{test/filters/test_eraser.rb → spec/filters/eraser_spec.rb} +13 -13
  52. data/{test/filters/test_escapable.rb → spec/filters/escapable_spec.rb} +15 -13
  53. data/{test/filters/test_multi_flattener.rb → spec/filters/multi_flattener_spec.rb} +4 -4
  54. data/spec/filters/static_analyzer_spec.rb +35 -0
  55. data/{test/filters/test_static_merger.rb → spec/filters/static_merger_spec.rb} +7 -7
  56. data/spec/filters/string_splitter_spec.rb +50 -0
  57. data/spec/generator_spec.rb +158 -0
  58. data/spec/grammar_spec.rb +47 -0
  59. data/{test/html/test_attribute_merger.rb → spec/html/attribute_merger_spec.rb} +11 -11
  60. data/{test/html/test_attribute_remover.rb → spec/html/attribute_remover_spec.rb} +7 -7
  61. data/{test/html/test_attribute_sorter.rb → spec/html/attribute_sorter_spec.rb} +8 -8
  62. data/{test/html/test_fast.rb → spec/html/fast_spec.rb} +23 -23
  63. data/{test/html/test_pretty.rb → spec/html/pretty_spec.rb} +9 -15
  64. data/spec/map_spec.rb +39 -0
  65. data/{test/mixins/test_dispatcher.rb → spec/mixins/dispatcher_spec.rb} +12 -12
  66. data/{test/mixins/test_grammar_dsl.rb → spec/mixins/grammar_dsl_spec.rb} +19 -19
  67. data/{test/helper.rb → spec/spec_helper.rb} +9 -15
  68. data/spec/static_analyzer_spec.rb +39 -0
  69. data/spec/utils_spec.rb +39 -0
  70. data/temple.gemspec +4 -2
  71. metadata +62 -63
  72. data/.travis.yml +0 -13
  73. data/lib/temple/hash.rb +0 -104
  74. data/test/test_engine.rb +0 -170
  75. data/test/test_filter.rb +0 -29
  76. data/test/test_generator.rb +0 -136
  77. data/test/test_grammar.rb +0 -47
  78. data/test/test_hash.rb +0 -39
  79. data/test/test_utils.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.6.7
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Magnus Holm
@@ -9,48 +9,62 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-30 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
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - '>='
18
+ - - ">="
19
19
  - !ruby/object:Gem::Version
20
20
  version: '0'
21
21
  type: :development
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - '>='
25
+ - - ">="
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
+ - - ">="
33
33
  - !ruby/object:Gem::Version
34
34
  version: '0'
35
35
  type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - '>='
39
+ - - ">="
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: rake
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - '>='
46
+ - - ">="
47
47
  - !ruby/object:Gem::Version
48
48
  version: '0'
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - '>='
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: erubi
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
54
68
  - !ruby/object:Gem::Version
55
69
  version: '0'
56
70
  description:
@@ -61,9 +75,9 @@ executables: []
61
75
  extensions: []
62
76
  extra_rdoc_files: []
63
77
  files:
64
- - .gitignore
65
- - .travis.yml
66
- - .yardopts
78
+ - ".github/workflows/test.yml"
79
+ - ".gitignore"
80
+ - ".yardopts"
67
81
  - CHANGES
68
82
  - EXPRESSIONS.md
69
83
  - Gemfile
@@ -78,6 +92,7 @@ files:
78
92
  - lib/temple/erb/trimming.rb
79
93
  - lib/temple/exceptions.rb
80
94
  - lib/temple/filter.rb
95
+ - lib/temple/filters/ambles.rb
81
96
  - lib/temple/filters/code_merger.rb
82
97
  - lib/temple/filters/control_flow.rb
83
98
  - lib/temple/filters/dynamic_inliner.rb
@@ -86,7 +101,9 @@ files:
86
101
  - lib/temple/filters/escapable.rb
87
102
  - lib/temple/filters/multi_flattener.rb
88
103
  - lib/temple/filters/remove_bom.rb
104
+ - lib/temple/filters/static_analyzer.rb
89
105
  - lib/temple/filters/static_merger.rb
106
+ - lib/temple/filters/string_splitter.rb
90
107
  - lib/temple/filters/validator.rb
91
108
  - lib/temple/generator.rb
92
109
  - lib/temple/generators/array.rb
@@ -95,7 +112,6 @@ files:
95
112
  - lib/temple/generators/rails_output_buffer.rb
96
113
  - lib/temple/generators/string_buffer.rb
97
114
  - lib/temple/grammar.rb
98
- - lib/temple/hash.rb
99
115
  - lib/temple/html/attribute_merger.rb
100
116
  - lib/temple/html/attribute_remover.rb
101
117
  - lib/temple/html/attribute_sorter.rb
@@ -103,40 +119,46 @@ files:
103
119
  - lib/temple/html/fast.rb
104
120
  - lib/temple/html/filter.rb
105
121
  - lib/temple/html/pretty.rb
122
+ - lib/temple/html/safe.rb
123
+ - lib/temple/map.rb
106
124
  - lib/temple/mixins/dispatcher.rb
107
125
  - lib/temple/mixins/engine_dsl.rb
108
126
  - lib/temple/mixins/grammar_dsl.rb
109
127
  - lib/temple/mixins/options.rb
110
128
  - lib/temple/mixins/template.rb
111
129
  - lib/temple/parser.rb
130
+ - lib/temple/static_analyzer.rb
112
131
  - lib/temple/templates.rb
113
132
  - lib/temple/templates/rails.rb
114
133
  - lib/temple/templates/tilt.rb
115
134
  - lib/temple/utils.rb
116
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
117
161
  - temple.gemspec
118
- - test/filters/test_code_merger.rb
119
- - test/filters/test_control_flow.rb
120
- - test/filters/test_dynamic_inliner.rb
121
- - test/filters/test_eraser.rb
122
- - test/filters/test_escapable.rb
123
- - test/filters/test_multi_flattener.rb
124
- - test/filters/test_static_merger.rb
125
- - test/helper.rb
126
- - test/html/test_attribute_merger.rb
127
- - test/html/test_attribute_remover.rb
128
- - test/html/test_attribute_sorter.rb
129
- - test/html/test_fast.rb
130
- - test/html/test_pretty.rb
131
- - test/mixins/test_dispatcher.rb
132
- - test/mixins/test_grammar_dsl.rb
133
- - test/test_engine.rb
134
- - test/test_erb.rb
135
- - test/test_filter.rb
136
- - test/test_generator.rb
137
- - test/test_grammar.rb
138
- - test/test_hash.rb
139
- - test/test_utils.rb
140
162
  homepage: https://github.com/judofyr/temple
141
163
  licenses:
142
164
  - MIT
@@ -147,40 +169,17 @@ require_paths:
147
169
  - lib
148
170
  required_ruby_version: !ruby/object:Gem::Requirement
149
171
  requirements:
150
- - - '>='
172
+ - - ">="
151
173
  - !ruby/object:Gem::Version
152
- version: '0'
174
+ version: 2.5.0
153
175
  required_rubygems_version: !ruby/object:Gem::Requirement
154
176
  requirements:
155
- - - '>='
177
+ - - ">="
156
178
  - !ruby/object:Gem::Version
157
179
  version: '0'
158
180
  requirements: []
159
- rubyforge_project:
160
- rubygems_version: 2.0.0
181
+ rubygems_version: 3.2.5
161
182
  signing_key:
162
183
  specification_version: 4
163
184
  summary: Template compilation framework in Ruby
164
- test_files:
165
- - test/filters/test_code_merger.rb
166
- - test/filters/test_control_flow.rb
167
- - test/filters/test_dynamic_inliner.rb
168
- - test/filters/test_eraser.rb
169
- - test/filters/test_escapable.rb
170
- - test/filters/test_multi_flattener.rb
171
- - test/filters/test_static_merger.rb
172
- - test/helper.rb
173
- - test/html/test_attribute_merger.rb
174
- - test/html/test_attribute_remover.rb
175
- - test/html/test_attribute_sorter.rb
176
- - test/html/test_fast.rb
177
- - test/html/test_pretty.rb
178
- - test/mixins/test_dispatcher.rb
179
- - test/mixins/test_grammar_dsl.rb
180
- - test/test_engine.rb
181
- - test/test_erb.rb
182
- - test/test_filter.rb
183
- - test/test_generator.rb
184
- - test/test_grammar.rb
185
- - test/test_hash.rb
186
- - test/test_utils.rb
185
+ test_files: []
data/.travis.yml DELETED
@@ -1,13 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 1.8.7
4
- - 1.9.3
5
- - 2.0.0
6
- - ruby-head
7
- - jruby-18mode
8
- - jruby-19mode
9
- - rbx-18mode
10
- - rbx-19mode
11
- matrix:
12
- allow_failures:
13
- - rvm: ruby-head
data/lib/temple/hash.rb DELETED
@@ -1,104 +0,0 @@
1
- module Temple
2
- # Immutable hash class which supports hash merging
3
- # @api public
4
- class ImmutableHash
5
- include Enumerable
6
-
7
- def initialize(*hash)
8
- @hash = hash.compact
9
- end
10
-
11
- def include?(key)
12
- @hash.any? {|h| h.include?(key) }
13
- end
14
-
15
- def [](key)
16
- @hash.each {|h| return h[key] if h.include?(key) }
17
- nil
18
- end
19
-
20
- def each
21
- keys.each {|k| yield(k, self[k]) }
22
- end
23
-
24
- def keys
25
- @hash.inject([]) {|keys, h| keys.concat(h.keys) }.uniq
26
- end
27
-
28
- def values
29
- keys.map {|k| self[k] }
30
- end
31
-
32
- def to_hash
33
- result = {}
34
- each {|k, v| result[k] = v }
35
- result
36
- end
37
- end
38
-
39
- # Mutable hash class which supports hash merging
40
- # @api public
41
- class MutableHash < ImmutableHash
42
- def initialize(*hash)
43
- super({}, *hash)
44
- end
45
-
46
- def []=(key, value)
47
- @hash.first[key] = value
48
- end
49
-
50
- def update(hash)
51
- @hash.first.update(hash)
52
- end
53
- end
54
-
55
- class OptionHash < MutableHash
56
- def initialize(*hash, &block)
57
- super(*hash)
58
- @handler = block
59
- @valid = {}
60
- @deprecated = {}
61
- end
62
-
63
- def []=(key, value)
64
- validate_key!(key)
65
- super
66
- end
67
-
68
- def update(hash)
69
- validate_hash!(hash)
70
- super
71
- end
72
-
73
- def valid_keys
74
- keys.concat(@valid.keys).uniq
75
- end
76
-
77
- def add_valid_keys(*keys)
78
- keys.flatten.each { |key| @valid[key] = true }
79
- end
80
-
81
- def add_deprecated_keys(*keys)
82
- keys.flatten.each { |key| @valid[key] = @deprecated[key] = true }
83
- end
84
-
85
- def validate_hash!(hash)
86
- hash.to_hash.keys.each {|key| validate_key!(key) }
87
- end
88
-
89
- def validate_key!(key)
90
- @handler.call(self, key, true) if deprecated_key?(key)
91
- @handler.call(self, key, false) unless valid_key?(key)
92
- end
93
-
94
- def deprecated_key?(key)
95
- @deprecated.include?(key) ||
96
- @hash.any? {|h| h.deprecated_key?(key) if h.respond_to?(:deprecated_key?) }
97
- end
98
-
99
- def valid_key?(key)
100
- include?(key) || @valid.include?(key) ||
101
- @hash.any? {|h| h.valid_key?(key) if h.respond_to?(:valid_key?) }
102
- end
103
- end
104
- end
data/test/test_engine.rb DELETED
@@ -1,170 +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 TestEngine < Temple::Engine
17
- use(:Parser) do |input|
18
- [:static, input]
19
- end
20
- use :MyFilter1, proc {|exp| exp }
21
- use :MyFilter2, proc {|exp| exp }
22
- use Temple::HTML::Pretty, :format, :pretty => true
23
- filter :MultiFlattener
24
- generator :ArrayBuffer
25
- use :BeforeLast, Callable1.new
26
- use(:Last) { Callable2.new }
27
- end
28
-
29
- describe Temple::Engine do
30
- it 'should build chain' do
31
- TestEngine.chain.size.should.equal 8
32
-
33
- TestEngine.chain[0].first.should.equal :Parser
34
- TestEngine.chain[0].size.should.equal 2
35
- TestEngine.chain[0].last.should.be.instance_of Proc
36
-
37
- TestEngine.chain[1].first.should.equal :MyFilter1
38
- TestEngine.chain[1].size.should.equal 2
39
- TestEngine.chain[1].last.should.be.instance_of Proc
40
-
41
- TestEngine.chain[2].first.should.equal :MyFilter2
42
- TestEngine.chain[2].size.should.equal 2
43
- TestEngine.chain[2].last.should.be.instance_of Proc
44
-
45
- TestEngine.chain[3].first.should.equal :'Temple::HTML::Pretty'
46
- TestEngine.chain[3].size.should.equal 2
47
- TestEngine.chain[3].last.should.be.instance_of Proc
48
-
49
- TestEngine.chain[4].first.should.equal :MultiFlattener
50
- TestEngine.chain[4].size.should.equal 2
51
- TestEngine.chain[4].last.should.be.instance_of Proc
52
-
53
- TestEngine.chain[5].first.should.equal :ArrayBuffer
54
- TestEngine.chain[5].size.should.equal 2
55
- TestEngine.chain[5].last.should.be.instance_of Proc
56
-
57
- TestEngine.chain[6].first.should.equal :BeforeLast
58
- TestEngine.chain[6].size.should.equal 2
59
- TestEngine.chain[6].last.should.be.instance_of Proc
60
-
61
- TestEngine.chain[7].first.should.equal :Last
62
- TestEngine.chain[7].size.should.equal 2
63
- TestEngine.chain[7].last.should.be.instance_of Proc
64
- end
65
-
66
- it 'should instantiate chain' do
67
- call_chain = TestEngine.new.send(:call_chain)
68
- call_chain[0].should.be.instance_of Method
69
- call_chain[1].should.be.instance_of Method
70
- call_chain[2].should.be.instance_of Method
71
- call_chain[3].should.be.instance_of Temple::HTML::Pretty
72
- call_chain[4].should.be.instance_of Temple::Filters::MultiFlattener
73
- call_chain[5].should.be.instance_of Temple::Generators::ArrayBuffer
74
- call_chain[6].should.be.instance_of Callable1
75
- call_chain[7].should.be.instance_of Callable2
76
- end
77
-
78
- it 'should have #append' do
79
- engine = TestEngine.new
80
- call_chain = engine.send(:call_chain)
81
- call_chain.size.should.equal 8
82
-
83
- engine.append :MyFilter3 do |exp|
84
- exp
85
- end
86
-
87
- TestEngine.chain.size.should.equal 8
88
- engine.chain.size.should.equal 9
89
- engine.chain[8].first.should.equal :MyFilter3
90
- engine.chain[8].size.should.equal 2
91
- engine.chain[8].last.should.be.instance_of Proc
92
-
93
- call_chain = engine.send(:call_chain)
94
- call_chain.size.should.equal 9
95
- call_chain[8].should.be.instance_of Method
96
- end
97
-
98
- it 'should have #prepend' do
99
- engine = TestEngine.new
100
- call_chain = engine.send(:call_chain)
101
- call_chain.size.should.equal 8
102
-
103
- engine.prepend :MyFilter0 do |exp|
104
- exp
105
- end
106
-
107
- TestEngine.chain.size.should.equal 8
108
- engine.chain.size.should.equal 9
109
- engine.chain[0].first.should.equal :MyFilter0
110
- engine.chain[0].size.should.equal 2
111
- engine.chain[0].last.should.be.instance_of Proc
112
- engine.chain[1].first.should.equal :Parser
113
-
114
- call_chain = engine.send(:call_chain)
115
- call_chain.size.should.equal 9
116
- call_chain[0].should.be.instance_of Method
117
- end
118
-
119
- it 'should have #after' do
120
- engine = TestEngine.new
121
- engine.after :Parser, :MyFilter0 do |exp|
122
- exp
123
- end
124
- TestEngine.chain.size.should.equal 8
125
- engine.chain.size.should.equal 9
126
- engine.chain[0].first.should.equal :Parser
127
- engine.chain[1].first.should.equal :MyFilter0
128
- engine.chain[2].first.should.equal :MyFilter1
129
- end
130
-
131
- it 'should have #before' do
132
- engine = TestEngine.new
133
- engine.before :MyFilter1, :MyFilter0 do |exp|
134
- exp
135
- end
136
- TestEngine.chain.size.should.equal 8
137
- engine.chain.size.should.equal 9
138
- engine.chain[0].first.should.equal :Parser
139
- engine.chain[1].first.should.equal :MyFilter0
140
- engine.chain[2].first.should.equal :MyFilter1
141
- end
142
-
143
- it 'should have #remove' do
144
- engine = TestEngine.new
145
- engine.remove :MyFilter1
146
- TestEngine.chain.size.should.equal 8
147
- engine.chain.size.should.equal 7
148
- engine.chain[0].first.should.equal :Parser
149
- engine.chain[1].first.should.equal :MyFilter2
150
- end
151
-
152
- it 'should have #replace' do
153
- engine = TestEngine.new
154
- engine.replace :Parser, :MyParser do |exp|
155
- exp
156
- end
157
- engine.chain.size.should.equal 8
158
- engine.chain[0].first.should.equal :MyParser
159
- end
160
-
161
- it 'should work with inheritance' do
162
- inherited_engine = Class.new(TestEngine)
163
- inherited_engine.chain.size.should.equal 8
164
- inherited_engine.append :MyFilter3 do |exp|
165
- exp
166
- end
167
- inherited_engine.chain.size.should.equal 9
168
- TestEngine.chain.size.should.equal 8
169
- end
170
- 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::ImmutableHash
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,136 +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
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
- end
89
-
90
- describe Temple::Generators::ArrayBuffer do
91
- it 'should compile simple expressions' do
92
- gen = Temple::Generators::ArrayBuffer.new
93
- gen.call([:static, 'test']).should.equal '_buf = "test"'
94
- gen.call([:dynamic, 'test']).should.equal '_buf = (test).to_s'
95
- gen.call([:code, 'test']).should.equal '_buf = []; test; _buf = _buf.join'
96
-
97
- gen.call([:multi, [:static, 'a'], [:static, 'b']]).should.equal '_buf = []; _buf << ("a"); _buf << ("b"); _buf = _buf.join'
98
- gen.call([:multi, [:static, 'a'], [:dynamic, 'b']]).should.equal '_buf = []; _buf << ("a"); _buf << (b); _buf = _buf.join'
99
- end
100
- end
101
-
102
- describe Temple::Generators::StringBuffer do
103
- it 'should compile simple expressions' do
104
- gen = Temple::Generators::StringBuffer.new
105
- gen.call([:static, 'test']).should.equal '_buf = "test"'
106
- gen.call([:dynamic, 'test']).should.equal '_buf = (test).to_s'
107
- gen.call([:code, 'test']).should.equal '_buf = \'\'; test; _buf'
108
-
109
- gen.call([:multi, [:static, 'a'], [:static, 'b']]).should.equal '_buf = \'\'; _buf << ("a"); _buf << ("b"); _buf'
110
- gen.call([:multi, [:static, 'a'], [:dynamic, 'b']]).should.equal '_buf = \'\'; _buf << ("a"); _buf << ((b).to_s); _buf'
111
- end
112
- end
113
-
114
- describe Temple::Generators::ERB do
115
- it 'should compile simple expressions' do
116
- gen = Temple::Generators::ERB.new
117
- gen.call([:static, 'test']).should.equal 'test'
118
- gen.call([:dynamic, 'test']).should.equal '<%= test %>'
119
- gen.call([:code, 'test']).should.equal '<% test %>'
120
-
121
- gen.call([:multi, [:static, 'a'], [:static, 'b']]).should.equal 'ab'
122
- gen.call([:multi, [:static, 'a'], [:dynamic, 'b']]).should.equal 'a<%= b %>'
123
- end
124
- end
125
-
126
- describe Temple::Generators::RailsOutputBuffer do
127
- it 'should compile simple expressions' do
128
- gen = Temple::Generators::RailsOutputBuffer.new
129
- gen.call([:static, 'test']).should.equal '@output_buffer = ActiveSupport::SafeBuffer.new; ' +
130
- '@output_buffer.safe_concat(("test")); @output_buffer'
131
- gen.call([:dynamic, 'test']).should.equal '@output_buffer = ActiveSupport::SafeBuffer.new; ' +
132
- '@output_buffer.safe_concat(((test).to_s)); @output_buffer'
133
- gen.call([:code, 'test']).should.equal '@output_buffer = ActiveSupport::SafeBuffer.new; ' +
134
- 'test; @output_buffer'
135
- end
136
- end