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
@@ -1,4 +1,4 @@
1
- require 'helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Temple::Filters::MultiFlattener do
4
4
  before do
@@ -6,7 +6,7 @@ describe Temple::Filters::MultiFlattener do
6
6
  end
7
7
 
8
8
  it 'should flatten nested multi expressions' do
9
- @filter.call([:multi,
9
+ expect(@filter.call([:multi,
10
10
  [:static, "a"],
11
11
  [:multi,
12
12
  [:dynamic, "aa"],
@@ -17,7 +17,7 @@ describe Temple::Filters::MultiFlattener do
17
17
  [:dynamic, "ab"],
18
18
  ],
19
19
  [:static, "b"],
20
- ]).should.equal [:multi,
20
+ ])).to eq [:multi,
21
21
  [:static, "a"],
22
22
  [:dynamic, "aa"],
23
23
  [:static, "aaa"],
@@ -28,6 +28,6 @@ describe Temple::Filters::MultiFlattener do
28
28
  end
29
29
 
30
30
  it 'should return first element' do
31
- @filter.call([:multi, [:code, 'foo']]).should.equal [:code, 'foo']
31
+ expect(@filter.call([:multi, [:code, 'foo']])).to eq([:code, 'foo'])
32
32
  end
33
33
  end
@@ -0,0 +1,35 @@
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,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,158 @@
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 newlines' do
66
+ gen = SimpleGenerator.new(buffer: "VAR")
67
+ expect(gen.call([:multi,
68
+ [:static, "static"],
69
+ [:newline],
70
+ [:dynamic, "dynamic"],
71
+ [:newline],
72
+ [:code, "code"]
73
+ ])).to eq("VAR = BUFFER; VAR << (S:static); \n; " +
74
+ "VAR << (D:dynamic); \n; C:code; VAR")
75
+ end
76
+ end
77
+
78
+ describe Temple::Generators::Array do
79
+ it 'should compile simple expressions' do
80
+ gen = Temple::Generators::Array.new(freeze_static: false)
81
+ expect(gen.call([:static, 'test'])).to eq('_buf = []; _buf << ("test"); _buf')
82
+ expect(gen.call([:dynamic, 'test'])).to eq('_buf = []; _buf << (test); _buf')
83
+ expect(gen.call([:code, 'test'])).to eq('_buf = []; test; _buf')
84
+
85
+ expect(gen.call([:multi, [:static, 'a'], [:static, 'b']])).to eq('_buf = []; _buf << ("a"); _buf << ("b"); _buf')
86
+ expect(gen.call([:multi, [:static, 'a'], [:dynamic, 'b']])).to eq('_buf = []; _buf << ("a"); _buf << (b); _buf')
87
+ end
88
+
89
+ it 'should freeze static' do
90
+ gen = Temple::Generators::Array.new(freeze_static: true)
91
+ expect(gen.call([:static, 'test'])).to eq('_buf = []; _buf << ("test".freeze); _buf')
92
+ end
93
+ end
94
+
95
+ describe Temple::Generators::ArrayBuffer do
96
+ it 'should compile simple expressions' do
97
+ gen = Temple::Generators::ArrayBuffer.new(freeze_static: false)
98
+ expect(gen.call([:static, 'test'])).to eq('_buf = "test"')
99
+ expect(gen.call([:dynamic, 'test'])).to eq('_buf = (test).to_s')
100
+ expect(gen.call([:code, 'test'])).to eq('_buf = []; test; _buf = _buf.join("")')
101
+
102
+ expect(gen.call([:multi, [:static, 'a'], [:static, 'b']])).to eq('_buf = []; _buf << ("a"); _buf << ("b"); _buf = _buf.join("")')
103
+ expect(gen.call([:multi, [:static, 'a'], [:dynamic, 'b']])).to eq('_buf = []; _buf << ("a"); _buf << (b); _buf = _buf.join("")')
104
+ end
105
+
106
+ it 'should freeze static' do
107
+ gen = Temple::Generators::ArrayBuffer.new(freeze_static: true)
108
+ expect(gen.call([:static, 'test'])).to eq('_buf = "test"')
109
+ expect(gen.call([:multi, [:dynamic, '1'], [:static, 'test']])).to eq('_buf = []; _buf << (1); _buf << ("test".freeze); _buf = _buf.join("".freeze)')
110
+ end
111
+ end
112
+
113
+ describe Temple::Generators::StringBuffer do
114
+ it 'should compile simple expressions' do
115
+ gen = Temple::Generators::StringBuffer.new(freeze_static: false)
116
+ expect(gen.call([:static, 'test'])).to eq('_buf = "test"')
117
+ expect(gen.call([:dynamic, 'test'])).to eq('_buf = (test).to_s')
118
+ expect(gen.call([:code, 'test'])).to eq('_buf = \'\'; test; _buf')
119
+
120
+ expect(gen.call([:multi, [:static, 'a'], [:static, 'b']])).to eq('_buf = \'\'; _buf << ("a"); _buf << ("b"); _buf')
121
+ expect(gen.call([:multi, [:static, 'a'], [:dynamic, 'b']])).to eq('_buf = \'\'; _buf << ("a"); _buf << ((b).to_s); _buf')
122
+ end
123
+
124
+ it 'should freeze static' do
125
+ gen = Temple::Generators::StringBuffer.new(freeze_static: true)
126
+ expect(gen.call([:static, 'test'])).to eq('_buf = "test"')
127
+ expect(gen.call([:multi, [:dynamic, '1'], [:static, 'test']])).to eq('_buf = \'\'; _buf << ((1).to_s); _buf << ("test".freeze); _buf')
128
+ end
129
+ end
130
+
131
+ describe Temple::Generators::ERB do
132
+ it 'should compile simple expressions' do
133
+ gen = Temple::Generators::ERB.new
134
+ expect(gen.call([:static, 'test'])).to eq('test')
135
+ expect(gen.call([:dynamic, 'test'])).to eq('<%= test %>')
136
+ expect(gen.call([:code, 'test'])).to eq('<% test %>')
137
+
138
+ expect(gen.call([:multi, [:static, 'a'], [:static, 'b']])).to eq('ab')
139
+ expect(gen.call([:multi, [:static, 'a'], [:dynamic, 'b']])).to eq('a<%= b %>')
140
+ end
141
+ end
142
+
143
+ describe Temple::Generators::RailsOutputBuffer do
144
+ it 'should compile simple expressions' do
145
+ gen = Temple::Generators::RailsOutputBuffer.new(freeze_static: false)
146
+ expect(gen.call([:static, 'test'])).to eq('@output_buffer = output_buffer || ActionView::OutputBuffer.new; ' +
147
+ '@output_buffer.safe_concat(("test")); @output_buffer')
148
+ expect(gen.call([:dynamic, 'test'])).to eq('@output_buffer = output_buffer || ActionView::OutputBuffer.new; ' +
149
+ '@output_buffer.safe_concat(((test).to_s)); @output_buffer')
150
+ expect(gen.call([:code, 'test'])).to eq('@output_buffer = output_buffer || ActionView::OutputBuffer.new; ' +
151
+ 'test; @output_buffer')
152
+ end
153
+
154
+ it 'should freeze static' do
155
+ gen = Temple::Generators::RailsOutputBuffer.new(freeze_static: true)
156
+ expect(gen.call([:static, 'test'])).to eq('@output_buffer = output_buffer || ActionView::OutputBuffer.new; @output_buffer.safe_concat(("test".freeze)); @output_buffer')
157
+ end
158
+ 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,19 +1,19 @@
1
- require 'helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Temple::HTML::AttributeSorter do
4
4
  before do
5
5
  @ordered = Temple::HTML::AttributeSorter.new
6
- @unordered = Temple::HTML::AttributeSorter.new :sort_attrs => false
6
+ @unordered = Temple::HTML::AttributeSorter.new sort_attrs: false
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, '']]]]