curlybars 1.7.0 → 1.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/curlybars/error/lex.rb +1 -1
- data/lib/curlybars/error/parse.rb +1 -1
- data/lib/curlybars/node/path.rb +11 -13
- data/lib/curlybars/presenter.rb +2 -2
- data/lib/curlybars/template_handler.rb +3 -11
- data/lib/curlybars/version.rb +1 -1
- metadata +17 -93
- data/spec/acceptance/application_layout_spec.rb +0 -60
- data/spec/acceptance/collection_blocks_spec.rb +0 -28
- data/spec/acceptance/global_helper_spec.rb +0 -25
- data/spec/curlybars/configuration_spec.rb +0 -57
- data/spec/curlybars/error/base_spec.rb +0 -41
- data/spec/curlybars/error/compile_spec.rb +0 -19
- data/spec/curlybars/error/lex_spec.rb +0 -25
- data/spec/curlybars/error/parse_spec.rb +0 -74
- data/spec/curlybars/error/render_spec.rb +0 -19
- data/spec/curlybars/error/validate_spec.rb +0 -19
- data/spec/curlybars/lexer_spec.rb +0 -490
- data/spec/curlybars/method_whitelist_spec.rb +0 -299
- data/spec/curlybars/processor/tilde_spec.rb +0 -60
- data/spec/curlybars/rendering_support_spec.rb +0 -421
- data/spec/curlybars/safe_buffer_spec.rb +0 -46
- data/spec/curlybars/template_handler_spec.rb +0 -225
- data/spec/integration/cache_spec.rb +0 -126
- data/spec/integration/comment_spec.rb +0 -60
- data/spec/integration/exception_spec.rb +0 -31
- data/spec/integration/node/block_helper_else_spec.rb +0 -420
- data/spec/integration/node/each_else_spec.rb +0 -408
- data/spec/integration/node/each_spec.rb +0 -289
- data/spec/integration/node/escape_spec.rb +0 -27
- data/spec/integration/node/helper_spec.rb +0 -186
- data/spec/integration/node/if_else_spec.rb +0 -170
- data/spec/integration/node/if_spec.rb +0 -153
- data/spec/integration/node/output_spec.rb +0 -66
- data/spec/integration/node/partial_spec.rb +0 -64
- data/spec/integration/node/path_spec.rb +0 -296
- data/spec/integration/node/root_spec.rb +0 -13
- data/spec/integration/node/sub_expression_spec.rb +0 -426
- data/spec/integration/node/template_spec.rb +0 -84
- data/spec/integration/node/unless_else_spec.rb +0 -139
- data/spec/integration/node/unless_spec.rb +0 -128
- data/spec/integration/node/with_spec.rb +0 -178
- data/spec/integration/processor/tilde_spec.rb +0 -38
- data/spec/integration/processors_spec.rb +0 -29
- data/spec/integration/visitor_spec.rb +0 -154
@@ -1,128 +0,0 @@
|
|
1
|
-
describe "{{#unless}}...{{/unless}}" do
|
2
|
-
let(:global_helpers_providers) { [] }
|
3
|
-
|
4
|
-
describe "#compile" do
|
5
|
-
let(:post) { double("post") }
|
6
|
-
let(:presenter) { IntegrationTest::Presenter.new(double("view_context"), post: post) }
|
7
|
-
|
8
|
-
it "returns unless_template when condition is false" do
|
9
|
-
allow(presenter).to receive(:allows_method?).with(:condition).and_return(true)
|
10
|
-
allow(presenter).to receive(:condition).and_return(false)
|
11
|
-
|
12
|
-
template = Curlybars.compile(<<-HBS)
|
13
|
-
{{#unless condition}}
|
14
|
-
unless_template
|
15
|
-
{{/unless}}
|
16
|
-
HBS
|
17
|
-
|
18
|
-
expect(eval(template)).to resemble(<<-HTML)
|
19
|
-
unless_template
|
20
|
-
HTML
|
21
|
-
end
|
22
|
-
|
23
|
-
it "doesn't return unless_template when condition is true" do
|
24
|
-
allow(presenter).to receive(:allows_method?).with(:condition).and_return(true)
|
25
|
-
allow(presenter).to receive(:condition).and_return(true)
|
26
|
-
|
27
|
-
template = Curlybars.compile(<<-HBS)
|
28
|
-
{{#unless condition}}
|
29
|
-
unless_template
|
30
|
-
{{/unless}}
|
31
|
-
HBS
|
32
|
-
|
33
|
-
expect(eval(template)).to resemble("")
|
34
|
-
end
|
35
|
-
|
36
|
-
it "works with nested unless blocks (double negative)" do
|
37
|
-
allow(presenter).to receive(:allows_method?).with(:first_condition).and_return(true)
|
38
|
-
allow(presenter).to receive(:allows_method?).with(:second_condition).and_return(true)
|
39
|
-
allow(presenter).to receive(:first_condition).and_return(false)
|
40
|
-
allow(presenter).to receive(:second_condition).and_return(false)
|
41
|
-
|
42
|
-
template = Curlybars.compile(<<-HBS)
|
43
|
-
{{#unless first_condition}}
|
44
|
-
{{#unless second_condition}}
|
45
|
-
inner_unless_template
|
46
|
-
{{/unless}}
|
47
|
-
outer_unless_template
|
48
|
-
{{/unless}}
|
49
|
-
HBS
|
50
|
-
|
51
|
-
expect(eval(template)).to resemble(<<-HTML)
|
52
|
-
inner_unless_template
|
53
|
-
outer_unless_template
|
54
|
-
HTML
|
55
|
-
end
|
56
|
-
|
57
|
-
it "allows empty unless_template" do
|
58
|
-
allow(presenter).to receive(:allows_method?).with(:valid).and_return(true)
|
59
|
-
allow(presenter).to receive(:valid).and_return(true)
|
60
|
-
|
61
|
-
template = Curlybars.compile(<<-HBS)
|
62
|
-
{{#unless valid}}{{/unless}}
|
63
|
-
HBS
|
64
|
-
|
65
|
-
expect(eval(template)).to resemble("")
|
66
|
-
end
|
67
|
-
|
68
|
-
it "works with nested unless blocks (negative and positive)" do
|
69
|
-
allow(presenter).to receive(:allows_method?).with(:first_condition).and_return(true)
|
70
|
-
allow(presenter).to receive(:allows_method?).with(:second_condition).and_return(true)
|
71
|
-
allow(presenter).to receive(:first_condition).and_return(false)
|
72
|
-
allow(presenter).to receive(:second_condition).and_return(true)
|
73
|
-
|
74
|
-
template = Curlybars.compile(<<-HBS)
|
75
|
-
{{#unless first_condition}}
|
76
|
-
{{#unless second_condition}}
|
77
|
-
inner_unless_template
|
78
|
-
{{/unless}}
|
79
|
-
outer_unless_template
|
80
|
-
{{/unless}}
|
81
|
-
HBS
|
82
|
-
|
83
|
-
expect(eval(template)).to resemble(<<-HTML)
|
84
|
-
outer_unless_template
|
85
|
-
HTML
|
86
|
-
end
|
87
|
-
|
88
|
-
it "allows usage of variables in condition" do
|
89
|
-
template = Curlybars.compile(<<-HBS)
|
90
|
-
{{#each two_elements}}
|
91
|
-
{{#unless @first}}I am the second!{{/unless}}
|
92
|
-
{{/each}}
|
93
|
-
HBS
|
94
|
-
|
95
|
-
expect(eval(template)).to resemble(<<-HTML)
|
96
|
-
I am the second!
|
97
|
-
HTML
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
describe "#validate" do
|
102
|
-
it "validates with errors the condition" do
|
103
|
-
dependency_tree = {}
|
104
|
-
|
105
|
-
source = <<-HBS
|
106
|
-
{{#unless condition}}{{/unless}}
|
107
|
-
HBS
|
108
|
-
|
109
|
-
errors = Curlybars.validate(dependency_tree, source)
|
110
|
-
|
111
|
-
expect(errors).not_to be_empty
|
112
|
-
end
|
113
|
-
|
114
|
-
it "validates with errors the nested template" do
|
115
|
-
dependency_tree = { condition: nil }
|
116
|
-
|
117
|
-
source = <<-HBS
|
118
|
-
{{#unless condition}}
|
119
|
-
{{unallowed_method}}
|
120
|
-
{{/unless}}
|
121
|
-
HBS
|
122
|
-
|
123
|
-
errors = Curlybars.validate(dependency_tree, source)
|
124
|
-
|
125
|
-
expect(errors).not_to be_empty
|
126
|
-
end
|
127
|
-
end
|
128
|
-
end
|
@@ -1,178 +0,0 @@
|
|
1
|
-
describe "{{#with presenter}}...{{/with}}" do
|
2
|
-
let(:global_helpers_providers) { [IntegrationTest::GlobalHelperProvider.new] }
|
3
|
-
|
4
|
-
describe "#compile" do
|
5
|
-
let(:post) { double("post") }
|
6
|
-
let(:presenter) { IntegrationTest::Presenter.new(double("view_context"), post: post) }
|
7
|
-
|
8
|
-
it "works scopes one level" do
|
9
|
-
template = Curlybars.compile(<<-HBS)
|
10
|
-
{{#with user}}
|
11
|
-
{{avatar.url}}
|
12
|
-
{{/with}}
|
13
|
-
HBS
|
14
|
-
|
15
|
-
expect(eval(template)).to resemble(<<-HTML)
|
16
|
-
http://example.com/foo.png
|
17
|
-
HTML
|
18
|
-
end
|
19
|
-
|
20
|
-
it "scopes two levels" do
|
21
|
-
template = Curlybars.compile(<<-HBS)
|
22
|
-
{{#with user}}
|
23
|
-
{{#with avatar}}
|
24
|
-
{{url}}
|
25
|
-
{{/with}}
|
26
|
-
{{/with}}
|
27
|
-
HBS
|
28
|
-
|
29
|
-
expect(eval(template)).to resemble(<<-HTML)
|
30
|
-
http://example.com/foo.png
|
31
|
-
HTML
|
32
|
-
end
|
33
|
-
|
34
|
-
it "allows subexpressions" do
|
35
|
-
template = Curlybars.compile(<<-HBS)
|
36
|
-
{{#with (translate user "sk-SK")}}
|
37
|
-
{{avatar.url}}
|
38
|
-
{{/with}}
|
39
|
-
HBS
|
40
|
-
|
41
|
-
expect(eval(template)).to resemble(<<-HTML)
|
42
|
-
http://example.com/foo.png?locale=sk-SK
|
43
|
-
HTML
|
44
|
-
end
|
45
|
-
|
46
|
-
it "allows empty with_template" do
|
47
|
-
template = Curlybars.compile(<<-HBS)
|
48
|
-
{{#with user}}{{/with}}
|
49
|
-
HBS
|
50
|
-
|
51
|
-
expect(eval(template)).to resemble("")
|
52
|
-
end
|
53
|
-
|
54
|
-
it "renders the else template if the context is nil" do
|
55
|
-
template = Curlybars.compile(<<-HBS)
|
56
|
-
{{#with return_nil}}
|
57
|
-
text
|
58
|
-
{{else}}
|
59
|
-
else
|
60
|
-
{{/with}}
|
61
|
-
HBS
|
62
|
-
|
63
|
-
expect(eval(template)).to resemble(<<-HTML)
|
64
|
-
else
|
65
|
-
HTML
|
66
|
-
end
|
67
|
-
|
68
|
-
it "renders nothing if the context is nil and no else block is specified" do
|
69
|
-
template = Curlybars.compile(<<-HBS)
|
70
|
-
{{#with return_nil}}
|
71
|
-
text
|
72
|
-
{{/with}}
|
73
|
-
HBS
|
74
|
-
|
75
|
-
expect(eval(template)).to resemble("")
|
76
|
-
end
|
77
|
-
|
78
|
-
it "raises an exception if the parameter is not a context type object" do
|
79
|
-
template = Curlybars.compile(<<-HBS)
|
80
|
-
{{#with return_true}}{{/with}}
|
81
|
-
HBS
|
82
|
-
|
83
|
-
expect do
|
84
|
-
eval(template)
|
85
|
-
end.to raise_error(Curlybars::Error::Render)
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
describe "#validate" do
|
90
|
-
it "without errors" do
|
91
|
-
dependency_tree = { a_presenter: {} }
|
92
|
-
|
93
|
-
source = <<-HBS
|
94
|
-
{{#with a_presenter}}{{/with}}
|
95
|
-
HBS
|
96
|
-
|
97
|
-
errors = Curlybars.validate(dependency_tree, source)
|
98
|
-
|
99
|
-
expect(errors).to be_empty
|
100
|
-
end
|
101
|
-
|
102
|
-
it "without errors when a presenter helper is used" do
|
103
|
-
dependency_tree = { translate_article: [:helper, { title: nil }] }
|
104
|
-
|
105
|
-
source = <<-HBS
|
106
|
-
{{#with (translate_article 12345 "en-US")}}
|
107
|
-
{{title}}
|
108
|
-
{{/with}}
|
109
|
-
HBS
|
110
|
-
|
111
|
-
errors = Curlybars.validate(dependency_tree, source)
|
112
|
-
|
113
|
-
expect(errors).to be_empty
|
114
|
-
end
|
115
|
-
|
116
|
-
it "without errors when a generic presenter helper is used" do
|
117
|
-
dependency_tree = { article: { title: nil }, translate: [:helper, {}] }
|
118
|
-
|
119
|
-
source = <<-HBS
|
120
|
-
{{#with (translate article "en-US")}}
|
121
|
-
{{title}}
|
122
|
-
{{/with}}
|
123
|
-
HBS
|
124
|
-
|
125
|
-
errors = Curlybars.validate(dependency_tree, source)
|
126
|
-
|
127
|
-
expect(errors).to be_empty
|
128
|
-
end
|
129
|
-
|
130
|
-
it "with errors due to a leaf" do
|
131
|
-
dependency_tree = { not_a_presenter: nil }
|
132
|
-
|
133
|
-
source = <<-HBS
|
134
|
-
{{#with not_a_presenter}}{{/with}}
|
135
|
-
HBS
|
136
|
-
|
137
|
-
errors = Curlybars.validate(dependency_tree, source)
|
138
|
-
|
139
|
-
expect(errors).not_to be_empty
|
140
|
-
end
|
141
|
-
|
142
|
-
it "with errors due unallowed method" do
|
143
|
-
dependency_tree = {}
|
144
|
-
|
145
|
-
source = <<-HBS
|
146
|
-
{{#with unallowed}}{{/with}}
|
147
|
-
HBS
|
148
|
-
|
149
|
-
errors = Curlybars.validate(dependency_tree, source)
|
150
|
-
|
151
|
-
expect(errors).not_to be_empty
|
152
|
-
end
|
153
|
-
|
154
|
-
it "with errors due collection helpers" do
|
155
|
-
dependency_tree = { reverse_articles: [:helper, [{ title: nil }]] }
|
156
|
-
|
157
|
-
source = <<-HBS
|
158
|
-
{{#with (reverse_articles)}}{{/with}}
|
159
|
-
HBS
|
160
|
-
|
161
|
-
errors = Curlybars.validate(dependency_tree, source)
|
162
|
-
|
163
|
-
expect(errors).not_to be_empty
|
164
|
-
end
|
165
|
-
|
166
|
-
it "with errors due generic collection helpers" do
|
167
|
-
dependency_tree = { articles: [{ title: nil }], slice: [:helper, [{}]] }
|
168
|
-
|
169
|
-
source = <<-HBS
|
170
|
-
{{#with (slice articles 0 4)}}{{/with}}
|
171
|
-
HBS
|
172
|
-
|
173
|
-
errors = Curlybars.validate(dependency_tree, source)
|
174
|
-
|
175
|
-
expect(errors).not_to be_empty
|
176
|
-
end
|
177
|
-
end
|
178
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
describe "tilde operator" do
|
2
|
-
let(:global_helpers_providers) { [] }
|
3
|
-
|
4
|
-
describe "compilation" do
|
5
|
-
let(:post) { double("post") }
|
6
|
-
let(:presenter) { IntegrationTest::Presenter.new(double("view_context"), post: post) }
|
7
|
-
|
8
|
-
it "{{~ ... }} removes trailing whitespaces and newlines from the previous :TEXT" do
|
9
|
-
template = Curlybars.compile("before \r\t\n{{~'curlybars'}}\n\t\r after")
|
10
|
-
|
11
|
-
expect(eval(template)).to resemble("beforecurlybars\n\t\r after")
|
12
|
-
end
|
13
|
-
|
14
|
-
it "{{ ... ~}} removes trailing whitespaces and newlines from the next :TEXT" do
|
15
|
-
template = Curlybars.compile("before \r\t\n{{'curlybars'~}}\n\t\r after")
|
16
|
-
|
17
|
-
expect(eval(template)).to resemble("before \r\t\ncurlybarsafter")
|
18
|
-
end
|
19
|
-
|
20
|
-
it "{{~ ... ~}} does not remove trailing whitespaces and newlines from the next :TEXT" do
|
21
|
-
template = Curlybars.compile("before \r\t\n{{~'curlybars'~}}\n\t\r after")
|
22
|
-
|
23
|
-
expect(eval(template)).to resemble("beforecurlybarsafter")
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
describe "validation" do
|
28
|
-
let(:presenter) { double(:presenter, dependency_tree: { curlybars: nil }) }
|
29
|
-
|
30
|
-
it "runs even when 'run_processors' flag is set to false" do
|
31
|
-
allow(Curlybars::Processor::Tilde).to receive(:process!)
|
32
|
-
|
33
|
-
Curlybars.validate(presenter.dependency_tree, "source", run_processors: false)
|
34
|
-
|
35
|
-
expect(Curlybars::Processor::Tilde).to have_received(:process!)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
describe "processors" do
|
2
|
-
let(:presenter) { double(:presenter, dependency_tree: { curlybars: nil }) }
|
3
|
-
let(:processor) { double(:processor) }
|
4
|
-
|
5
|
-
before do
|
6
|
-
allow(Curlybars.configuration).to receive(:custom_processors).and_return([processor])
|
7
|
-
allow(processor).to receive(:process!)
|
8
|
-
end
|
9
|
-
|
10
|
-
describe "validation" do
|
11
|
-
it "are run by default" do
|
12
|
-
Curlybars.validate(presenter.dependency_tree, "source")
|
13
|
-
|
14
|
-
expect(processor).to have_received(:process!)
|
15
|
-
end
|
16
|
-
|
17
|
-
it "are run when run_processors is true" do
|
18
|
-
Curlybars.validate(presenter.dependency_tree, "source", run_processors: true)
|
19
|
-
|
20
|
-
expect(processor).to have_received(:process!)
|
21
|
-
end
|
22
|
-
|
23
|
-
it "are not run when run_processors is false" do
|
24
|
-
Curlybars.validate(presenter.dependency_tree, "source", run_processors: false)
|
25
|
-
|
26
|
-
expect(processor).not_to have_received(:process!)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,154 +0,0 @@
|
|
1
|
-
describe "visitor" do
|
2
|
-
let(:source) do
|
3
|
-
<<-HBS
|
4
|
-
{{#print_args_and_options 'first' 'second' key='value'}}
|
5
|
-
{{/print_args_and_options}}
|
6
|
-
|
7
|
-
{{calc (calc 1 "+" 2) "*" 3}}
|
8
|
-
|
9
|
-
{{#render_inverse}}
|
10
|
-
fn
|
11
|
-
{{else}}
|
12
|
-
inverse
|
13
|
-
{{@variable}}
|
14
|
-
{{/render_inverse}}
|
15
|
-
|
16
|
-
{{#each foo}}
|
17
|
-
top
|
18
|
-
{{#each bar}}
|
19
|
-
middle
|
20
|
-
{{#each baz}}
|
21
|
-
inner
|
22
|
-
{{else}}
|
23
|
-
inner inverse
|
24
|
-
{{/each}}
|
25
|
-
{{/each}}
|
26
|
-
{{/each}}
|
27
|
-
|
28
|
-
{{#if valid}}
|
29
|
-
if_template
|
30
|
-
{{#if bar}}
|
31
|
-
foo
|
32
|
-
{{else}}
|
33
|
-
qux
|
34
|
-
{{/if}}
|
35
|
-
{{/if}}
|
36
|
-
|
37
|
-
{{#if baz}}
|
38
|
-
qux
|
39
|
-
{{/if}}
|
40
|
-
|
41
|
-
{{> partial}}
|
42
|
-
|
43
|
-
{{user.avatar.url}}
|
44
|
-
{{#with this}}
|
45
|
-
{{user.avatar.url}}
|
46
|
-
{{/with}}
|
47
|
-
|
48
|
-
{{#unless things}}
|
49
|
-
hi
|
50
|
-
{{/unless}}
|
51
|
-
HBS
|
52
|
-
end
|
53
|
-
|
54
|
-
describe ".visit" do
|
55
|
-
it "visits BlockHelperElse nodes" do
|
56
|
-
visitor = counting_visitor_for(Curlybars::Node::BlockHelperElse)
|
57
|
-
output = Curlybars.visit(visitor, source)
|
58
|
-
expect(output).to eq(5)
|
59
|
-
end
|
60
|
-
|
61
|
-
it "visits EachElse nodes" do
|
62
|
-
visitor = counting_visitor_for(Curlybars::Node::EachElse)
|
63
|
-
output = Curlybars.visit(visitor, source)
|
64
|
-
expect(output).to eq(3)
|
65
|
-
end
|
66
|
-
|
67
|
-
it "visits IfElse nodes" do
|
68
|
-
visitor = counting_visitor_for(Curlybars::Node::IfElse)
|
69
|
-
output = Curlybars.visit(visitor, source)
|
70
|
-
expect(output).to eq(3)
|
71
|
-
end
|
72
|
-
|
73
|
-
it "visits Item nodes" do
|
74
|
-
visitor = counting_visitor_for(Curlybars::Node::Item)
|
75
|
-
output = Curlybars.visit(visitor, source)
|
76
|
-
expect(output).to eq(44)
|
77
|
-
end
|
78
|
-
|
79
|
-
it "visits Literal nodes" do
|
80
|
-
visitor = counting_visitor_for(Curlybars::Node::Literal)
|
81
|
-
output = Curlybars.visit(visitor, source)
|
82
|
-
expect(output).to eq(8)
|
83
|
-
end
|
84
|
-
|
85
|
-
it "visits Option nodes" do
|
86
|
-
visitor = counting_visitor_for(Curlybars::Node::Option)
|
87
|
-
output = Curlybars.visit(visitor, source)
|
88
|
-
expect(output).to eq(1)
|
89
|
-
end
|
90
|
-
|
91
|
-
it "visits Partial nodes" do
|
92
|
-
visitor = counting_visitor_for(Curlybars::Node::Partial)
|
93
|
-
output = Curlybars.visit(visitor, source)
|
94
|
-
expect(output).to eq(1)
|
95
|
-
end
|
96
|
-
|
97
|
-
it "visits Path nodes" do
|
98
|
-
visitor = counting_visitor_for(Curlybars::Node::Path)
|
99
|
-
output = Curlybars.visit(visitor, source)
|
100
|
-
expect(output).to eq(15)
|
101
|
-
end
|
102
|
-
|
103
|
-
it "visits Root nodes" do
|
104
|
-
visitor = counting_visitor_for(Curlybars::Node::Root)
|
105
|
-
output = Curlybars.visit(visitor, source)
|
106
|
-
expect(output).to eq(1)
|
107
|
-
end
|
108
|
-
|
109
|
-
it "visits SubExpression nodes" do
|
110
|
-
visitor = counting_visitor_for(Curlybars::Node::SubExpression)
|
111
|
-
output = Curlybars.visit(visitor, source)
|
112
|
-
expect(output).to eq(1)
|
113
|
-
end
|
114
|
-
|
115
|
-
it "visits Template nodes" do
|
116
|
-
visitor = counting_visitor_for(Curlybars::Node::Template)
|
117
|
-
output = Curlybars.visit(visitor, source)
|
118
|
-
expect(output).to eq(14)
|
119
|
-
end
|
120
|
-
|
121
|
-
it "visits Text nodes" do
|
122
|
-
visitor = counting_visitor_for(Curlybars::Node::Text)
|
123
|
-
output = Curlybars.visit(visitor, source)
|
124
|
-
expect(output).to eq(29)
|
125
|
-
end
|
126
|
-
|
127
|
-
it "visits UnlessElse nodes" do
|
128
|
-
visitor = counting_visitor_for(Curlybars::Node::UnlessElse)
|
129
|
-
output = Curlybars.visit(visitor, source)
|
130
|
-
expect(output).to eq(1)
|
131
|
-
end
|
132
|
-
|
133
|
-
it "visits Variable nodes" do
|
134
|
-
visitor = counting_visitor_for(Curlybars::Node::Variable)
|
135
|
-
output = Curlybars.visit(visitor, source)
|
136
|
-
expect(output).to eq(1)
|
137
|
-
end
|
138
|
-
|
139
|
-
it "visits WithElse nodes" do
|
140
|
-
visitor = counting_visitor_for(Curlybars::Node::WithElse)
|
141
|
-
output = Curlybars.visit(visitor, source)
|
142
|
-
expect(output).to eq(1)
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
def counting_visitor_for(klass)
|
147
|
-
Class.new(Curlybars::Visitor) do
|
148
|
-
define_method "visit_#{klass.name.demodulize.underscore}" do |node|
|
149
|
-
self.context += 1
|
150
|
-
super(node)
|
151
|
-
end
|
152
|
-
end.new(0)
|
153
|
-
end
|
154
|
-
end
|