temple 0.8.2 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.github/workflows/test.yml +34 -0
- data/.gitignore +1 -0
- data/CHANGES +18 -1
- data/README.md +1 -1
- data/Rakefile +4 -11
- data/lib/temple/erb/parser.rb +1 -1
- data/lib/temple/filters/ambles.rb +21 -0
- data/lib/temple/filters/string_splitter.rb +11 -0
- data/lib/temple/generator.rb +11 -5
- data/lib/temple/generators/rails_output_buffer.rb +2 -6
- data/lib/temple/mixins/grammar_dsl.rb +2 -1
- data/lib/temple/templates/rails.rb +4 -0
- data/lib/temple/templates/tilt.rb +1 -9
- data/lib/temple/utils.rb +2 -14
- data/lib/temple/version.rb +1 -1
- data/lib/temple.rb +1 -0
- data/spec/engine_spec.rb +189 -0
- data/{test/test_erb.rb → spec/erb_spec.rb} +12 -12
- data/spec/filter_spec.rb +29 -0
- data/{test/filters/test_code_merger.rb → spec/filters/code_merger_spec.rb} +7 -7
- data/{test/filters/test_control_flow.rb → spec/filters/control_flow_spec.rb} +13 -13
- data/{test/filters/test_dynamic_inliner.rb → spec/filters/dynamic_inliner_spec.rb} +18 -18
- data/{test/filters/test_eraser.rb → spec/filters/eraser_spec.rb} +9 -9
- data/{test/filters/test_escapable.rb → spec/filters/escapable_spec.rb} +10 -10
- data/{test/filters/test_multi_flattener.rb → spec/filters/multi_flattener_spec.rb} +4 -4
- data/{test/filters/test_static_analyzer.rb → spec/filters/static_analyzer_spec.rb} +6 -8
- data/{test/filters/test_static_merger.rb → spec/filters/static_merger_spec.rb} +7 -7
- data/spec/filters/string_splitter_spec.rb +50 -0
- data/spec/generator_spec.rb +167 -0
- data/spec/grammar_spec.rb +47 -0
- data/{test/html/test_attribute_merger.rb → spec/html/attribute_merger_spec.rb} +11 -11
- data/{test/html/test_attribute_remover.rb → spec/html/attribute_remover_spec.rb} +7 -7
- data/{test/html/test_attribute_sorter.rb → spec/html/attribute_sorter_spec.rb} +7 -7
- data/{test/html/test_fast.rb → spec/html/fast_spec.rb} +23 -23
- data/{test/html/test_pretty.rb → spec/html/pretty_spec.rb} +7 -7
- data/spec/map_spec.rb +39 -0
- data/{test/mixins/test_dispatcher.rb → spec/mixins/dispatcher_spec.rb} +12 -12
- data/{test/mixins/test_grammar_dsl.rb → spec/mixins/grammar_dsl_spec.rb} +19 -19
- data/{test/helper.rb → spec/spec_helper.rb} +5 -6
- data/{test/test_static_analyzer.rb → spec/static_analyzer_spec.rb} +6 -6
- data/spec/utils_spec.rb +39 -0
- data/temple.gemspec +3 -3
- metadata +34 -59
- data/.travis.yml +0 -30
- data/test/filters/test_string_splitter.rb +0 -25
- data/test/test_engine.rb +0 -189
- data/test/test_filter.rb +0 -29
- data/test/test_generator.rb +0 -158
- data/test/test_grammar.rb +0 -47
- data/test/test_map.rb +0 -39
- data/test/test_utils.rb +0 -39
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ec5bd4c914592e35029369b132ae55d5ae56771b73d5c8710d3b6cbaf8c1409d
|
4
|
+
data.tar.gz: 379717f7a2b6580cfe6e3732dcb8da6ff76f6adf2ec725cfc32eacd988f8471a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 938451e922d130af494c37d73612b35c53e05a94143d1cabff3e725b4512fbc4a04e1bf7acc27be0e8b37ebc7b00a2d9859e4f073c0941aeada7a1ed396889db
|
7
|
+
data.tar.gz: f2925b82e2fb217f63d0afa4890c71f7ff6e209ee7775e33b9fb4a3885dce9bd638e46b8280f58f3f5002b020fd3e07792c560c3e44ed4b182dbfcefa2c66978
|
@@ -0,0 +1,34 @@
|
|
1
|
+
name: test
|
2
|
+
on:
|
3
|
+
push:
|
4
|
+
branches:
|
5
|
+
- master
|
6
|
+
pull_request:
|
7
|
+
types:
|
8
|
+
- opened
|
9
|
+
- synchronize
|
10
|
+
- reopened
|
11
|
+
schedule:
|
12
|
+
- cron: "00 15 * * *"
|
13
|
+
jobs:
|
14
|
+
test:
|
15
|
+
runs-on: ubuntu-latest
|
16
|
+
strategy:
|
17
|
+
fail-fast: false
|
18
|
+
matrix:
|
19
|
+
ruby:
|
20
|
+
- '2.5'
|
21
|
+
- '2.6'
|
22
|
+
- '2.7'
|
23
|
+
- '3.0'
|
24
|
+
- '3.1'
|
25
|
+
- jruby
|
26
|
+
- truffleruby-head
|
27
|
+
steps:
|
28
|
+
- uses: actions/checkout@v2
|
29
|
+
- name: Set up Ruby
|
30
|
+
uses: ruby/setup-ruby@v1
|
31
|
+
with:
|
32
|
+
ruby-version: ${{ matrix.ruby }}
|
33
|
+
bundler-cache: true
|
34
|
+
- run: bundle exec rake spec
|
data/.gitignore
CHANGED
data/CHANGES
CHANGED
@@ -1,3 +1,20 @@
|
|
1
|
+
0.9.1
|
2
|
+
|
3
|
+
* Fix Slim's error in AttributeMerger due to 0.9.0's :capture_generator (#137)
|
4
|
+
* Fix Temple::ERB::Engine's <%= to not escape and <%== to escape expressions
|
5
|
+
|
6
|
+
0.9.0
|
7
|
+
|
8
|
+
* Require Ruby 2.5+ (#131)
|
9
|
+
* Change default :capture_generator to self (#113)
|
10
|
+
* Improve compatibility with Rails 7.1 (#135)
|
11
|
+
* Support Rails 6.1's annotate_rendered_view_with_filenames
|
12
|
+
with Temple::Filters::Ambles (#134)
|
13
|
+
* Fix a crash in StringSplitter filter (#138)
|
14
|
+
* Fix a warning by Object#=~ since Ruby 2.6 (#129)
|
15
|
+
* Fix deprecated Tilt template mime type (#108)
|
16
|
+
* Stop using deprecated EscapeUtils from Temple::Utils (#136)
|
17
|
+
|
1
18
|
0.8.2
|
2
19
|
|
3
20
|
* Support TruffleRuby in Temple::Filters::StaticAnalyzer (#127)
|
@@ -16,7 +33,7 @@
|
|
16
33
|
|
17
34
|
0.7.8
|
18
35
|
|
19
|
-
* Fix
|
36
|
+
* Fix a warning in StaticAnalyzer
|
20
37
|
|
21
38
|
0.7.7
|
22
39
|
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Temple
|
2
2
|
======
|
3
3
|
|
4
|
-
[](https://github.com/judofyr/temple/actions/workflows/test.yml) [](https://codeclimate.com/github/judofyr/temple) [](https://rubygems.org/gems/temple) [](http://rubydoc.info/gems/temple/frames)
|
5
5
|
|
6
6
|
Temple is an abstraction and a framework for compiling templates to pure Ruby.
|
7
7
|
It's all about making it easier to experiment, implement and optimize template
|
data/Rakefile
CHANGED
@@ -1,15 +1,8 @@
|
|
1
|
-
require '
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rspec/core/rake_task'
|
2
3
|
|
3
|
-
|
4
|
-
task :
|
5
|
-
sh "bacon -Ilib -Itest --automatic --quiet"
|
6
|
-
end
|
7
|
-
|
8
|
-
#Rake::TestTask.new(:test) do |t|
|
9
|
-
# t.libs << 'lib' << 'test'
|
10
|
-
# t.pattern = 'test/**/test_*.rb'
|
11
|
-
# t.verbose = false
|
12
|
-
#end
|
4
|
+
RSpec::Core::RakeTask.new(:spec)
|
5
|
+
task default: :spec
|
13
6
|
|
14
7
|
begin
|
15
8
|
require 'rcov/rcovtask'
|
data/lib/temple/erb/parser.rb
CHANGED
@@ -0,0 +1,21 @@
|
|
1
|
+
module Temple
|
2
|
+
module Filters
|
3
|
+
class Ambles < Filter
|
4
|
+
define_options :preamble, :postamble
|
5
|
+
|
6
|
+
def initialize(*)
|
7
|
+
super
|
8
|
+
@preamble = options[:preamble]
|
9
|
+
@postamble = options[:postamble]
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(ast)
|
13
|
+
ret = [:multi]
|
14
|
+
ret << [:static, @preamble] if @preamble
|
15
|
+
ret << ast
|
16
|
+
ret << [:static, @postamble] if @postamble
|
17
|
+
ret
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -46,6 +46,7 @@ module Temple
|
|
46
46
|
|
47
47
|
case type
|
48
48
|
when :on_tstring_content
|
49
|
+
beg_str, end_str = escape_quotes(beg_str, end_str)
|
49
50
|
exps << [:static, eval("#{beg_str}#{str}#{end_str}").to_s]
|
50
51
|
when :on_embexpr_beg
|
51
52
|
embedded = shift_balanced_embexpr(tokens)
|
@@ -54,6 +55,16 @@ module Temple
|
|
54
55
|
end
|
55
56
|
end
|
56
57
|
|
58
|
+
# Some quotes are split-unsafe. Replace such quotes with null characters.
|
59
|
+
def escape_quotes(beg_str, end_str)
|
60
|
+
case [beg_str[-1], end_str]
|
61
|
+
when ['(', ')'], ['[', ']'], ['{', '}']
|
62
|
+
[beg_str.sub(/.\z/) { "\0" }, "\0"]
|
63
|
+
else
|
64
|
+
[beg_str, end_str]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
57
68
|
def shift_balanced_embexpr(tokens)
|
58
69
|
String.new.tap do |embedded|
|
59
70
|
embexpr_open = 1
|
data/lib/temple/generator.rb
CHANGED
@@ -10,7 +10,7 @@ module Temple
|
|
10
10
|
include Mixins::Options
|
11
11
|
|
12
12
|
define_options :save_buffer,
|
13
|
-
capture_generator:
|
13
|
+
capture_generator: :self,
|
14
14
|
buffer: '_buf',
|
15
15
|
freeze_static: RUBY_VERSION >= '2.1'
|
16
16
|
|
@@ -54,7 +54,7 @@ module Temple
|
|
54
54
|
end
|
55
55
|
|
56
56
|
def on_capture(name, exp)
|
57
|
-
capture_generator.new(buffer: name).call(exp)
|
57
|
+
capture_generator.new(**options, buffer: name).call(exp)
|
58
58
|
end
|
59
59
|
|
60
60
|
def on_static(text)
|
@@ -76,9 +76,15 @@ module Temple
|
|
76
76
|
end
|
77
77
|
|
78
78
|
def capture_generator
|
79
|
-
@capture_generator ||=
|
80
|
-
|
81
|
-
|
79
|
+
@capture_generator ||=
|
80
|
+
case options[:capture_generator]
|
81
|
+
when :self
|
82
|
+
self.class
|
83
|
+
when Class
|
84
|
+
options[:capture_generator]
|
85
|
+
else
|
86
|
+
Generators.const_get(options[:capture_generator])
|
87
|
+
end
|
82
88
|
end
|
83
89
|
|
84
90
|
def concat(str)
|
@@ -10,7 +10,7 @@ module Temple
|
|
10
10
|
# @api public
|
11
11
|
class RailsOutputBuffer < StringBuffer
|
12
12
|
define_options :streaming,
|
13
|
-
buffer_class: '
|
13
|
+
buffer_class: 'ActionView::OutputBuffer',
|
14
14
|
buffer: '@output_buffer',
|
15
15
|
# output_buffer is needed for Rails 3.1 Streaming support
|
16
16
|
capture_generator: RailsOutputBuffer
|
@@ -20,11 +20,7 @@ module Temple
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def create_buffer
|
23
|
-
|
24
|
-
"#{buffer} = output_buffer || #{options[:buffer_class]}.new"
|
25
|
-
else
|
26
|
-
"#{buffer} = #{options[:buffer_class]}.new"
|
27
|
-
end
|
23
|
+
"#{buffer} = output_buffer || #{options[:buffer_class]}.new"
|
28
24
|
end
|
29
25
|
|
30
26
|
def concat(str)
|
@@ -143,7 +143,8 @@ module Temple
|
|
143
143
|
start = Or.new(self)
|
144
144
|
curr = [start]
|
145
145
|
rule.each do |elem|
|
146
|
-
|
146
|
+
case elem
|
147
|
+
when /^(.*)(\*|\?|\+)$/
|
147
148
|
elem = Element.new(self, const_get($1))
|
148
149
|
curr.each {|c| c << elem }
|
149
150
|
elem << elem if $2 != '?'
|
@@ -5,6 +5,10 @@ module Temple
|
|
5
5
|
|
6
6
|
def call(template, source = nil)
|
7
7
|
opts = {}.update(self.class.options).update(file: template.identifier)
|
8
|
+
if ActionView::Base.try(:annotate_rendered_view_with_filenames) && template.format == :html
|
9
|
+
opts[:preamble] = "<!-- BEGIN #{template.short_identifier} -->\n"
|
10
|
+
opts[:postamble] = "<!-- END #{template.short_identifier} -->\n"
|
11
|
+
end
|
8
12
|
self.class.compile((source || template.source), opts)
|
9
13
|
end
|
10
14
|
|
@@ -7,14 +7,6 @@ module Temple
|
|
7
7
|
|
8
8
|
define_options mime_type: 'text/html'
|
9
9
|
|
10
|
-
def self.default_mime_type
|
11
|
-
options[:mime_type]
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.default_mime_type=(mime_type)
|
15
|
-
options[:mime_type] = mime_type
|
16
|
-
end
|
17
|
-
|
18
10
|
# Prepare Temple template
|
19
11
|
#
|
20
12
|
# Called immediately after template data is loaded.
|
@@ -22,7 +14,7 @@ module Temple
|
|
22
14
|
# @return [void]
|
23
15
|
def prepare
|
24
16
|
opts = {}.update(self.class.options).update(options).update(file: eval_file)
|
25
|
-
opts.delete(:mime_type)
|
17
|
+
metadata[:mime_type] = opts.delete(:mime_type)
|
26
18
|
if opts.include?(:outvar)
|
27
19
|
opts[:buffer] = opts.delete(:outvar)
|
28
20
|
opts[:save_buffer] = true
|
data/lib/temple/utils.rb
CHANGED
@@ -1,10 +1,6 @@
|
|
1
1
|
begin
|
2
|
-
require '
|
2
|
+
require 'cgi/escape'
|
3
3
|
rescue LoadError
|
4
|
-
begin
|
5
|
-
require 'cgi/escape'
|
6
|
-
rescue LoadError
|
7
|
-
end
|
8
4
|
end
|
9
5
|
|
10
6
|
module Temple
|
@@ -21,15 +17,7 @@ module Temple
|
|
21
17
|
html.html_safe? ? html : escape_html(html)
|
22
18
|
end
|
23
19
|
|
24
|
-
if defined?(
|
25
|
-
# Returns an escaped copy of `html`.
|
26
|
-
#
|
27
|
-
# @param html [String] The string to escape
|
28
|
-
# @return [String] The escaped string
|
29
|
-
def escape_html(html)
|
30
|
-
EscapeUtils.escape_html(html.to_s, false)
|
31
|
-
end
|
32
|
-
elsif defined?(CGI.escapeHTML)
|
20
|
+
if defined?(CGI.escapeHTML)
|
33
21
|
# Returns an escaped copy of `html`.
|
34
22
|
#
|
35
23
|
# @param html [String] The string to escape
|
data/lib/temple/version.rb
CHANGED
data/lib/temple.rb
CHANGED
data/spec/engine_spec.rb
ADDED
@@ -0,0 +1,189 @@
|
|
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
|
@@ -1,5 +1,5 @@
|
|
1
|
-
require '
|
2
|
-
require 'tilt/
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'tilt/erubi'
|
3
3
|
|
4
4
|
describe Temple::ERB::Engine do
|
5
5
|
it 'should compile erb' do
|
@@ -11,7 +11,7 @@ describe Temple::ERB::Engine do
|
|
11
11
|
<% end %>
|
12
12
|
}
|
13
13
|
|
14
|
-
erb(src).
|
14
|
+
expect(erb(src)).to eq(erubi(src))
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'should recognize comments' do
|
@@ -20,7 +20,7 @@ hello
|
|
20
20
|
<%# comment -- ignored -- useful in testing %>
|
21
21
|
world}
|
22
22
|
|
23
|
-
erb(src).
|
23
|
+
expect(erb(src)).to eq(erubi(src))
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'should recognize <%% and %%>' do
|
@@ -31,19 +31,19 @@ world}
|
|
31
31
|
<% end %>
|
32
32
|
}
|
33
33
|
|
34
|
-
erb(src).
|
34
|
+
expect(erb(src)).to eq("\n<%\n %>\n")
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'should escape automatically' do
|
38
|
-
src = '
|
38
|
+
src = '<%== "<" %>'
|
39
39
|
ans = '<'
|
40
|
-
erb(src).
|
40
|
+
expect(erb(src)).to eq(ans)
|
41
41
|
end
|
42
42
|
|
43
|
-
it 'should support
|
44
|
-
src = '
|
43
|
+
it 'should support = to disable automatic escape' do
|
44
|
+
src = '<%= "<" %>'
|
45
45
|
ans = '<'
|
46
|
-
erb(src).
|
46
|
+
expect(erb(src)).to eq(ans)
|
47
47
|
end
|
48
48
|
|
49
49
|
it 'should support trim mode' do
|
@@ -55,7 +55,7 @@ world}
|
|
55
55
|
<% end %>
|
56
56
|
}
|
57
57
|
|
58
|
-
erb(src, trim: true).
|
59
|
-
erb(src, trim: false).
|
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
60
|
end
|
61
61
|
end
|
data/spec/filter_spec.rb
ADDED
@@ -0,0 +1,29 @@
|
|
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,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Temple::Filters::CodeMerger do
|
4
4
|
before do
|
@@ -6,21 +6,21 @@ describe Temple::Filters::CodeMerger do
|
|
6
6
|
end
|
7
7
|
|
8
8
|
it 'should merge serveral codes' do
|
9
|
-
@filter.call([:multi,
|
9
|
+
expect(@filter.call([:multi,
|
10
10
|
[:code, "a"],
|
11
11
|
[:code, "b"],
|
12
12
|
[:code, "c"]
|
13
|
-
]).
|
13
|
+
])).to eq [:code, "a; b; c"]
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'should merge serveral codes around static' do
|
17
|
-
@filter.call([:multi,
|
17
|
+
expect(@filter.call([:multi,
|
18
18
|
[:code, "a"],
|
19
19
|
[:code, "b"],
|
20
20
|
[:static, "123"],
|
21
21
|
[:code, "a"],
|
22
22
|
[:code, "b"]
|
23
|
-
]).
|
23
|
+
])).to eq [:multi,
|
24
24
|
[:code, "a; b"],
|
25
25
|
[:static, "123"],
|
26
26
|
[:code, "a; b"]
|
@@ -28,11 +28,11 @@ describe Temple::Filters::CodeMerger do
|
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'should merge serveral codes with newlines' do
|
31
|
-
@filter.call([:multi,
|
31
|
+
expect(@filter.call([:multi,
|
32
32
|
[:code, "a"],
|
33
33
|
[:code, "b"],
|
34
34
|
[:newline],
|
35
35
|
[:code, "c"]
|
36
|
-
]).
|
36
|
+
])).to eq [:code, "a; b\nc"]
|
37
37
|
end
|
38
38
|
end
|