temple 0.8.2 → 0.10.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/test.yml +35 -0
  3. data/.gitignore +1 -0
  4. data/CHANGES +34 -1
  5. data/Gemfile +0 -1
  6. data/README.md +1 -1
  7. data/Rakefile +4 -11
  8. data/lib/temple/engine.rb +1 -0
  9. data/lib/temple/erb/engine.rb +3 -0
  10. data/lib/temple/erb/parser.rb +2 -1
  11. data/lib/temple/erb/template.rb +1 -0
  12. data/lib/temple/erb/trimming.rb +1 -0
  13. data/lib/temple/exceptions.rb +1 -0
  14. data/lib/temple/filter.rb +1 -0
  15. data/lib/temple/filters/ambles.rb +22 -0
  16. data/lib/temple/filters/code_merger.rb +1 -0
  17. data/lib/temple/filters/control_flow.rb +1 -0
  18. data/lib/temple/filters/dynamic_inliner.rb +2 -1
  19. data/lib/temple/filters/encoding.rb +1 -0
  20. data/lib/temple/filters/eraser.rb +1 -0
  21. data/lib/temple/filters/escapable.rb +1 -0
  22. data/lib/temple/filters/multi_flattener.rb +1 -0
  23. data/lib/temple/filters/remove_bom.rb +1 -0
  24. data/lib/temple/filters/static_analyzer.rb +1 -0
  25. data/lib/temple/filters/static_merger.rb +1 -0
  26. data/lib/temple/filters/string_splitter.rb +13 -1
  27. data/lib/temple/filters/validator.rb +1 -0
  28. data/lib/temple/generator.rb +5 -2
  29. data/lib/temple/generators/array.rb +1 -0
  30. data/lib/temple/generators/array_buffer.rb +1 -0
  31. data/lib/temple/generators/erb.rb +1 -0
  32. data/lib/temple/generators/rails_output_buffer.rb +4 -4
  33. data/lib/temple/generators/string_buffer.rb +2 -1
  34. data/lib/temple/grammar.rb +1 -0
  35. data/lib/temple/html/attribute_merger.rb +1 -0
  36. data/lib/temple/html/attribute_remover.rb +1 -0
  37. data/lib/temple/html/attribute_sorter.rb +1 -0
  38. data/lib/temple/html/dispatcher.rb +1 -0
  39. data/lib/temple/html/fast.rb +1 -0
  40. data/lib/temple/html/filter.rb +1 -0
  41. data/lib/temple/html/pretty.rb +1 -0
  42. data/lib/temple/html/safe.rb +1 -0
  43. data/lib/temple/map.rb +1 -0
  44. data/lib/temple/mixins/dispatcher.rb +1 -0
  45. data/lib/temple/mixins/engine_dsl.rb +1 -0
  46. data/lib/temple/mixins/grammar_dsl.rb +4 -2
  47. data/lib/temple/mixins/options.rb +1 -0
  48. data/lib/temple/mixins/template.rb +1 -0
  49. data/lib/temple/parser.rb +1 -0
  50. data/lib/temple/static_analyzer.rb +1 -0
  51. data/lib/temple/templates/rails.rb +7 -2
  52. data/lib/temple/templates/tilt.rb +2 -9
  53. data/lib/temple/templates.rb +1 -0
  54. data/lib/temple/utils.rb +5 -15
  55. data/lib/temple/version.rb +2 -1
  56. data/lib/temple.rb +2 -0
  57. data/spec/engine_spec.rb +189 -0
  58. data/{test/test_erb.rb → spec/erb_spec.rb} +12 -12
  59. data/spec/filter_spec.rb +29 -0
  60. data/{test/filters/test_code_merger.rb → spec/filters/code_merger_spec.rb} +7 -7
  61. data/{test/filters/test_control_flow.rb → spec/filters/control_flow_spec.rb} +13 -13
  62. data/{test/filters/test_dynamic_inliner.rb → spec/filters/dynamic_inliner_spec.rb} +18 -18
  63. data/{test/filters/test_eraser.rb → spec/filters/eraser_spec.rb} +9 -9
  64. data/{test/filters/test_escapable.rb → spec/filters/escapable_spec.rb} +10 -10
  65. data/{test/filters/test_multi_flattener.rb → spec/filters/multi_flattener_spec.rb} +4 -4
  66. data/{test/filters/test_static_analyzer.rb → spec/filters/static_analyzer_spec.rb} +6 -8
  67. data/{test/filters/test_static_merger.rb → spec/filters/static_merger_spec.rb} +7 -7
  68. data/spec/filters/string_splitter_spec.rb +50 -0
  69. data/spec/generator_spec.rb +179 -0
  70. data/spec/grammar_spec.rb +47 -0
  71. data/{test/html/test_attribute_merger.rb → spec/html/attribute_merger_spec.rb} +11 -11
  72. data/{test/html/test_attribute_remover.rb → spec/html/attribute_remover_spec.rb} +7 -7
  73. data/{test/html/test_attribute_sorter.rb → spec/html/attribute_sorter_spec.rb} +7 -7
  74. data/{test/html/test_fast.rb → spec/html/fast_spec.rb} +23 -23
  75. data/{test/html/test_pretty.rb → spec/html/pretty_spec.rb} +7 -7
  76. data/spec/map_spec.rb +39 -0
  77. data/{test/mixins/test_dispatcher.rb → spec/mixins/dispatcher_spec.rb} +12 -12
  78. data/{test/mixins/test_grammar_dsl.rb → spec/mixins/grammar_dsl_spec.rb} +19 -19
  79. data/{test/helper.rb → spec/spec_helper.rb} +5 -6
  80. data/{test/test_static_analyzer.rb → spec/static_analyzer_spec.rb} +6 -6
  81. data/spec/utils_spec.rb +39 -0
  82. data/temple.gemspec +3 -4
  83. metadata +34 -59
  84. data/.travis.yml +0 -30
  85. data/test/filters/test_string_splitter.rb +0 -25
  86. data/test/test_engine.rb +0 -189
  87. data/test/test_filter.rb +0 -29
  88. data/test/test_generator.rb +0 -158
  89. data/test/test_grammar.rb +0 -47
  90. data/test/test_map.rb +0 -39
  91. data/test/test_utils.rb +0 -39
@@ -1,4 +1,4 @@
1
- require 'helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Temple::Filters::StaticAnalyzer do
4
4
  before do
@@ -8,21 +8,19 @@ describe Temple::Filters::StaticAnalyzer do
8
8
 
9
9
  if Temple::StaticAnalyzer.available?
10
10
  it 'should convert :dynamic to :static if code is static' do
11
- @filter.call([:dynamic, '"#{"hello"}#{100}"']
12
- ).should.equal [:static, 'hello100']
11
+ expect(@filter.call([:dynamic, '"#{"hello"}#{100}"'])).to eq([:static, 'hello100'])
13
12
  end
14
13
 
15
14
  it 'should not convert :dynamic if code is dynamic' do
16
15
  exp = [:dynamic, '"#{hello}#{100}"']
17
- @filter.call(exp).should.equal(exp)
16
+ expect(@filter.call(exp)).to eq(exp)
18
17
  end
19
18
 
20
19
  it 'should not change number of newlines in generated code' do
21
20
  exp = [:dynamic, "[100,\n200,\n]"]
22
- @filter.call(exp).should.equal([:multi, [:static, '[100, 200]'], [:newline], [:newline]])
21
+ expect(@filter.call(exp)).to eq([:multi, [:static, '[100, 200]'], [:newline], [:newline]])
23
22
 
24
- @generator.call(@filter.call(exp)).count("\n").
25
- should.equal(@generator.call(exp).count("\n"))
23
+ expect(@generator.call(@filter.call(exp)).count("\n")).to eq(@generator.call(exp).count("\n"))
26
24
  end
27
25
  else
28
26
  it 'should do nothing' do
@@ -30,7 +28,7 @@ describe Temple::Filters::StaticAnalyzer do
30
28
  [:dynamic, '"#{"hello"}#{100}"'],
31
29
  [:dynamic, '"#{hello}#{100}"'],
32
30
  ].each do |exp|
33
- @filter.call(exp).should.equal(exp)
31
+ expect(@filter.call(exp)).to eq(exp)
34
32
  end
35
33
  end
36
34
  end
@@ -1,4 +1,4 @@
1
- require 'helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Temple::Filters::StaticMerger do
4
4
  before do
@@ -6,21 +6,21 @@ describe Temple::Filters::StaticMerger do
6
6
  end
7
7
 
8
8
  it 'should merge serveral statics' do
9
- @filter.call([:multi,
9
+ expect(@filter.call([:multi,
10
10
  [:static, "Hello "],
11
11
  [:static, "World, "],
12
12
  [:static, "Good night"]
13
- ]).should.equal [:static, "Hello World, Good night"]
13
+ ])).to eq [:static, "Hello World, Good night"]
14
14
  end
15
15
 
16
16
  it 'should merge serveral statics around code' do
17
- @filter.call([:multi,
17
+ expect(@filter.call([:multi,
18
18
  [:static, "Hello "],
19
19
  [:static, "World!"],
20
20
  [:code, "123"],
21
21
  [:static, "Good night, "],
22
22
  [:static, "everybody"]
23
- ]).should.equal [:multi,
23
+ ])).to eq [:multi,
24
24
  [:static, "Hello World!"],
25
25
  [:code, "123"],
26
26
  [:static, "Good night, everybody"]
@@ -28,12 +28,12 @@ describe Temple::Filters::StaticMerger do
28
28
  end
29
29
 
30
30
  it 'should merge serveral statics across newlines' do
31
- @filter.call([:multi,
31
+ expect(@filter.call([:multi,
32
32
  [:static, "Hello "],
33
33
  [:static, "World, "],
34
34
  [:newline],
35
35
  [:static, "Good night"]
36
- ]).should.equal [:multi,
36
+ ])).to eq [:multi,
37
37
  [:static, "Hello World, Good night"],
38
38
  [:newline]
39
39
  ]
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+ begin
3
+ require 'ripper'
4
+ rescue LoadError
5
+ end
6
+
7
+ if defined?(Ripper)
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
@@ -0,0 +1,179 @@
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
+ class SimpleCaptureGenerator < SimpleGenerator
26
+ def preamble
27
+ "#{buffer} = CAPTURE_BUFFER"
28
+ end
29
+ end
30
+
31
+ describe Temple::Generator do
32
+ it 'should compile simple expressions' do
33
+ gen = SimpleGenerator.new
34
+
35
+ expect(gen.call([:static, 'test'])).to eq('_buf = BUFFER; _buf << (S:test); _buf')
36
+ expect(gen.call([:dynamic, 'test'])).to eq('_buf = BUFFER; _buf << (D:test); _buf')
37
+ expect(gen.call([:code, 'test'])).to eq('_buf = BUFFER; C:test; _buf')
38
+ end
39
+
40
+ it 'should compile multi expression' do
41
+ gen = SimpleGenerator.new(buffer: "VAR")
42
+ expect(gen.call([:multi,
43
+ [:static, "static"],
44
+ [:dynamic, "dynamic"],
45
+ [:code, "code"]
46
+ ])).to eq('VAR = BUFFER; VAR << (S:static); VAR << (D:dynamic); C:code; VAR')
47
+ end
48
+
49
+ it 'should compile capture' do
50
+ gen = SimpleGenerator.new(buffer: "VAR", capture_generator: SimpleGenerator)
51
+ expect(gen.call([:capture, "foo",
52
+ [:static, "test"]
53
+ ])).to eq('VAR = BUFFER; foo = BUFFER; foo << (S:test); foo; VAR')
54
+ end
55
+
56
+ it 'should compile capture with multi' do
57
+ gen = SimpleGenerator.new(buffer: "VAR", capture_generator: SimpleGenerator)
58
+ expect(gen.call([:multi,
59
+ [:static, "before"],
60
+
61
+ [:capture, "foo", [:multi,
62
+ [:static, "static"],
63
+ [:dynamic, "dynamic"],
64
+ [:code, "code"]]],
65
+
66
+ [:static, "after"]
67
+ ])).to eq('VAR = BUFFER; VAR << (S:before); foo = BUFFER; foo << (S:static); ' +
68
+ 'foo << (D:dynamic); C:code; foo; VAR << (S:after); VAR')
69
+ end
70
+
71
+ it 'should compile nested captures with the same capture_generator' do
72
+ gen = SimpleGenerator.new(buffer: "VAR", capture_generator: SimpleCaptureGenerator)
73
+ expect(gen.call(
74
+ [:capture, "foo", [:multi,
75
+ [:static, "a"],
76
+ [:capture, "bar", [:multi,
77
+ [:static, "b"],
78
+ [:capture, "baz", [:multi,
79
+ [:static, "c"],
80
+ ]]
81
+ ]]
82
+ ]]
83
+ )).to eq "VAR = BUFFER; foo = CAPTURE_BUFFER; foo << (S:a); bar = CAPTURE_BUFFER; bar << (S:b); baz = CAPTURE_BUFFER; baz << (S:c); baz; bar; foo; VAR"
84
+ end
85
+
86
+ it 'should compile newlines' do
87
+ gen = SimpleGenerator.new(buffer: "VAR")
88
+ expect(gen.call([:multi,
89
+ [:static, "static"],
90
+ [:newline],
91
+ [:dynamic, "dynamic"],
92
+ [:newline],
93
+ [:code, "code"]
94
+ ])).to eq("VAR = BUFFER; VAR << (S:static); \n; " +
95
+ "VAR << (D:dynamic); \n; C:code; VAR")
96
+ end
97
+ end
98
+
99
+ describe Temple::Generators::Array do
100
+ it 'should compile simple expressions' do
101
+ gen = Temple::Generators::Array.new(freeze_static: false)
102
+ expect(gen.call([:static, 'test'])).to eq('_buf = []; _buf << ("test"); _buf')
103
+ expect(gen.call([:dynamic, 'test'])).to eq('_buf = []; _buf << (test); _buf')
104
+ expect(gen.call([:code, 'test'])).to eq('_buf = []; test; _buf')
105
+
106
+ expect(gen.call([:multi, [:static, 'a'], [:static, 'b']])).to eq('_buf = []; _buf << ("a"); _buf << ("b"); _buf')
107
+ expect(gen.call([:multi, [:static, 'a'], [:dynamic, 'b']])).to eq('_buf = []; _buf << ("a"); _buf << (b); _buf')
108
+ end
109
+
110
+ it 'should freeze static' do
111
+ gen = Temple::Generators::Array.new(freeze_static: true)
112
+ expect(gen.call([:static, 'test'])).to eq('_buf = []; _buf << ("test".freeze); _buf')
113
+ end
114
+ end
115
+
116
+ describe Temple::Generators::ArrayBuffer do
117
+ it 'should compile simple expressions' do
118
+ gen = Temple::Generators::ArrayBuffer.new(freeze_static: false)
119
+ expect(gen.call([:static, 'test'])).to eq('_buf = "test"')
120
+ expect(gen.call([:dynamic, 'test'])).to eq('_buf = (test).to_s')
121
+ expect(gen.call([:code, 'test'])).to eq('_buf = []; test; _buf = _buf.join("")')
122
+
123
+ expect(gen.call([:multi, [:static, 'a'], [:static, 'b']])).to eq('_buf = []; _buf << ("a"); _buf << ("b"); _buf = _buf.join("")')
124
+ expect(gen.call([:multi, [:static, 'a'], [:dynamic, 'b']])).to eq('_buf = []; _buf << ("a"); _buf << (b); _buf = _buf.join("")')
125
+ end
126
+
127
+ it 'should freeze static' do
128
+ gen = Temple::Generators::ArrayBuffer.new(freeze_static: true)
129
+ expect(gen.call([:static, 'test'])).to eq('_buf = "test"')
130
+ expect(gen.call([:multi, [:dynamic, '1'], [:static, 'test']])).to eq('_buf = []; _buf << (1); _buf << ("test".freeze); _buf = _buf.join("".freeze)')
131
+ end
132
+ end
133
+
134
+ describe Temple::Generators::StringBuffer do
135
+ it 'should compile simple expressions' do
136
+ gen = Temple::Generators::StringBuffer.new(freeze_static: false)
137
+ expect(gen.call([:static, 'test'])).to eq('_buf = "test"')
138
+ expect(gen.call([:dynamic, 'test'])).to eq('_buf = (test).to_s')
139
+ expect(gen.call([:code, 'test'])).to eq('_buf = \'\'.dup; test; _buf')
140
+
141
+ expect(gen.call([:multi, [:static, 'a'], [:static, 'b']])).to eq('_buf = \'\'.dup; _buf << ("a"); _buf << ("b"); _buf')
142
+ expect(gen.call([:multi, [:static, 'a'], [:dynamic, 'b']])).to eq('_buf = \'\'.dup; _buf << ("a"); _buf << ((b).to_s); _buf')
143
+ end
144
+
145
+ it 'should freeze static' do
146
+ gen = Temple::Generators::StringBuffer.new(freeze_static: true)
147
+ expect(gen.call([:static, 'test'])).to eq('_buf = "test"')
148
+ expect(gen.call([:multi, [:dynamic, '1'], [:static, 'test']])).to eq('_buf = \'\'.dup; _buf << ((1).to_s); _buf << ("test".freeze); _buf')
149
+ end
150
+ end
151
+
152
+ describe Temple::Generators::ERB do
153
+ it 'should compile simple expressions' do
154
+ gen = Temple::Generators::ERB.new
155
+ expect(gen.call([:static, 'test'])).to eq('test')
156
+ expect(gen.call([:dynamic, 'test'])).to eq('<%= test %>')
157
+ expect(gen.call([:code, 'test'])).to eq('<% test %>')
158
+
159
+ expect(gen.call([:multi, [:static, 'a'], [:static, 'b']])).to eq('ab')
160
+ expect(gen.call([:multi, [:static, 'a'], [:dynamic, 'b']])).to eq('a<%= b %>')
161
+ end
162
+ end
163
+
164
+ describe Temple::Generators::RailsOutputBuffer do
165
+ it 'should compile simple expressions' do
166
+ gen = Temple::Generators::RailsOutputBuffer.new(freeze_static: false)
167
+ expect(gen.call([:static, 'test'])).to eq('@output_buffer = output_buffer || ActionView::OutputBuffer.new; ' +
168
+ '@output_buffer.safe_concat(("test")); @output_buffer')
169
+ expect(gen.call([:dynamic, 'test'])).to eq('@output_buffer = output_buffer || ActionView::OutputBuffer.new; ' +
170
+ '@output_buffer.safe_concat(((test).to_s)); @output_buffer')
171
+ expect(gen.call([:code, 'test'])).to eq('@output_buffer = output_buffer || ActionView::OutputBuffer.new; ' +
172
+ 'test; @output_buffer')
173
+ end
174
+
175
+ it 'should freeze static' do
176
+ gen = Temple::Generators::RailsOutputBuffer.new(freeze_static: true)
177
+ expect(gen.call([:static, 'test'])).to eq('@output_buffer = output_buffer || ActionView::OutputBuffer.new; @output_buffer.safe_concat(("test".freeze)); @output_buffer')
178
+ end
179
+ end
@@ -0,0 +1,47 @@
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,4 +1,4 @@
1
- require 'helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Temple::HTML::AttributeMerger do
4
4
  before do
@@ -6,24 +6,24 @@ describe Temple::HTML::AttributeMerger do
6
6
  end
7
7
 
8
8
  it 'should pass static attributes through' do
9
- @merger.call([:html, :tag,
9
+ expect(@merger.call([:html, :tag,
10
10
  'div',
11
11
  [:html, :attrs, [:html, :attr, 'class', [:static, 'b']]],
12
12
  [:content]
13
- ]).should.equal [:html, :tag, "div",
13
+ ])).to eq [:html, :tag, "div",
14
14
  [:html, :attrs,
15
15
  [:html, :attr, "class", [:static, "b"]]],
16
16
  [:content]]
17
17
  end
18
18
 
19
19
  it 'should preserve the order of html attributes' do
20
- @merger.call([:html, :tag,
20
+ expect(@merger.call([:html, :tag,
21
21
  'meta',
22
22
  [:html, :attrs, [:html, :attr, 'c', [:static, '1']],
23
23
  [:html, :attr, 'd', [:static, '2']],
24
24
  [:html, :attr, 'a', [:static, '3']],
25
25
  [:html, :attr, 'b', [:static, '4']]]
26
- ]).should.equal [:html, :tag, 'meta',
26
+ ])).to eq [:html, :tag, 'meta',
27
27
  [:html, :attrs,
28
28
  [:html, :attr, 'c', [:static, '1']],
29
29
  [:html, :attr, 'd', [:static, '2']],
@@ -31,22 +31,22 @@ describe Temple::HTML::AttributeMerger do
31
31
  [:html, :attr, 'b', [:static, '4']]]]
32
32
 
33
33
  # Use case:
34
- @merger.call([:html, :tag,
34
+ expect(@merger.call([:html, :tag,
35
35
  'meta',
36
36
  [:html, :attrs, [:html, :attr, 'http-equiv', [:static, 'Content-Type']],
37
37
  [:html, :attr, 'content', [:static, '']]]
38
- ]).should.equal [:html, :tag, 'meta',
38
+ ])).to eq [:html, :tag, 'meta',
39
39
  [:html, :attrs,
40
40
  [:html, :attr, 'http-equiv', [:static, 'Content-Type']],
41
41
  [:html, :attr, 'content', [:static, '']]]]
42
42
  end
43
43
 
44
44
  it 'should merge ids' do
45
- @merger.call([:html, :tag,
45
+ expect(@merger.call([:html, :tag,
46
46
  'div',
47
47
  [:html, :attrs, [:html, :attr, 'id', [:dynamic, 'a']], [:html, :attr, 'id', [:dynamic, 'b']]],
48
48
  [:content]
49
- ]).should.equal [:html, :tag, "div",
49
+ ])).to eq [:html, :tag, "div",
50
50
  [:html, :attrs,
51
51
  [:html, :attr, "id",
52
52
  [:multi,
@@ -58,11 +58,11 @@ describe Temple::HTML::AttributeMerger do
58
58
  end
59
59
 
60
60
  it 'should merge classes' do
61
- @merger.call([:html, :tag,
61
+ expect(@merger.call([:html, :tag,
62
62
  'div',
63
63
  [:html, :attrs, [:html, :attr, 'class', [:static, 'a']], [:html, :attr, 'class', [:dynamic, 'b']]],
64
64
  [:content]
65
- ]).should.equal [:html, :tag, "div",
65
+ ])).to eq [:html, :tag, "div",
66
66
  [:html, :attrs,
67
67
  [:html, :attr, "class",
68
68
  [:multi,
@@ -1,4 +1,4 @@
1
- require 'helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Temple::HTML::AttributeRemover do
4
4
  before do
@@ -6,22 +6,22 @@ describe Temple::HTML::AttributeRemover do
6
6
  end
7
7
 
8
8
  it 'should pass static attributes through' do
9
- @remover.call([:html, :tag,
9
+ expect(@remover.call([:html, :tag,
10
10
  'div',
11
11
  [:html, :attrs, [:html, :attr, 'class', [:static, 'b']]],
12
12
  [:content]
13
- ]).should.equal [:html, :tag, "div",
13
+ ])).to eq [:html, :tag, "div",
14
14
  [:multi,
15
15
  [:html, :attr, "class", [:static, "b"]]],
16
16
  [:content]]
17
17
  end
18
18
 
19
19
  it 'should check for empty dynamic attribute if it is included in :remove_empty_attrs' do
20
- @remover.call([:html, :tag,
20
+ expect(@remover.call([:html, :tag,
21
21
  'div',
22
22
  [:html, :attrs, [:html, :attr, 'class', [:dynamic, 'b']]],
23
23
  [:content]
24
- ]).should.equal [:html, :tag, "div",
24
+ ])).to eq [:html, :tag, "div",
25
25
  [:multi,
26
26
  [:multi,
27
27
  [:capture, "_temple_html_attributeremover1", [:dynamic, "b"]],
@@ -31,11 +31,11 @@ describe Temple::HTML::AttributeRemover do
31
31
  end
32
32
 
33
33
  it 'should not check for empty dynamic attribute if it is not included in :remove_empty_attrs' do
34
- @remover.call([:html, :tag,
34
+ expect(@remover.call([:html, :tag,
35
35
  'div',
36
36
  [:html, :attrs, [:html, :attr, 'name', [:dynamic, 'b']]],
37
37
  [:content]
38
- ]).should.equal [:html, :tag, "div",
38
+ ])).to eq [:html, :tag, "div",
39
39
  [:multi,
40
40
  [:html, :attr, "name", [:dynamic, "b"]]],
41
41
  [:content]]
@@ -1,4 +1,4 @@
1
- require 'helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Temple::HTML::AttributeSorter do
4
4
  before do
@@ -7,13 +7,13 @@ describe Temple::HTML::AttributeSorter do
7
7
  end
8
8
 
9
9
  it 'should sort html attributes by name by default, when :sort_attrs is true' do
10
- @ordered.call([:html, :tag,
10
+ expect(@ordered.call([:html, :tag,
11
11
  'meta',
12
12
  [:html, :attrs, [:html, :attr, 'c', [:static, '1']],
13
13
  [:html, :attr, 'd', [:static, '2']],
14
14
  [:html, :attr, 'a', [:static, '3']],
15
15
  [:html, :attr, 'b', [:static, '4']]]
16
- ]).should.equal [:html, :tag, 'meta',
16
+ ])).to eq [:html, :tag, 'meta',
17
17
  [:html, :attrs,
18
18
  [:html, :attr, 'a', [:static, '3']],
19
19
  [:html, :attr, 'b', [:static, '4']],
@@ -22,13 +22,13 @@ describe Temple::HTML::AttributeSorter do
22
22
  end
23
23
 
24
24
  it 'should preserve the order of html attributes when :sort_attrs is false' do
25
- @unordered.call([:html, :tag,
25
+ expect(@unordered.call([:html, :tag,
26
26
  'meta',
27
27
  [:html, :attrs, [:html, :attr, 'c', [:static, '1']],
28
28
  [:html, :attr, 'd', [:static, '2']],
29
29
  [:html, :attr, 'a', [:static, '3']],
30
30
  [:html, :attr, 'b', [:static, '4']]]
31
- ]).should.equal [:html, :tag, 'meta',
31
+ ])).to eq [:html, :tag, 'meta',
32
32
  [:html, :attrs,
33
33
  [:html, :attr, 'c', [:static, '1']],
34
34
  [:html, :attr, 'd', [:static, '2']],
@@ -36,11 +36,11 @@ describe Temple::HTML::AttributeSorter do
36
36
  [:html, :attr, 'b', [:static, '4']]]]
37
37
 
38
38
  # Use case:
39
- @unordered.call([:html, :tag,
39
+ expect(@unordered.call([:html, :tag,
40
40
  'meta',
41
41
  [:html, :attrs, [:html, :attr, 'http-equiv', [:static, 'Content-Type']],
42
42
  [:html, :attr, 'content', [:static, '']]]
43
- ]).should.equal [:html, :tag, 'meta',
43
+ ])).to eq [:html, :tag, 'meta',
44
44
  [:html, :attrs,
45
45
  [:html, :attr, 'http-equiv', [:static, 'Content-Type']],
46
46
  [:html, :attr, 'content', [:static, '']]]]
@@ -1,4 +1,4 @@
1
- require 'helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Temple::HTML::Fast do
4
4
  before do
@@ -6,37 +6,37 @@ describe Temple::HTML::Fast do
6
6
  end
7
7
 
8
8
  it 'should compile html doctype' do
9
- @html.call([:multi, [:html, :doctype, '5']]).should.equal [:multi, [:static, '<!DOCTYPE html>']]
10
- @html.call([:multi, [:html, :doctype, 'html']]).should.equal [:multi, [:static, '<!DOCTYPE html>']]
11
- @html.call([:multi, [:html, :doctype, '1.1']]).should.equal [:multi,
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
12
  [:static, '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">']]
13
13
  end
14
14
 
15
15
  it 'should compile xml encoding' do
16
- @html.call([:html, :doctype, 'xml latin1']).should.equal [:static, "<?xml version=\"1.0\" encoding=\"latin1\" ?>"]
16
+ expect(@html.call([:html, :doctype, 'xml latin1'])).to eq([:static, "<?xml version=\"1.0\" encoding=\"latin1\" ?>"])
17
17
  end
18
18
 
19
19
  it 'should compile html comment' do
20
- @html.call([:html, :comment, [:static, 'test']]).should.equal [:multi, [:static, "<!--"], [:static, "test"], [:static, "-->"]]
20
+ expect(@html.call([:html, :comment, [:static, 'test']])).to eq([:multi, [:static, "<!--"], [:static, "test"], [:static, "-->"]])
21
21
  end
22
22
 
23
23
  it 'should compile js wrapped in comments' do
24
- Temple::HTML::Fast.new(js_wrapper: nil).call([:html, :js, [:static, 'test']]).should.equal [:static, "test"]
25
- Temple::HTML::Fast.new(js_wrapper: :comment).call([:html, :js, [:static, 'test']]).should.equal [:multi, [:static, "<!--\n"], [:static, "test"], [:static, "\n//-->"]]
26
- Temple::HTML::Fast.new(js_wrapper: :cdata).call([:html, :js, [:static, 'test']]).should.equal [:multi, [:static, "\n//<![CDATA[\n"], [:static, "test"], [:static, "\n//]]>\n"]]
27
- Temple::HTML::Fast.new(js_wrapper: :both).call([:html, :js, [:static, 'test']]).should.equal [:multi, [:static, "<!--\n//<![CDATA[\n"], [:static, "test"], [:static, "\n//]]>\n//-->"]]
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
28
  end
29
29
 
30
30
  it 'should guess default js comment' do
31
- Temple::HTML::Fast.new(js_wrapper: :guess, format: :xhtml).call([:html, :js, [:static, 'test']]).should.equal [:multi, [:static, "\n//<![CDATA[\n"], [:static, "test"], [:static, "\n//]]>\n"]]
32
- Temple::HTML::Fast.new(js_wrapper: :guess, format: :html).call([:html, :js, [:static, 'test']]).should.equal [:multi, [:static, "<!--\n"], [:static, "test"], [:static, "\n//-->"]]
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
33
  end
34
34
 
35
35
  it 'should compile autoclosed html tag' do
36
- @html.call([:html, :tag,
36
+ expect(@html.call([:html, :tag,
37
37
  'img', [:attrs],
38
38
  [:multi, [:newline]]
39
- ]).should.equal [:multi,
39
+ ])).to eq [:multi,
40
40
  [:static, "<img"],
41
41
  [:attrs],
42
42
  [:static, " />"],
@@ -44,18 +44,18 @@ describe Temple::HTML::Fast do
44
44
  end
45
45
 
46
46
  it 'should compile explicitly closed html tag' do
47
- @html.call([:html, :tag,
47
+ expect(@html.call([:html, :tag,
48
48
  'closed', [:attrs]
49
- ]).should.equal [:multi,
49
+ ])).to eq [:multi,
50
50
  [:static, "<closed"],
51
51
  [:attrs],
52
52
  [:static, " />"]]
53
53
  end
54
54
 
55
55
  it 'should compile html with content' do
56
- @html.call([:html, :tag,
56
+ expect(@html.call([:html, :tag,
57
57
  'div', [:attrs], [:content]
58
- ]).should.equal [:multi,
58
+ ])).to eq [:multi,
59
59
  [:static, "<div"],
60
60
  [:attrs],
61
61
  [:static, ">"],
@@ -64,13 +64,13 @@ describe Temple::HTML::Fast do
64
64
  end
65
65
 
66
66
  it 'should compile html with attrs' do
67
- @html.call([:html, :tag,
67
+ expect(@html.call([:html, :tag,
68
68
  'div',
69
69
  [:html, :attrs,
70
70
  [:html, :attr, 'id', [:static, 'test']],
71
71
  [:html, :attr, 'class', [:dynamic, 'block']]],
72
72
  [:content]
73
- ]).should.equal [:multi,
73
+ ])).to eq [:multi,
74
74
  [:static, "<div"],
75
75
  [:multi,
76
76
  [:multi, [:static, " id=\""], [:static, "test"], [:static, '"']],
@@ -82,16 +82,16 @@ describe Temple::HTML::Fast do
82
82
 
83
83
  it 'should keep codes intact' do
84
84
  exp = [:multi, [:code, 'foo']]
85
- @html.call(exp).should.equal exp
85
+ expect(@html.call(exp)).to eq(exp)
86
86
  end
87
87
 
88
88
  it 'should keep statics intact' do
89
89
  exp = [:multi, [:static, '<']]
90
- @html.call(exp).should.equal exp
90
+ expect(@html.call(exp)).to eq(exp)
91
91
  end
92
92
 
93
93
  it 'should keep dynamic intact' do
94
94
  exp = [:multi, [:dynamic, 'foo']]
95
- @html.call(exp).should.equal exp
95
+ expect(@html.call(exp)).to eq(exp)
96
96
  end
97
97
  end