temple 0.8.2 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/test.yml +34 -0
  3. data/.gitignore +1 -0
  4. data/CHANGES +18 -1
  5. data/README.md +1 -1
  6. data/Rakefile +4 -11
  7. data/lib/temple/erb/parser.rb +1 -1
  8. data/lib/temple/filters/ambles.rb +21 -0
  9. data/lib/temple/filters/string_splitter.rb +11 -0
  10. data/lib/temple/generator.rb +11 -5
  11. data/lib/temple/generators/rails_output_buffer.rb +2 -6
  12. data/lib/temple/mixins/grammar_dsl.rb +2 -1
  13. data/lib/temple/templates/rails.rb +4 -0
  14. data/lib/temple/templates/tilt.rb +1 -9
  15. data/lib/temple/utils.rb +2 -14
  16. data/lib/temple/version.rb +1 -1
  17. data/lib/temple.rb +1 -0
  18. data/spec/engine_spec.rb +189 -0
  19. data/{test/test_erb.rb → spec/erb_spec.rb} +12 -12
  20. data/spec/filter_spec.rb +29 -0
  21. data/{test/filters/test_code_merger.rb → spec/filters/code_merger_spec.rb} +7 -7
  22. data/{test/filters/test_control_flow.rb → spec/filters/control_flow_spec.rb} +13 -13
  23. data/{test/filters/test_dynamic_inliner.rb → spec/filters/dynamic_inliner_spec.rb} +18 -18
  24. data/{test/filters/test_eraser.rb → spec/filters/eraser_spec.rb} +9 -9
  25. data/{test/filters/test_escapable.rb → spec/filters/escapable_spec.rb} +10 -10
  26. data/{test/filters/test_multi_flattener.rb → spec/filters/multi_flattener_spec.rb} +4 -4
  27. data/{test/filters/test_static_analyzer.rb → spec/filters/static_analyzer_spec.rb} +6 -8
  28. data/{test/filters/test_static_merger.rb → spec/filters/static_merger_spec.rb} +7 -7
  29. data/spec/filters/string_splitter_spec.rb +50 -0
  30. data/spec/generator_spec.rb +167 -0
  31. data/spec/grammar_spec.rb +47 -0
  32. data/{test/html/test_attribute_merger.rb → spec/html/attribute_merger_spec.rb} +11 -11
  33. data/{test/html/test_attribute_remover.rb → spec/html/attribute_remover_spec.rb} +7 -7
  34. data/{test/html/test_attribute_sorter.rb → spec/html/attribute_sorter_spec.rb} +7 -7
  35. data/{test/html/test_fast.rb → spec/html/fast_spec.rb} +23 -23
  36. data/{test/html/test_pretty.rb → spec/html/pretty_spec.rb} +7 -7
  37. data/spec/map_spec.rb +39 -0
  38. data/{test/mixins/test_dispatcher.rb → spec/mixins/dispatcher_spec.rb} +12 -12
  39. data/{test/mixins/test_grammar_dsl.rb → spec/mixins/grammar_dsl_spec.rb} +19 -19
  40. data/{test/helper.rb → spec/spec_helper.rb} +5 -6
  41. data/{test/test_static_analyzer.rb → spec/static_analyzer_spec.rb} +6 -6
  42. data/spec/utils_spec.rb +39 -0
  43. data/temple.gemspec +3 -3
  44. metadata +34 -59
  45. data/.travis.yml +0 -30
  46. data/test/filters/test_string_splitter.rb +0 -25
  47. data/test/test_engine.rb +0 -189
  48. data/test/test_filter.rb +0 -29
  49. data/test/test_generator.rb +0 -158
  50. data/test/test_grammar.rb +0 -47
  51. data/test/test_map.rb +0 -39
  52. data/test/test_utils.rb +0 -39
@@ -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
@@ -1,4 +1,4 @@
1
- require 'helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Temple::HTML::Pretty do
4
4
  before do
@@ -6,9 +6,9 @@ describe Temple::HTML::Pretty do
6
6
  end
7
7
 
8
8
  it 'should indent nested tags' do
9
- @html.call([:html, :tag, 'div', [:multi],
9
+ expect(@html.call([:html, :tag, 'div', [:multi],
10
10
  [:html, :tag, 'p', [:multi], [:multi, [:static, 'text'], [:dynamic, 'code']]]
11
- ]).should.equal [:multi,
11
+ ])).to eq [:multi,
12
12
  [:code, "_temple_html_pretty1 = /<code|<pre|<textarea/"],
13
13
  [:multi,
14
14
  [:static, "<div"],
@@ -26,9 +26,9 @@ describe Temple::HTML::Pretty do
26
26
  end
27
27
 
28
28
  it 'should not indent preformatted tags' do
29
- @html.call([:html, :tag, 'pre', [:multi],
29
+ expect(@html.call([:html, :tag, 'pre', [:multi],
30
30
  [:html, :tag, 'p', [:multi], [:static, 'text']]
31
- ]).should.equal [:multi,
31
+ ])).to eq [:multi,
32
32
  [:code, "_temple_html_pretty1 = /<code|<pre|<textarea/"],
33
33
  [:multi,
34
34
  [:static, "<pre"],
@@ -45,9 +45,9 @@ describe Temple::HTML::Pretty do
45
45
 
46
46
  it 'should not escape html_safe strings' do
47
47
  with_html_safe do
48
- @html.call(
48
+ expect(@html.call(
49
49
  [:dynamic, '"text<".html_safe']
50
- ).should.equal [:multi,
50
+ )).to eq [:multi,
51
51
  [:code, "_temple_html_pretty1 = /<code|<pre|<textarea/"],
52
52
  [:dynamic, "::Temple::Utils.indent_dynamic((\"text<\".html_safe), nil, \"\\n\", _temple_html_pretty1)"]]
53
53
  end
data/spec/map_spec.rb ADDED
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe Temple::ImmutableMap do
4
+ it 'has read accessor' do
5
+ hash = Temple::ImmutableMap.new({a: 1},{b: 2, a: 3})
6
+ expect(hash[:a]).to eq(1)
7
+ expect(hash[:b]).to eq(2)
8
+ end
9
+
10
+ it 'has include?' do
11
+ hash = Temple::ImmutableMap.new({a: 1},{b: 2, a: 3})
12
+ expect(hash).to include(:a)
13
+ expect(hash).to include(:b)
14
+ expect(hash).not_to include(:c)
15
+ end
16
+
17
+ it 'has values' do
18
+ expect(Temple::ImmutableMap.new({a: 1},{b: 2, a: 3}).values.sort).to eq([1,2])
19
+ end
20
+
21
+ it 'has keys' do
22
+ expect(Temple::ImmutableMap.new({a: 1},{b: 2, a: 3}).keys).to eq([:a,:b])
23
+ end
24
+
25
+ it 'has to_a' do
26
+ expect(Temple::ImmutableMap.new({a: 1},{b: 2, a: 3}).to_a).to eq([[:a, 1], [:b, 2]])
27
+ end
28
+ end
29
+
30
+ describe Temple::MutableMap do
31
+ it 'has write accessor' do
32
+ parent = {a: 1}
33
+ hash = Temple::MutableMap.new(parent)
34
+ expect(hash[:a]).to eq(1)
35
+ hash[:a] = 2
36
+ expect(hash[:a]).to eq(2)
37
+ expect(parent[:a]).to eq(1)
38
+ end
39
+ end
@@ -1,4 +1,4 @@
1
- require 'helper'
1
+ require 'spec_helper'
2
2
 
3
3
  class FilterWithDispatcherMixin
4
4
  include Temple::Mixins::Dispatcher
@@ -40,31 +40,31 @@ describe Temple::Mixins::Dispatcher do
40
40
  end
41
41
 
42
42
  it 'should return unhandled expressions' do
43
- @filter.call([:unhandled]).should.equal [:unhandled]
43
+ expect(@filter.call([:unhandled])).to eq([:unhandled])
44
44
  end
45
45
 
46
46
  it 'should dispatch first level' do
47
- @filter.call([:test, 42]).should.equal [:on_test, 42]
47
+ expect(@filter.call([:test, 42])).to eq([:on_test, 42])
48
48
  end
49
49
 
50
50
  it 'should dispatch second level' do
51
- @filter.call([:second, :test, 42]).should.equal [:on_second_test, 42]
51
+ expect(@filter.call([:second, :test, 42])).to eq([:on_second_test, 42])
52
52
  end
53
53
 
54
54
  it 'should dispatch second level if prefixed' do
55
- @filter.call([:test, :check, 42]).should.equal [:on_check, 42]
55
+ expect(@filter.call([:test, :check, 42])).to eq([:on_check, 42])
56
56
  end
57
57
 
58
58
  it 'should dispatch parent level' do
59
- @filter.call([:a, 42]).should == [:a, 42]
60
- @filter.call([:a, :b, 42]).should == [:on_ab, 42]
61
- @filter.call([:a, :b, :test, 42]).should == [:on_ab_test, 42]
62
- @filter.call([:a, :b, :c, 42]).should == [:on_ab, :c, 42]
63
- @filter.call([:a, :b, :c, :d, 42]).should == [:on_ab, :c, :d, 42]
64
- @filter.call([:a, :b, :c, :d, :test, 42]).should == [:on_abcd_test, 42]
59
+ expect(@filter.call([:a, 42])).to eq [:a, 42]
60
+ expect(@filter.call([:a, :b, 42])).to eq [:on_ab, 42]
61
+ expect(@filter.call([:a, :b, :test, 42])).to eq [:on_ab_test, 42]
62
+ expect(@filter.call([:a, :b, :c, 42])).to eq [:on_ab, :c, 42]
63
+ expect(@filter.call([:a, :b, :c, :d, 42])).to eq [:on_ab, :c, :d, 42]
64
+ expect(@filter.call([:a, :b, :c, :d, :test, 42])).to eq [:on_abcd_test, 42]
65
65
  end
66
66
 
67
67
  it 'should dispatch zero level' do
68
- FilterWithDispatcherMixinAndOn.new.call([:foo,42]).should == [:on_zero, :foo, 42]
68
+ expect(FilterWithDispatcherMixinAndOn.new.call([:foo,42])).to eq [:on_zero, :foo, 42]
69
69
  end
70
70
  end
@@ -1,4 +1,4 @@
1
- require 'helper'
1
+ require 'spec_helper'
2
2
 
3
3
  module BasicGrammar
4
4
  extend Temple::Mixins::GrammarDSL
@@ -28,42 +28,42 @@ end
28
28
 
29
29
  describe Temple::Mixins::GrammarDSL do
30
30
  it 'should support class types' do
31
- BasicGrammar.should.match :symbol
32
- BasicGrammar.should.not.match [:symbol]
33
- BasicGrammar.should.not.match 'string'
34
- BasicGrammar.should.not.match ['string']
31
+ expect(BasicGrammar).to be_match(:symbol)
32
+ expect(BasicGrammar).not_to be_match([:symbol])
33
+ expect(BasicGrammar).not_to be_match('string')
34
+ expect(BasicGrammar).not_to be_match(['string'])
35
35
  end
36
36
 
37
37
  it 'should support value types' do
38
- BasicGrammar.should.match 42
39
- BasicGrammar.should.not.match 43
38
+ expect(BasicGrammar).to be_match(42)
39
+ expect(BasicGrammar).not_to be_match(43)
40
40
  end
41
41
 
42
42
  it 'should support nesting' do
43
- BasicGrammar.should.match [:zero_or_more, [:zero_or_more]]
43
+ expect(BasicGrammar).to be_match([:zero_or_more, [:zero_or_more]])
44
44
  end
45
45
 
46
46
  it 'should support *' do
47
- BasicGrammar.should.match [:zero_or_more]
48
- BasicGrammar.should.match [:zero_or_more, nil, 42]
47
+ expect(BasicGrammar).to be_match([:zero_or_more])
48
+ expect(BasicGrammar).to be_match([:zero_or_more, nil, 42])
49
49
  end
50
50
 
51
51
  it 'should support +' do
52
- BasicGrammar.should.not.match [:one_or_more]
53
- BasicGrammar.should.match [:one_or_more, 42]
54
- BasicGrammar.should.match [:one_or_more, 42, nil]
52
+ expect(BasicGrammar).not_to be_match([:one_or_more])
53
+ expect(BasicGrammar).to be_match( [:one_or_more, 42])
54
+ expect(BasicGrammar).to be_match( [:one_or_more, 42, nil])
55
55
  end
56
56
 
57
57
  it 'should support ?' do
58
- BasicGrammar.should.not.match [:zero_or_one, nil, 42]
59
- BasicGrammar.should.match [:zero_or_one]
60
- BasicGrammar.should.match [:zero_or_one, 42]
58
+ expect(BasicGrammar).not_to be_match([:zero_or_one, nil, 42])
59
+ expect(BasicGrammar).to be_match( [:zero_or_one])
60
+ expect(BasicGrammar).to be_match( [:zero_or_one, 42])
61
61
  end
62
62
 
63
63
  it 'should support extended grammars' do
64
- ExtendedGrammar.should.match [:extended, [:extended, 42]]
65
- BasicGrammar.should.not.match [:zero_or_more, [:extended, nil]]
66
- BasicGrammar.should.not.match [:extended, [:extended, 42]]
64
+ expect(ExtendedGrammar).to be_match([:extended, [:extended, 42]])
65
+ expect(BasicGrammar).not_to be_match([:zero_or_more, [:extended, nil]])
66
+ expect(BasicGrammar).not_to be_match([:extended, [:extended, 42]])
67
67
  end
68
68
 
69
69
  it 'should have validate!' do
@@ -1,4 +1,3 @@
1
- require 'bacon'
2
1
  require 'temple'
3
2
 
4
3
  module TestHelper
@@ -13,18 +12,18 @@ module TestHelper
13
12
  end
14
13
 
15
14
  def grammar_validate(grammar, exp, message)
16
- lambda { grammar.validate!(exp) }.should.raise(Temple::InvalidExpression).message.should.equal message
15
+ expect { grammar.validate!(exp) }.to raise_error(Temple::InvalidExpression, message)
17
16
  end
18
17
 
19
18
  def erb(src, options = {})
20
19
  Temple::ERB::Template.new(options) { src }.render
21
20
  end
22
21
 
23
- def erubis(src, options = {})
24
- Tilt::ErubisTemplate.new(options) { src }.render
22
+ def erubi(src, options = {})
23
+ Tilt::ErubiTemplate.new(options) { src }.render
25
24
  end
26
25
  end
27
26
 
28
- class Bacon::Context
29
- include TestHelper
27
+ RSpec.configure do |config|
28
+ config.include TestHelper
30
29
  end
@@ -1,9 +1,9 @@
1
- require 'helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Temple::StaticAnalyzer do
4
4
  describe '.available?' do
5
5
  it 'should return true if its dependency is available' do
6
- Temple::StaticAnalyzer.available?.should.equal(defined?(Ripper) && Ripper.respond_to?(:lex))
6
+ expect(Temple::StaticAnalyzer.available?).to eq(defined?(Ripper) && Ripper.respond_to?(:lex))
7
7
  end
8
8
  end
9
9
 
@@ -11,13 +11,13 @@ describe Temple::StaticAnalyzer do
11
11
  describe '.static?' do
12
12
  it 'should return true if given Ruby expression is static' do
13
13
  ['true', 'false', '"hello world"', "[1, { 2 => 3 }]", "[\n1,\n]"].each do |exp|
14
- Temple::StaticAnalyzer.static?(exp).should.equal(true)
14
+ expect(Temple::StaticAnalyzer.static?(exp)).to eq(true)
15
15
  end
16
16
  end
17
17
 
18
18
  it 'should return false if given Ruby expression is dynamic' do
19
19
  ['1 + 2', 'variable', 'method_call(a)', 'CONSTANT'].each do |exp|
20
- Temple::StaticAnalyzer.static?(exp).should.equal(false)
20
+ expect(Temple::StaticAnalyzer.static?(exp)).to eq(false)
21
21
  end
22
22
  end
23
23
  end
@@ -25,13 +25,13 @@ describe Temple::StaticAnalyzer do
25
25
  describe '.syntax_error?' do
26
26
  it 'should return false if given Ruby expression is valid' do
27
27
  ['Foo.bar.baz { |c| c.d! }', '{ foo: bar }'].each do |exp|
28
- Temple::StaticAnalyzer.syntax_error?(exp).should.equal(false)
28
+ expect(Temple::StaticAnalyzer.syntax_error?(exp)).to eq(false)
29
29
  end
30
30
  end
31
31
 
32
32
  it 'should return true if given Ruby expression is invalid' do
33
33
  ['Foo.bar.baz { |c| c.d! ', ' foo: bar '].each do |exp|
34
- Temple::StaticAnalyzer.syntax_error?(exp).should.equal(true)
34
+ expect(Temple::StaticAnalyzer.syntax_error?(exp)).to eq(true)
35
35
  end
36
36
  end
37
37
  end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ class UniqueTest
4
+ include Temple::Utils
5
+ end
6
+
7
+ describe Temple::Utils do
8
+ it 'has empty_exp?' do
9
+ expect(Temple::Utils.empty_exp?([:multi])).to eq(true)
10
+ expect(Temple::Utils.empty_exp?([:multi, [:multi]])).to eq(true)
11
+ expect(Temple::Utils.empty_exp?([:multi, [:multi, [:newline]], [:newline]])).to eq(true)
12
+ expect(Temple::Utils.empty_exp?([:multi])).to eq(true)
13
+ expect(Temple::Utils.empty_exp?([:multi, [:multi, [:static, 'text']]])).to eq(false)
14
+ expect(Temple::Utils.empty_exp?([:multi, [:newline], [:multi, [:dynamic, 'text']]])).to eq(false)
15
+ end
16
+
17
+ it 'has unique_name' do
18
+ u = UniqueTest.new
19
+ expect(u.unique_name).to eq('_uniquetest1')
20
+ expect(u.unique_name).to eq('_uniquetest2')
21
+ expect(UniqueTest.new.unique_name).to eq('_uniquetest1')
22
+ end
23
+
24
+ it 'has escape_html' do
25
+ expect(Temple::Utils.escape_html('<')).to eq('&lt;')
26
+ end
27
+
28
+ it 'should escape unsafe html strings' do
29
+ with_html_safe do
30
+ expect(Temple::Utils.escape_html_safe('<')).to eq('&lt;')
31
+ end
32
+ end
33
+
34
+ it 'should not escape safe html strings' do
35
+ with_html_safe do
36
+ expect(Temple::Utils.escape_html_safe('<'.html_safe)).to eq('<')
37
+ end
38
+ end
39
+ end