temple 0.9.1 → 0.10.3
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 +4 -4
- data/.github/workflows/test.yml +2 -1
- data/CHANGES +21 -0
- data/Gemfile +0 -1
- data/Rakefile +0 -13
- data/lib/temple/engine.rb +1 -0
- data/lib/temple/erb/engine.rb +3 -0
- data/lib/temple/erb/parser.rb +1 -0
- data/lib/temple/erb/template.rb +1 -0
- data/lib/temple/erb/trimming.rb +1 -0
- data/lib/temple/exceptions.rb +1 -0
- data/lib/temple/filter.rb +1 -0
- data/lib/temple/filters/ambles.rb +1 -0
- data/lib/temple/filters/code_merger.rb +1 -0
- data/lib/temple/filters/control_flow.rb +1 -0
- data/lib/temple/filters/dynamic_inliner.rb +2 -1
- data/lib/temple/filters/dynamic_merger.rb +69 -0
- data/lib/temple/filters/encoding.rb +1 -0
- data/lib/temple/filters/eraser.rb +1 -0
- data/lib/temple/filters/escapable.rb +1 -0
- data/lib/temple/filters/multi_flattener.rb +1 -0
- data/lib/temple/filters/remove_bom.rb +1 -0
- data/lib/temple/filters/static_analyzer.rb +1 -0
- data/lib/temple/filters/static_merger.rb +1 -0
- data/lib/temple/filters/string_splitter.rb +2 -1
- data/lib/temple/filters/validator.rb +1 -0
- data/lib/temple/generator.rb +9 -12
- data/lib/temple/generators/array.rb +1 -0
- data/lib/temple/generators/array_buffer.rb +1 -0
- data/lib/temple/generators/erb.rb +1 -0
- data/lib/temple/generators/rails_output_buffer.rb +7 -3
- data/lib/temple/generators/string_buffer.rb +2 -1
- data/lib/temple/grammar.rb +1 -0
- data/lib/temple/html/attribute_merger.rb +1 -0
- data/lib/temple/html/attribute_remover.rb +1 -0
- data/lib/temple/html/attribute_sorter.rb +1 -0
- data/lib/temple/html/dispatcher.rb +1 -0
- data/lib/temple/html/fast.rb +1 -0
- data/lib/temple/html/filter.rb +1 -0
- data/lib/temple/html/pretty.rb +1 -0
- data/lib/temple/html/safe.rb +1 -0
- data/lib/temple/map.rb +1 -0
- data/lib/temple/mixins/dispatcher.rb +1 -0
- data/lib/temple/mixins/engine_dsl.rb +1 -0
- data/lib/temple/mixins/grammar_dsl.rb +2 -1
- data/lib/temple/mixins/options.rb +1 -0
- data/lib/temple/mixins/template.rb +1 -0
- data/lib/temple/parser.rb +1 -0
- data/lib/temple/static_analyzer.rb +1 -0
- data/lib/temple/templates/rails.rb +3 -2
- data/lib/temple/templates/tilt.rb +1 -0
- data/lib/temple/templates.rb +1 -0
- data/lib/temple/utils.rb +3 -1
- data/lib/temple/version.rb +2 -1
- data/lib/temple.rb +2 -0
- data/temple.gemspec +1 -3
- metadata +4 -28
- data/spec/engine_spec.rb +0 -189
- data/spec/erb_spec.rb +0 -61
- data/spec/filter_spec.rb +0 -29
- data/spec/filters/code_merger_spec.rb +0 -38
- data/spec/filters/control_flow_spec.rb +0 -90
- data/spec/filters/dynamic_inliner_spec.rb +0 -95
- data/spec/filters/eraser_spec.rb +0 -55
- data/spec/filters/escapable_spec.rb +0 -49
- data/spec/filters/multi_flattener_spec.rb +0 -33
- data/spec/filters/static_analyzer_spec.rb +0 -35
- data/spec/filters/static_merger_spec.rb +0 -41
- data/spec/filters/string_splitter_spec.rb +0 -50
- data/spec/generator_spec.rb +0 -167
- data/spec/grammar_spec.rb +0 -47
- data/spec/html/attribute_merger_spec.rb +0 -76
- data/spec/html/attribute_remover_spec.rb +0 -43
- data/spec/html/attribute_sorter_spec.rb +0 -48
- data/spec/html/fast_spec.rb +0 -97
- data/spec/html/pretty_spec.rb +0 -55
- data/spec/map_spec.rb +0 -39
- data/spec/mixins/dispatcher_spec.rb +0 -70
- data/spec/mixins/grammar_dsl_spec.rb +0 -86
- data/spec/spec_helper.rb +0 -29
- data/spec/static_analyzer_spec.rb +0 -39
- data/spec/utils_spec.rb +0 -39
@@ -1,35 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Temple::Filters::StaticAnalyzer do
|
4
|
-
before do
|
5
|
-
@filter = Temple::Filters::StaticAnalyzer.new
|
6
|
-
@generator = Temple::Generator.new
|
7
|
-
end
|
8
|
-
|
9
|
-
if Temple::StaticAnalyzer.available?
|
10
|
-
it 'should convert :dynamic to :static if code is static' do
|
11
|
-
expect(@filter.call([:dynamic, '"#{"hello"}#{100}"'])).to eq([:static, 'hello100'])
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'should not convert :dynamic if code is dynamic' do
|
15
|
-
exp = [:dynamic, '"#{hello}#{100}"']
|
16
|
-
expect(@filter.call(exp)).to eq(exp)
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'should not change number of newlines in generated code' do
|
20
|
-
exp = [:dynamic, "[100,\n200,\n]"]
|
21
|
-
expect(@filter.call(exp)).to eq([:multi, [:static, '[100, 200]'], [:newline], [:newline]])
|
22
|
-
|
23
|
-
expect(@generator.call(@filter.call(exp)).count("\n")).to eq(@generator.call(exp).count("\n"))
|
24
|
-
end
|
25
|
-
else
|
26
|
-
it 'should do nothing' do
|
27
|
-
[
|
28
|
-
[:dynamic, '"#{"hello"}#{100}"'],
|
29
|
-
[:dynamic, '"#{hello}#{100}"'],
|
30
|
-
].each do |exp|
|
31
|
-
expect(@filter.call(exp)).to eq(exp)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Temple::Filters::StaticMerger do
|
4
|
-
before do
|
5
|
-
@filter = Temple::Filters::StaticMerger.new
|
6
|
-
end
|
7
|
-
|
8
|
-
it 'should merge serveral statics' do
|
9
|
-
expect(@filter.call([:multi,
|
10
|
-
[:static, "Hello "],
|
11
|
-
[:static, "World, "],
|
12
|
-
[:static, "Good night"]
|
13
|
-
])).to eq [:static, "Hello World, Good night"]
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'should merge serveral statics around code' do
|
17
|
-
expect(@filter.call([:multi,
|
18
|
-
[:static, "Hello "],
|
19
|
-
[:static, "World!"],
|
20
|
-
[:code, "123"],
|
21
|
-
[:static, "Good night, "],
|
22
|
-
[:static, "everybody"]
|
23
|
-
])).to eq [:multi,
|
24
|
-
[:static, "Hello World!"],
|
25
|
-
[:code, "123"],
|
26
|
-
[:static, "Good night, everybody"]
|
27
|
-
]
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'should merge serveral statics across newlines' do
|
31
|
-
expect(@filter.call([:multi,
|
32
|
-
[:static, "Hello "],
|
33
|
-
[:static, "World, "],
|
34
|
-
[:newline],
|
35
|
-
[:static, "Good night"]
|
36
|
-
])).to eq [:multi,
|
37
|
-
[:static, "Hello World, Good night"],
|
38
|
-
[:newline]
|
39
|
-
]
|
40
|
-
end
|
41
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
require 'spec_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
|
-
{
|
14
|
-
%q|''| => [:multi],
|
15
|
-
%q|""| => [:multi],
|
16
|
-
%q|"hello"| => [:multi, [:static, 'hello']],
|
17
|
-
%q|"hello #{}world"| => [:multi, [:static, 'hello '], [:static, 'world']],
|
18
|
-
%q|"#{hello}"| => [:multi, [:dynamic, 'hello']],
|
19
|
-
%q|"nya#{123}"| => [:multi, [:static, 'nya'], [:dynamic, '123']],
|
20
|
-
%q|"#{()}()"| => [:multi, [:dynamic, '()'], [:static, '()']],
|
21
|
-
%q|" #{ " #{ '#{}' } " }"| => [:multi, [:static, ' '], [:multi, [:static, ' '], [:multi, [:static, '#{}']], [:static, ' ']]],
|
22
|
-
%q|%Q[a#{b}c#{d}e]| => [:multi, [:static, 'a'], [:dynamic, 'b'], [:static, 'c'], [:dynamic, 'd'], [:static, 'e']],
|
23
|
-
%q|%q[a#{b}c#{d}e]| => [:multi, [:static, 'a#{b}c#{d}e']],
|
24
|
-
%q|"\#{}#{123}"| => [:multi, [:static, '#{}'], [:dynamic, '123']],
|
25
|
-
%q|"#{ '}' }"| => [:multi, [:multi, [:static, '}']]],
|
26
|
-
%q| "a" # hello | => [:multi, [:static, 'a']],
|
27
|
-
%q|"\""| => [:multi, [:static, '"']],
|
28
|
-
%q|"\\\\\\""| => [:multi, [:static, '\\"']],
|
29
|
-
%q|'\"'| => [:multi, [:static, '\"']],
|
30
|
-
%q|'\\\"'| => [:multi, [:static, '\\"']],
|
31
|
-
%q|"static#{dynamic}"| => [:multi, [:static, 'static'], [:dynamic, 'dynamic']],
|
32
|
-
}.each do |code, expected|
|
33
|
-
it "should split #{code}" do
|
34
|
-
actual = @filter.call([:dynamic, code])
|
35
|
-
expect(actual).to eq(expected)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
describe '.compile' do
|
40
|
-
it 'should raise CompileError for non-string literals' do
|
41
|
-
expect { Temple::Filters::StringSplitter.compile('1') }.to raise_error(Temple::FilterError)
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'should compile strings quoted with parenthesis' do
|
45
|
-
tokens = Temple::Filters::StringSplitter.compile('%Q(href("#{1 + 1}");)')
|
46
|
-
expect(tokens).to eq([[:static, "href(\""], [:dynamic, "1 + 1"], [:static, "\");"]])
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
data/spec/generator_spec.rb
DELETED
@@ -1,167 +0,0 @@
|
|
1
|
-
require 'spec_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
|
-
expect(gen.call([:static, 'test'])).to eq('_buf = BUFFER; _buf << (S:test); _buf')
|
30
|
-
expect(gen.call([:dynamic, 'test'])).to eq('_buf = BUFFER; _buf << (D:test); _buf')
|
31
|
-
expect(gen.call([:code, 'test'])).to eq('_buf = BUFFER; C:test; _buf')
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'should compile multi expression' do
|
35
|
-
gen = SimpleGenerator.new(buffer: "VAR")
|
36
|
-
expect(gen.call([:multi,
|
37
|
-
[:static, "static"],
|
38
|
-
[:dynamic, "dynamic"],
|
39
|
-
[:code, "code"]
|
40
|
-
])).to eq('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
|
-
expect(gen.call([:capture, "foo",
|
46
|
-
[:static, "test"]
|
47
|
-
])).to eq('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
|
-
expect(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
|
-
])).to eq('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 nested capture with the same capture_generator' do
|
66
|
-
gen = SimpleGenerator.new(buffer: "VAR", capture_generator: SimpleGenerator)
|
67
|
-
expect(gen.call([:capture, "foo", [:multi,
|
68
|
-
[:capture, "bar", [:multi,
|
69
|
-
[:static, "a"],
|
70
|
-
[:static, "b"]]]]
|
71
|
-
])).to eq "VAR = BUFFER; foo = BUFFER; bar = BUFFER; bar << (S:a); bar << (S:b); bar; foo; VAR"
|
72
|
-
end
|
73
|
-
|
74
|
-
it 'should compile newlines' do
|
75
|
-
gen = SimpleGenerator.new(buffer: "VAR")
|
76
|
-
expect(gen.call([:multi,
|
77
|
-
[:static, "static"],
|
78
|
-
[:newline],
|
79
|
-
[:dynamic, "dynamic"],
|
80
|
-
[:newline],
|
81
|
-
[:code, "code"]
|
82
|
-
])).to eq("VAR = BUFFER; VAR << (S:static); \n; " +
|
83
|
-
"VAR << (D:dynamic); \n; C:code; VAR")
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
describe Temple::Generators::Array do
|
88
|
-
it 'should compile simple expressions' do
|
89
|
-
gen = Temple::Generators::Array.new(freeze_static: false)
|
90
|
-
expect(gen.call([:static, 'test'])).to eq('_buf = []; _buf << ("test"); _buf')
|
91
|
-
expect(gen.call([:dynamic, 'test'])).to eq('_buf = []; _buf << (test); _buf')
|
92
|
-
expect(gen.call([:code, 'test'])).to eq('_buf = []; test; _buf')
|
93
|
-
|
94
|
-
expect(gen.call([:multi, [:static, 'a'], [:static, 'b']])).to eq('_buf = []; _buf << ("a"); _buf << ("b"); _buf')
|
95
|
-
expect(gen.call([:multi, [:static, 'a'], [:dynamic, 'b']])).to eq('_buf = []; _buf << ("a"); _buf << (b); _buf')
|
96
|
-
end
|
97
|
-
|
98
|
-
it 'should freeze static' do
|
99
|
-
gen = Temple::Generators::Array.new(freeze_static: true)
|
100
|
-
expect(gen.call([:static, 'test'])).to eq('_buf = []; _buf << ("test".freeze); _buf')
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
describe Temple::Generators::ArrayBuffer do
|
105
|
-
it 'should compile simple expressions' do
|
106
|
-
gen = Temple::Generators::ArrayBuffer.new(freeze_static: false)
|
107
|
-
expect(gen.call([:static, 'test'])).to eq('_buf = "test"')
|
108
|
-
expect(gen.call([:dynamic, 'test'])).to eq('_buf = (test).to_s')
|
109
|
-
expect(gen.call([:code, 'test'])).to eq('_buf = []; test; _buf = _buf.join("")')
|
110
|
-
|
111
|
-
expect(gen.call([:multi, [:static, 'a'], [:static, 'b']])).to eq('_buf = []; _buf << ("a"); _buf << ("b"); _buf = _buf.join("")')
|
112
|
-
expect(gen.call([:multi, [:static, 'a'], [:dynamic, 'b']])).to eq('_buf = []; _buf << ("a"); _buf << (b); _buf = _buf.join("")')
|
113
|
-
end
|
114
|
-
|
115
|
-
it 'should freeze static' do
|
116
|
-
gen = Temple::Generators::ArrayBuffer.new(freeze_static: true)
|
117
|
-
expect(gen.call([:static, 'test'])).to eq('_buf = "test"')
|
118
|
-
expect(gen.call([:multi, [:dynamic, '1'], [:static, 'test']])).to eq('_buf = []; _buf << (1); _buf << ("test".freeze); _buf = _buf.join("".freeze)')
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
describe Temple::Generators::StringBuffer do
|
123
|
-
it 'should compile simple expressions' do
|
124
|
-
gen = Temple::Generators::StringBuffer.new(freeze_static: false)
|
125
|
-
expect(gen.call([:static, 'test'])).to eq('_buf = "test"')
|
126
|
-
expect(gen.call([:dynamic, 'test'])).to eq('_buf = (test).to_s')
|
127
|
-
expect(gen.call([:code, 'test'])).to eq('_buf = \'\'; test; _buf')
|
128
|
-
|
129
|
-
expect(gen.call([:multi, [:static, 'a'], [:static, 'b']])).to eq('_buf = \'\'; _buf << ("a"); _buf << ("b"); _buf')
|
130
|
-
expect(gen.call([:multi, [:static, 'a'], [:dynamic, 'b']])).to eq('_buf = \'\'; _buf << ("a"); _buf << ((b).to_s); _buf')
|
131
|
-
end
|
132
|
-
|
133
|
-
it 'should freeze static' do
|
134
|
-
gen = Temple::Generators::StringBuffer.new(freeze_static: true)
|
135
|
-
expect(gen.call([:static, 'test'])).to eq('_buf = "test"')
|
136
|
-
expect(gen.call([:multi, [:dynamic, '1'], [:static, 'test']])).to eq('_buf = \'\'; _buf << ((1).to_s); _buf << ("test".freeze); _buf')
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
describe Temple::Generators::ERB do
|
141
|
-
it 'should compile simple expressions' do
|
142
|
-
gen = Temple::Generators::ERB.new
|
143
|
-
expect(gen.call([:static, 'test'])).to eq('test')
|
144
|
-
expect(gen.call([:dynamic, 'test'])).to eq('<%= test %>')
|
145
|
-
expect(gen.call([:code, 'test'])).to eq('<% test %>')
|
146
|
-
|
147
|
-
expect(gen.call([:multi, [:static, 'a'], [:static, 'b']])).to eq('ab')
|
148
|
-
expect(gen.call([:multi, [:static, 'a'], [:dynamic, 'b']])).to eq('a<%= b %>')
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
describe Temple::Generators::RailsOutputBuffer do
|
153
|
-
it 'should compile simple expressions' do
|
154
|
-
gen = Temple::Generators::RailsOutputBuffer.new(freeze_static: false)
|
155
|
-
expect(gen.call([:static, 'test'])).to eq('@output_buffer = output_buffer || ActionView::OutputBuffer.new; ' +
|
156
|
-
'@output_buffer.safe_concat(("test")); @output_buffer')
|
157
|
-
expect(gen.call([:dynamic, 'test'])).to eq('@output_buffer = output_buffer || ActionView::OutputBuffer.new; ' +
|
158
|
-
'@output_buffer.safe_concat(((test).to_s)); @output_buffer')
|
159
|
-
expect(gen.call([:code, 'test'])).to eq('@output_buffer = output_buffer || ActionView::OutputBuffer.new; ' +
|
160
|
-
'test; @output_buffer')
|
161
|
-
end
|
162
|
-
|
163
|
-
it 'should freeze static' do
|
164
|
-
gen = Temple::Generators::RailsOutputBuffer.new(freeze_static: true)
|
165
|
-
expect(gen.call([:static, 'test'])).to eq('@output_buffer = output_buffer || ActionView::OutputBuffer.new; @output_buffer.safe_concat(("test".freeze)); @output_buffer')
|
166
|
-
end
|
167
|
-
end
|
data/spec/grammar_spec.rb
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Temple::Grammar do
|
4
|
-
it 'should match core expressions' do
|
5
|
-
expect(Temple::Grammar).to be_match([:multi])
|
6
|
-
expect(Temple::Grammar).to be_match([:multi, [:multi]])
|
7
|
-
expect(Temple::Grammar).to be_match([:static, 'Text'])
|
8
|
-
expect(Temple::Grammar).to be_match([:dynamic, 'Text'])
|
9
|
-
expect(Temple::Grammar).to be_match([:code, 'Text'])
|
10
|
-
expect(Temple::Grammar).to be_match([:capture, 'Text', [:multi]])
|
11
|
-
expect(Temple::Grammar).to be_match([:newline])
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'should not match invalid core expressions' do
|
15
|
-
expect(Temple::Grammar).not_to be_match([:multi, 'String'])
|
16
|
-
expect(Temple::Grammar).not_to be_match([:static])
|
17
|
-
expect(Temple::Grammar).not_to be_match([:dynamic, 1])
|
18
|
-
expect(Temple::Grammar).not_to be_match([:code, :sym])
|
19
|
-
expect(Temple::Grammar).not_to be_match([:capture, [:multi]])
|
20
|
-
expect(Temple::Grammar).not_to be_match([:newline, [:multi]])
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'should match control flow expressions' do
|
24
|
-
expect(Temple::Grammar).to be_match([:if, 'Condition', [:multi]])
|
25
|
-
expect(Temple::Grammar).to be_match([:if, 'Condition', [:multi], [:multi]])
|
26
|
-
expect(Temple::Grammar).to be_match([:block, 'Loop', [:multi]])
|
27
|
-
expect(Temple::Grammar).to be_match([:case, 'Arg', ['Cond1', [:multi]], ['Cond1', [:multi]], [:else, [:multi]]])
|
28
|
-
expect(Temple::Grammar).not_to be_match([:case, 'Arg', [:sym, [:multi]]])
|
29
|
-
expect(Temple::Grammar).to be_match([:cond, ['Cond1', [:multi]], ['Cond2', [:multi]], [:else, [:multi]]])
|
30
|
-
expect(Temple::Grammar).not_to be_match([:cond, [:sym, [:multi]]])
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'should match escape expression' do
|
34
|
-
expect(Temple::Grammar).to be_match([:escape, true, [:multi]])
|
35
|
-
expect(Temple::Grammar).to be_match([:escape, false, [:multi]])
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'should match html expressions' do
|
39
|
-
expect(Temple::Grammar).to be_match([:html, :doctype, 'Doctype'])
|
40
|
-
expect(Temple::Grammar).to be_match([:html, :comment, [:multi]])
|
41
|
-
expect(Temple::Grammar).to be_match([:html, :tag, 'Tag', [:multi]])
|
42
|
-
expect(Temple::Grammar).to be_match([:html, :tag, 'Tag', [:multi], [:multi]])
|
43
|
-
expect(Temple::Grammar).to be_match([:html, :tag, 'Tag', [:multi], [:static, 'Text']])
|
44
|
-
expect(Temple::Grammar).to be_match([:html, :tag, 'Tag', [:html, :attrs, [:html, :attr, 'id',
|
45
|
-
[:static, 'val']]], [:static, 'Text']])
|
46
|
-
end
|
47
|
-
end
|
@@ -1,76 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Temple::HTML::AttributeMerger do
|
4
|
-
before do
|
5
|
-
@merger = Temple::HTML::AttributeMerger.new
|
6
|
-
end
|
7
|
-
|
8
|
-
it 'should pass static attributes through' do
|
9
|
-
expect(@merger.call([:html, :tag,
|
10
|
-
'div',
|
11
|
-
[:html, :attrs, [:html, :attr, 'class', [:static, 'b']]],
|
12
|
-
[:content]
|
13
|
-
])).to eq [:html, :tag, "div",
|
14
|
-
[:html, :attrs,
|
15
|
-
[:html, :attr, "class", [:static, "b"]]],
|
16
|
-
[:content]]
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'should preserve the order of html attributes' do
|
20
|
-
expect(@merger.call([:html, :tag,
|
21
|
-
'meta',
|
22
|
-
[:html, :attrs, [:html, :attr, 'c', [:static, '1']],
|
23
|
-
[:html, :attr, 'd', [:static, '2']],
|
24
|
-
[:html, :attr, 'a', [:static, '3']],
|
25
|
-
[:html, :attr, 'b', [:static, '4']]]
|
26
|
-
])).to eq [:html, :tag, 'meta',
|
27
|
-
[:html, :attrs,
|
28
|
-
[:html, :attr, 'c', [:static, '1']],
|
29
|
-
[:html, :attr, 'd', [:static, '2']],
|
30
|
-
[:html, :attr, 'a', [:static, '3']],
|
31
|
-
[:html, :attr, 'b', [:static, '4']]]]
|
32
|
-
|
33
|
-
# Use case:
|
34
|
-
expect(@merger.call([:html, :tag,
|
35
|
-
'meta',
|
36
|
-
[:html, :attrs, [:html, :attr, 'http-equiv', [:static, 'Content-Type']],
|
37
|
-
[:html, :attr, 'content', [:static, '']]]
|
38
|
-
])).to eq [:html, :tag, 'meta',
|
39
|
-
[:html, :attrs,
|
40
|
-
[:html, :attr, 'http-equiv', [:static, 'Content-Type']],
|
41
|
-
[:html, :attr, 'content', [:static, '']]]]
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'should merge ids' do
|
45
|
-
expect(@merger.call([:html, :tag,
|
46
|
-
'div',
|
47
|
-
[:html, :attrs, [:html, :attr, 'id', [:dynamic, 'a']], [:html, :attr, 'id', [:dynamic, 'b']]],
|
48
|
-
[:content]
|
49
|
-
])).to eq [:html, :tag, "div",
|
50
|
-
[:html, :attrs,
|
51
|
-
[:html, :attr, "id",
|
52
|
-
[:multi,
|
53
|
-
[:code, "_temple_html_attributemerger1 = []"],
|
54
|
-
[:capture, "_temple_html_attributemerger1[0]", [:dynamic, "a"]],
|
55
|
-
[:capture, "_temple_html_attributemerger1[1]", [:dynamic, "b"]],
|
56
|
-
[:dynamic, "_temple_html_attributemerger1.reject(&:empty?).join(\"_\")"]]]],
|
57
|
-
[:content]]
|
58
|
-
end
|
59
|
-
|
60
|
-
it 'should merge classes' do
|
61
|
-
expect(@merger.call([:html, :tag,
|
62
|
-
'div',
|
63
|
-
[:html, :attrs, [:html, :attr, 'class', [:static, 'a']], [:html, :attr, 'class', [:dynamic, 'b']]],
|
64
|
-
[:content]
|
65
|
-
])).to eq [:html, :tag, "div",
|
66
|
-
[:html, :attrs,
|
67
|
-
[:html, :attr, "class",
|
68
|
-
[:multi,
|
69
|
-
[:code, "_temple_html_attributemerger1 = []"],
|
70
|
-
[:capture, "_temple_html_attributemerger1[0]", [:static, "a"]],
|
71
|
-
[:capture, "_temple_html_attributemerger1[1]", [:dynamic, "b"]],
|
72
|
-
[:dynamic, "_temple_html_attributemerger1.reject(&:empty?).join(\" \")"]]]],
|
73
|
-
[:content]]
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
@@ -1,43 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Temple::HTML::AttributeRemover do
|
4
|
-
before do
|
5
|
-
@remover = Temple::HTML::AttributeRemover.new
|
6
|
-
end
|
7
|
-
|
8
|
-
it 'should pass static attributes through' do
|
9
|
-
expect(@remover.call([:html, :tag,
|
10
|
-
'div',
|
11
|
-
[:html, :attrs, [:html, :attr, 'class', [:static, 'b']]],
|
12
|
-
[:content]
|
13
|
-
])).to eq [:html, :tag, "div",
|
14
|
-
[:multi,
|
15
|
-
[:html, :attr, "class", [:static, "b"]]],
|
16
|
-
[:content]]
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'should check for empty dynamic attribute if it is included in :remove_empty_attrs' do
|
20
|
-
expect(@remover.call([:html, :tag,
|
21
|
-
'div',
|
22
|
-
[:html, :attrs, [:html, :attr, 'class', [:dynamic, 'b']]],
|
23
|
-
[:content]
|
24
|
-
])).to eq [:html, :tag, "div",
|
25
|
-
[:multi,
|
26
|
-
[:multi,
|
27
|
-
[:capture, "_temple_html_attributeremover1", [:dynamic, "b"]],
|
28
|
-
[:if, "!_temple_html_attributeremover1.empty?",
|
29
|
-
[:html, :attr, "class", [:dynamic, "_temple_html_attributeremover1"]]]]],
|
30
|
-
[:content]]
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'should not check for empty dynamic attribute if it is not included in :remove_empty_attrs' do
|
34
|
-
expect(@remover.call([:html, :tag,
|
35
|
-
'div',
|
36
|
-
[:html, :attrs, [:html, :attr, 'name', [:dynamic, 'b']]],
|
37
|
-
[:content]
|
38
|
-
])).to eq [:html, :tag, "div",
|
39
|
-
[:multi,
|
40
|
-
[:html, :attr, "name", [:dynamic, "b"]]],
|
41
|
-
[:content]]
|
42
|
-
end
|
43
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Temple::HTML::AttributeSorter do
|
4
|
-
before do
|
5
|
-
@ordered = Temple::HTML::AttributeSorter.new
|
6
|
-
@unordered = Temple::HTML::AttributeSorter.new sort_attrs: false
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'should sort html attributes by name by default, when :sort_attrs is true' do
|
10
|
-
expect(@ordered.call([:html, :tag,
|
11
|
-
'meta',
|
12
|
-
[:html, :attrs, [:html, :attr, 'c', [:static, '1']],
|
13
|
-
[:html, :attr, 'd', [:static, '2']],
|
14
|
-
[:html, :attr, 'a', [:static, '3']],
|
15
|
-
[:html, :attr, 'b', [:static, '4']]]
|
16
|
-
])).to eq [:html, :tag, 'meta',
|
17
|
-
[:html, :attrs,
|
18
|
-
[:html, :attr, 'a', [:static, '3']],
|
19
|
-
[:html, :attr, 'b', [:static, '4']],
|
20
|
-
[:html, :attr, 'c', [:static, '1']],
|
21
|
-
[:html, :attr, 'd', [:static, '2']]]]
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'should preserve the order of html attributes when :sort_attrs is false' do
|
25
|
-
expect(@unordered.call([:html, :tag,
|
26
|
-
'meta',
|
27
|
-
[:html, :attrs, [:html, :attr, 'c', [:static, '1']],
|
28
|
-
[:html, :attr, 'd', [:static, '2']],
|
29
|
-
[:html, :attr, 'a', [:static, '3']],
|
30
|
-
[:html, :attr, 'b', [:static, '4']]]
|
31
|
-
])).to eq [:html, :tag, 'meta',
|
32
|
-
[:html, :attrs,
|
33
|
-
[:html, :attr, 'c', [:static, '1']],
|
34
|
-
[:html, :attr, 'd', [:static, '2']],
|
35
|
-
[:html, :attr, 'a', [:static, '3']],
|
36
|
-
[:html, :attr, 'b', [:static, '4']]]]
|
37
|
-
|
38
|
-
# Use case:
|
39
|
-
expect(@unordered.call([:html, :tag,
|
40
|
-
'meta',
|
41
|
-
[:html, :attrs, [:html, :attr, 'http-equiv', [:static, 'Content-Type']],
|
42
|
-
[:html, :attr, 'content', [:static, '']]]
|
43
|
-
])).to eq [:html, :tag, 'meta',
|
44
|
-
[:html, :attrs,
|
45
|
-
[:html, :attr, 'http-equiv', [:static, 'Content-Type']],
|
46
|
-
[:html, :attr, 'content', [:static, '']]]]
|
47
|
-
end
|
48
|
-
end
|
data/spec/html/fast_spec.rb
DELETED
@@ -1,97 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Temple::HTML::Fast do
|
4
|
-
before do
|
5
|
-
@html = Temple::HTML::Fast.new
|
6
|
-
end
|
7
|
-
|
8
|
-
it 'should compile html doctype' do
|
9
|
-
expect(@html.call([:multi, [:html, :doctype, '5']])).to eq([:multi, [:static, '<!DOCTYPE html>']])
|
10
|
-
expect(@html.call([:multi, [:html, :doctype, 'html']])).to eq([:multi, [:static, '<!DOCTYPE html>']])
|
11
|
-
expect(@html.call([:multi, [:html, :doctype, '1.1']])).to eq [:multi,
|
12
|
-
[:static, '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">']]
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'should compile xml encoding' do
|
16
|
-
expect(@html.call([:html, :doctype, 'xml latin1'])).to eq([:static, "<?xml version=\"1.0\" encoding=\"latin1\" ?>"])
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'should compile html comment' do
|
20
|
-
expect(@html.call([:html, :comment, [:static, 'test']])).to eq([:multi, [:static, "<!--"], [:static, "test"], [:static, "-->"]])
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'should compile js wrapped in comments' do
|
24
|
-
expect(Temple::HTML::Fast.new(js_wrapper: nil).call([:html, :js, [:static, 'test']])).to eq([:static, "test"])
|
25
|
-
expect(Temple::HTML::Fast.new(js_wrapper: :comment).call([:html, :js, [:static, 'test']])).to eq([:multi, [:static, "<!--\n"], [:static, "test"], [:static, "\n//-->"]])
|
26
|
-
expect(Temple::HTML::Fast.new(js_wrapper: :cdata).call([:html, :js, [:static, 'test']])).to eq([:multi, [:static, "\n//<![CDATA[\n"], [:static, "test"], [:static, "\n//]]>\n"]])
|
27
|
-
expect(Temple::HTML::Fast.new(js_wrapper: :both).call([:html, :js, [:static, 'test']])).to eq([:multi, [:static, "<!--\n//<![CDATA[\n"], [:static, "test"], [:static, "\n//]]>\n//-->"]])
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'should guess default js comment' do
|
31
|
-
expect(Temple::HTML::Fast.new(js_wrapper: :guess, format: :xhtml).call([:html, :js, [:static, 'test']])).to eq([:multi, [:static, "\n//<![CDATA[\n"], [:static, "test"], [:static, "\n//]]>\n"]])
|
32
|
-
expect(Temple::HTML::Fast.new(js_wrapper: :guess, format: :html).call([:html, :js, [:static, 'test']])).to eq([:multi, [:static, "<!--\n"], [:static, "test"], [:static, "\n//-->"]])
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'should compile autoclosed html tag' do
|
36
|
-
expect(@html.call([:html, :tag,
|
37
|
-
'img', [:attrs],
|
38
|
-
[:multi, [:newline]]
|
39
|
-
])).to eq [:multi,
|
40
|
-
[:static, "<img"],
|
41
|
-
[:attrs],
|
42
|
-
[:static, " />"],
|
43
|
-
[:multi, [:newline]]]
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'should compile explicitly closed html tag' do
|
47
|
-
expect(@html.call([:html, :tag,
|
48
|
-
'closed', [:attrs]
|
49
|
-
])).to eq [:multi,
|
50
|
-
[:static, "<closed"],
|
51
|
-
[:attrs],
|
52
|
-
[:static, " />"]]
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'should compile html with content' do
|
56
|
-
expect(@html.call([:html, :tag,
|
57
|
-
'div', [:attrs], [:content]
|
58
|
-
])).to eq [:multi,
|
59
|
-
[:static, "<div"],
|
60
|
-
[:attrs],
|
61
|
-
[:static, ">"],
|
62
|
-
[:content],
|
63
|
-
[:static, "</div>"]]
|
64
|
-
end
|
65
|
-
|
66
|
-
it 'should compile html with attrs' do
|
67
|
-
expect(@html.call([:html, :tag,
|
68
|
-
'div',
|
69
|
-
[:html, :attrs,
|
70
|
-
[:html, :attr, 'id', [:static, 'test']],
|
71
|
-
[:html, :attr, 'class', [:dynamic, 'block']]],
|
72
|
-
[:content]
|
73
|
-
])).to eq [:multi,
|
74
|
-
[:static, "<div"],
|
75
|
-
[:multi,
|
76
|
-
[:multi, [:static, " id=\""], [:static, "test"], [:static, '"']],
|
77
|
-
[:multi, [:static, " class=\""], [:dynamic, "block"], [:static, '"']]],
|
78
|
-
[:static, ">"],
|
79
|
-
[:content],
|
80
|
-
[:static, "</div>"]]
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'should keep codes intact' do
|
84
|
-
exp = [:multi, [:code, 'foo']]
|
85
|
-
expect(@html.call(exp)).to eq(exp)
|
86
|
-
end
|
87
|
-
|
88
|
-
it 'should keep statics intact' do
|
89
|
-
exp = [:multi, [:static, '<']]
|
90
|
-
expect(@html.call(exp)).to eq(exp)
|
91
|
-
end
|
92
|
-
|
93
|
-
it 'should keep dynamic intact' do
|
94
|
-
exp = [:multi, [:dynamic, 'foo']]
|
95
|
-
expect(@html.call(exp)).to eq(exp)
|
96
|
-
end
|
97
|
-
end
|
data/spec/html/pretty_spec.rb
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Temple::HTML::Pretty do
|
4
|
-
before do
|
5
|
-
@html = Temple::HTML::Pretty.new
|
6
|
-
end
|
7
|
-
|
8
|
-
it 'should indent nested tags' do
|
9
|
-
expect(@html.call([:html, :tag, 'div', [:multi],
|
10
|
-
[:html, :tag, 'p', [:multi], [:multi, [:static, 'text'], [:dynamic, 'code']]]
|
11
|
-
])).to eq [:multi,
|
12
|
-
[:code, "_temple_html_pretty1 = /<code|<pre|<textarea/"],
|
13
|
-
[:multi,
|
14
|
-
[:static, "<div"],
|
15
|
-
[:multi],
|
16
|
-
[:static, ">"],
|
17
|
-
[:multi,
|
18
|
-
[:static, "\n <p"],
|
19
|
-
[:multi],
|
20
|
-
[:static, ">"],
|
21
|
-
[:multi,
|
22
|
-
[:static, "\n text"],
|
23
|
-
[:dynamic, "::Temple::Utils.indent_dynamic((code), false, \"\\n \", _temple_html_pretty1)"]],
|
24
|
-
[:static, "\n </p>"]],
|
25
|
-
[:static, "\n</div>"]]]
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'should not indent preformatted tags' do
|
29
|
-
expect(@html.call([:html, :tag, 'pre', [:multi],
|
30
|
-
[:html, :tag, 'p', [:multi], [:static, 'text']]
|
31
|
-
])).to eq [:multi,
|
32
|
-
[:code, "_temple_html_pretty1 = /<code|<pre|<textarea/"],
|
33
|
-
[:multi,
|
34
|
-
[:static, "<pre"],
|
35
|
-
[:multi],
|
36
|
-
[:static, ">"],
|
37
|
-
[:multi,
|
38
|
-
[:static, "<p"],
|
39
|
-
[:multi],
|
40
|
-
[:static, ">"],
|
41
|
-
[:static, "text"],
|
42
|
-
[:static, "</p>"]],
|
43
|
-
[:static, "</pre>"]]]
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'should not escape html_safe strings' do
|
47
|
-
with_html_safe do
|
48
|
-
expect(@html.call(
|
49
|
-
[:dynamic, '"text<".html_safe']
|
50
|
-
)).to eq [:multi,
|
51
|
-
[:code, "_temple_html_pretty1 = /<code|<pre|<textarea/"],
|
52
|
-
[:dynamic, "::Temple::Utils.indent_dynamic((\"text<\".html_safe), nil, \"\\n\", _temple_html_pretty1)"]]
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|