temple 0.10.2 → 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/CHANGES +5 -0
- data/Rakefile +0 -13
- data/lib/temple/filters/dynamic_merger.rb +69 -0
- data/lib/temple/version.rb +1 -1
- data/lib/temple.rb +1 -0
- data/temple.gemspec +1 -2
- 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 -179
- 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,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
|
data/spec/map_spec.rb
DELETED
@@ -1,39 +0,0 @@
|
|
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,70 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
class FilterWithDispatcherMixin
|
4
|
-
include Temple::Mixins::Dispatcher
|
5
|
-
|
6
|
-
def on_test(arg)
|
7
|
-
[:on_test, arg]
|
8
|
-
end
|
9
|
-
|
10
|
-
def on_test_check(arg)
|
11
|
-
[:on_check, arg]
|
12
|
-
end
|
13
|
-
|
14
|
-
def on_second_test(arg)
|
15
|
-
[:on_second_test, arg]
|
16
|
-
end
|
17
|
-
|
18
|
-
def on_a_b(*arg)
|
19
|
-
[:on_ab, *arg]
|
20
|
-
end
|
21
|
-
|
22
|
-
def on_a_b_test(arg)
|
23
|
-
[:on_ab_test, arg]
|
24
|
-
end
|
25
|
-
|
26
|
-
def on_a_b_c_d_test(arg)
|
27
|
-
[:on_abcd_test, arg]
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
class FilterWithDispatcherMixinAndOn < FilterWithDispatcherMixin
|
32
|
-
def on(*args)
|
33
|
-
[:on_zero, *args]
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
describe Temple::Mixins::Dispatcher do
|
38
|
-
before do
|
39
|
-
@filter = FilterWithDispatcherMixin.new
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'should return unhandled expressions' do
|
43
|
-
expect(@filter.call([:unhandled])).to eq([:unhandled])
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'should dispatch first level' do
|
47
|
-
expect(@filter.call([:test, 42])).to eq([:on_test, 42])
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'should dispatch second level' do
|
51
|
-
expect(@filter.call([:second, :test, 42])).to eq([:on_second_test, 42])
|
52
|
-
end
|
53
|
-
|
54
|
-
it 'should dispatch second level if prefixed' do
|
55
|
-
expect(@filter.call([:test, :check, 42])).to eq([:on_check, 42])
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'should dispatch parent level' do
|
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
|
-
end
|
66
|
-
|
67
|
-
it 'should dispatch zero level' do
|
68
|
-
expect(FilterWithDispatcherMixinAndOn.new.call([:foo,42])).to eq [:on_zero, :foo, 42]
|
69
|
-
end
|
70
|
-
end
|
@@ -1,86 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module BasicGrammar
|
4
|
-
extend Temple::Mixins::GrammarDSL
|
5
|
-
|
6
|
-
Expression <<
|
7
|
-
Symbol |
|
8
|
-
Answer |
|
9
|
-
[:zero_or_more, 'Expression*'] |
|
10
|
-
[:one_or_more, 'Expression+'] |
|
11
|
-
[:zero_or_one, 'Expression?'] |
|
12
|
-
[:bool, Bool] |
|
13
|
-
nil
|
14
|
-
|
15
|
-
Bool <<
|
16
|
-
true | false
|
17
|
-
|
18
|
-
Answer <<
|
19
|
-
Value(42)
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
module ExtendedGrammar
|
24
|
-
extend BasicGrammar
|
25
|
-
|
26
|
-
Expression << [:extended, Expression]
|
27
|
-
end
|
28
|
-
|
29
|
-
describe Temple::Mixins::GrammarDSL do
|
30
|
-
it 'should support class types' do
|
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
|
-
end
|
36
|
-
|
37
|
-
it 'should support value types' do
|
38
|
-
expect(BasicGrammar).to be_match(42)
|
39
|
-
expect(BasicGrammar).not_to be_match(43)
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'should support nesting' do
|
43
|
-
expect(BasicGrammar).to be_match([:zero_or_more, [:zero_or_more]])
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'should support *' do
|
47
|
-
expect(BasicGrammar).to be_match([:zero_or_more])
|
48
|
-
expect(BasicGrammar).to be_match([:zero_or_more, nil, 42])
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'should support +' do
|
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
|
-
end
|
56
|
-
|
57
|
-
it 'should support ?' do
|
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
|
-
end
|
62
|
-
|
63
|
-
it 'should support extended grammars' do
|
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
|
-
end
|
68
|
-
|
69
|
-
it 'should have validate!' do
|
70
|
-
grammar_validate BasicGrammar,
|
71
|
-
[:zero_or_more, [:zero_or_more, [:unknown]]],
|
72
|
-
"BasicGrammar::Expression did not match\n[:unknown]\n"
|
73
|
-
|
74
|
-
grammar_validate BasicGrammar,
|
75
|
-
[:zero_or_more, [:one_or_more]],
|
76
|
-
"BasicGrammar::Expression did not match\n[:one_or_more]\n"
|
77
|
-
|
78
|
-
grammar_validate BasicGrammar,
|
79
|
-
[:zero_or_more, 123, [:unknown]],
|
80
|
-
"BasicGrammar::Expression did not match\n123\n"
|
81
|
-
|
82
|
-
grammar_validate BasicGrammar,
|
83
|
-
[:bool, 123],
|
84
|
-
"BasicGrammar::Bool did not match\n123\n"
|
85
|
-
end
|
86
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
require 'temple'
|
2
|
-
|
3
|
-
module TestHelper
|
4
|
-
def with_html_safe
|
5
|
-
require 'temple/html/safe'
|
6
|
-
String.send(:define_method, :html_safe?) { false }
|
7
|
-
String.send(:define_method, :html_safe) { Temple::HTML::SafeString.new(self) }
|
8
|
-
yield
|
9
|
-
ensure
|
10
|
-
String.send(:undef_method, :html_safe?) if String.method_defined?(:html_safe?)
|
11
|
-
String.send(:undef_method, :html_safe) if String.method_defined?(:html_safe)
|
12
|
-
end
|
13
|
-
|
14
|
-
def grammar_validate(grammar, exp, message)
|
15
|
-
expect { grammar.validate!(exp) }.to raise_error(Temple::InvalidExpression, message)
|
16
|
-
end
|
17
|
-
|
18
|
-
def erb(src, options = {})
|
19
|
-
Temple::ERB::Template.new(options) { src }.render
|
20
|
-
end
|
21
|
-
|
22
|
-
def erubi(src, options = {})
|
23
|
-
Tilt::ErubiTemplate.new(options) { src }.render
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
RSpec.configure do |config|
|
28
|
-
config.include TestHelper
|
29
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Temple::StaticAnalyzer do
|
4
|
-
describe '.available?' do
|
5
|
-
it 'should return true if its dependency is available' do
|
6
|
-
expect(Temple::StaticAnalyzer.available?).to eq(defined?(Ripper) && Ripper.respond_to?(:lex))
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
if Temple::StaticAnalyzer.available?
|
11
|
-
describe '.static?' do
|
12
|
-
it 'should return true if given Ruby expression is static' do
|
13
|
-
['true', 'false', '"hello world"', "[1, { 2 => 3 }]", "[\n1,\n]"].each do |exp|
|
14
|
-
expect(Temple::StaticAnalyzer.static?(exp)).to eq(true)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'should return false if given Ruby expression is dynamic' do
|
19
|
-
['1 + 2', 'variable', 'method_call(a)', 'CONSTANT'].each do |exp|
|
20
|
-
expect(Temple::StaticAnalyzer.static?(exp)).to eq(false)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
describe '.syntax_error?' do
|
26
|
-
it 'should return false if given Ruby expression is valid' do
|
27
|
-
['Foo.bar.baz { |c| c.d! }', '{ foo: bar }'].each do |exp|
|
28
|
-
expect(Temple::StaticAnalyzer.syntax_error?(exp)).to eq(false)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'should return true if given Ruby expression is invalid' do
|
33
|
-
['Foo.bar.baz { |c| c.d! ', ' foo: bar '].each do |exp|
|
34
|
-
expect(Temple::StaticAnalyzer.syntax_error?(exp)).to eq(true)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
data/spec/utils_spec.rb
DELETED
@@ -1,39 +0,0 @@
|
|
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('<')
|
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('<')
|
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
|