mvz-ruby-handlebars 0.0.11 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +88 -8
- data/Gemfile +1 -1
- data/README.md +1 -1
- data/Rakefile +4 -4
- data/lib/ruby-handlebars/context.rb +1 -1
- data/lib/ruby-handlebars/escapers/html_escaper.rb +1 -1
- data/lib/ruby-handlebars/helper.rb +1 -1
- data/lib/ruby-handlebars/helpers/each_helper.rb +3 -3
- data/lib/ruby-handlebars/helpers/helper_missing_helper.rb +2 -2
- data/lib/ruby-handlebars/helpers/if_helper.rb +2 -2
- data/lib/ruby-handlebars/helpers/register_default_helpers.rb +5 -5
- data/lib/ruby-handlebars/helpers/unless_helper.rb +2 -2
- data/lib/ruby-handlebars/helpers/with_helper.rb +2 -2
- data/lib/ruby-handlebars/parser.rb +19 -21
- data/lib/ruby-handlebars/template.rb +1 -1
- data/lib/ruby-handlebars/tree.rb +3 -3
- data/lib/ruby-handlebars/version.rb +1 -1
- data/lib/ruby-handlebars.rb +8 -8
- data/spec/handlebars_spec.rb +102 -102
- data/spec/parser_spec.rb +163 -155
- data/spec/ruby-handlebars/context_spec.rb +64 -64
- data/spec/ruby-handlebars/helpers/each_helper_spec.rb +41 -41
- data/spec/ruby-handlebars/helpers/helper_missing_helper_spec.rb +14 -14
- data/spec/ruby-handlebars/helpers/if_helper_spec.rb +16 -16
- data/spec/ruby-handlebars/helpers/register_default_helpers_spec.rb +10 -10
- data/spec/ruby-handlebars/helpers/unless_helper_spec.rb +14 -14
- data/spec/ruby-handlebars/helpers/with_helper_spec.rb +6 -6
- data/spec/spec_helper.rb +1 -1
- data/spec/tree_spec.rb +3 -3
- metadata +18 -4
@@ -1,144 +1,144 @@
|
|
1
|
-
require_relative
|
2
|
-
require_relative
|
1
|
+
require_relative "../spec_helper"
|
2
|
+
require_relative "../../lib/ruby-handlebars/context"
|
3
3
|
|
4
4
|
describe Handlebars::Context do
|
5
5
|
let(:ctx) { described_class.new(nil, data) }
|
6
6
|
|
7
|
-
context
|
7
|
+
context "get" do
|
8
8
|
let(:data) { {
|
9
|
-
key_data:
|
9
|
+
key_data: "Some value"
|
10
10
|
} }
|
11
11
|
|
12
12
|
before do
|
13
|
-
ctx.add_item(:key_locals,
|
14
|
-
ctx.add_item(:a_list, [
|
15
|
-
ctx.add_item(:a_hash, {key:
|
13
|
+
ctx.add_item(:key_locals, "Some other value")
|
14
|
+
ctx.add_item(:a_list, ["a", "b", "c"])
|
15
|
+
ctx.add_item(:a_hash, {key: "A third value"})
|
16
16
|
end
|
17
17
|
|
18
|
-
it
|
19
|
-
expect(ctx.get(
|
20
|
-
expect(ctx.get(
|
18
|
+
it "fetches data stored in the context" do
|
19
|
+
expect(ctx.get("key_data")).to eq("Some value")
|
20
|
+
expect(ctx.get("key_locals")).to eq("Some other value")
|
21
21
|
end
|
22
22
|
|
23
|
-
it
|
24
|
-
ctx.add_item(:key_data,
|
23
|
+
it "uses data from @locals before @data" do
|
24
|
+
ctx.add_item(:key_data, "Now stored in @locals")
|
25
25
|
|
26
|
-
expect(ctx.get(
|
26
|
+
expect(ctx.get("key_data")).to eq("Now stored in @locals")
|
27
27
|
end
|
28
28
|
|
29
|
-
context
|
30
|
-
it
|
31
|
-
expect(ctx.get(
|
29
|
+
context "when digging inside data" do
|
30
|
+
it "uses keys separated by dots" do
|
31
|
+
expect(ctx.get("a_hash.key")).to eq("A third value")
|
32
32
|
end
|
33
33
|
|
34
|
-
it
|
35
|
-
expect(ctx.get(
|
36
|
-
expect(ctx.get(
|
34
|
+
it "can also use methods" do
|
35
|
+
expect(ctx.get("a_list.first")).to eq("a")
|
36
|
+
expect(ctx.get("a_list.last")).to eq("c")
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
-
context
|
41
|
+
context "add_item" do
|
42
42
|
let(:data) { {} }
|
43
43
|
|
44
|
-
it
|
45
|
-
expect(ctx.get(
|
46
|
-
ctx.add_item(
|
47
|
-
expect(ctx.get(
|
44
|
+
it "adds a new key to the stored data" do
|
45
|
+
expect(ctx.get("my_key")).to be nil
|
46
|
+
ctx.add_item("my_key", "With some value")
|
47
|
+
expect(ctx.get("my_key")).to eq("With some value")
|
48
48
|
end
|
49
49
|
|
50
|
-
it
|
51
|
-
ctx.add_item(
|
52
|
-
ctx.add_item(
|
50
|
+
it "overrides existing values" do
|
51
|
+
ctx.add_item("a", 12)
|
52
|
+
ctx.add_item("a", 25)
|
53
53
|
|
54
|
-
expect(ctx.get(
|
54
|
+
expect(ctx.get("a")).to eq(25)
|
55
55
|
end
|
56
56
|
|
57
|
-
it
|
58
|
-
ctx.add_item(
|
57
|
+
it "does not make differences between string and sym keys" do
|
58
|
+
ctx.add_item("a", 12)
|
59
59
|
ctx.add_item(:a, 25)
|
60
60
|
|
61
|
-
expect(ctx.get(
|
61
|
+
expect(ctx.get("a")).to eq(25)
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
-
context
|
65
|
+
context "add_items" do
|
66
66
|
let(:data) { {} }
|
67
67
|
|
68
|
-
it
|
68
|
+
it "is basically a wrapper around add_item to add multiple items" do
|
69
69
|
allow(ctx).to receive(:add_item)
|
70
70
|
|
71
|
-
ctx.add_items(a:
|
71
|
+
ctx.add_items(a: "One key", b: "A second key", c: "A third key")
|
72
72
|
expect(ctx).to have_received(:add_item).at_most(3).times
|
73
|
-
expect(ctx).to have_received(:add_item).once.with(:a,
|
74
|
-
expect(ctx).to have_received(:add_item).once.with(:b,
|
75
|
-
expect(ctx).to have_received(:add_item).once.with(:c,
|
73
|
+
expect(ctx).to have_received(:add_item).once.with(:a, "One key")
|
74
|
+
expect(ctx).to have_received(:add_item).once.with(:b, "A second key")
|
75
|
+
expect(ctx).to have_received(:add_item).once.with(:c, "A third key")
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
79
|
-
context
|
79
|
+
context "with_temporary_context" do
|
80
80
|
let(:data) { {} }
|
81
81
|
|
82
82
|
before do
|
83
83
|
ctx.add_items(
|
84
|
-
key:
|
85
|
-
value:
|
84
|
+
key: "some key",
|
85
|
+
value: "some value"
|
86
86
|
)
|
87
87
|
end
|
88
88
|
|
89
|
-
it
|
90
|
-
expect(ctx.get(
|
89
|
+
it "allows creating temporary variables" do
|
90
|
+
expect(ctx.get("unknown_key")).to be nil
|
91
91
|
|
92
92
|
ctx.with_temporary_context(unknown_key: 42) do
|
93
|
-
expect(ctx.get(
|
93
|
+
expect(ctx.get("unknown_key")).to eq(42)
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
97
|
-
it
|
98
|
-
ctx.with_temporary_context(value:
|
99
|
-
expect(ctx.get(
|
97
|
+
it "can override an existing variable" do
|
98
|
+
ctx.with_temporary_context(value: "A completelly new value") do
|
99
|
+
expect(ctx.get("value")).to eq("A completelly new value")
|
100
100
|
end
|
101
101
|
end
|
102
102
|
|
103
|
-
it
|
103
|
+
it "provides mutable variables (well, variables ...)" do
|
104
104
|
ctx.with_temporary_context(unknown_key: 42) do
|
105
|
-
expect(ctx.get(
|
106
|
-
ctx.add_item(
|
107
|
-
expect(ctx.get(
|
105
|
+
expect(ctx.get("unknown_key")).to eq(42)
|
106
|
+
ctx.add_item("unknown_key", 56)
|
107
|
+
expect(ctx.get("unknown_key")).to eq(56)
|
108
108
|
end
|
109
109
|
end
|
110
110
|
|
111
|
-
it
|
112
|
-
ctx.with_temporary_context(value:
|
113
|
-
expect(ctx.get(
|
111
|
+
it "after the block, existing variables are restored" do
|
112
|
+
ctx.with_temporary_context(value: "A completelly new value") do
|
113
|
+
expect(ctx.get("value")).to eq("A completelly new value")
|
114
114
|
end
|
115
115
|
|
116
|
-
expect(ctx.get(
|
116
|
+
expect(ctx.get("value")).to eq("some value")
|
117
117
|
end
|
118
118
|
|
119
|
-
it
|
119
|
+
it "after the block, the declared variables are not available anymore" do
|
120
120
|
ctx.with_temporary_context(unknown_key: 42) do
|
121
|
-
expect(ctx.get(
|
121
|
+
expect(ctx.get("unknown_key")).to eq(42)
|
122
122
|
end
|
123
123
|
|
124
|
-
expect(ctx.get(
|
124
|
+
expect(ctx.get("unknown_key")).to be nil
|
125
125
|
end
|
126
126
|
|
127
|
-
it
|
128
|
-
expect( ctx.with_temporary_context(value:
|
127
|
+
it "returns the data executed by the block" do
|
128
|
+
expect( ctx.with_temporary_context(value: "A completelly new value") { 12 } ).to eq(12)
|
129
129
|
end
|
130
130
|
|
131
|
-
context
|
131
|
+
context "when data are stored in @data" do
|
132
132
|
let(:data) { {my_key: "With some value"} }
|
133
133
|
|
134
|
-
it
|
135
|
-
expect(ctx.get(
|
134
|
+
it "let them available after the block is executed" do
|
135
|
+
expect(ctx.get("my_key")).to eq("With some value")
|
136
136
|
|
137
137
|
ctx.with_temporary_context(my_key: 12) do
|
138
|
-
expect(ctx.get(
|
138
|
+
expect(ctx.get("my_key")).to eq(12)
|
139
139
|
end
|
140
140
|
|
141
|
-
expect(ctx.get(
|
141
|
+
expect(ctx.get("my_key")).to eq("With some value")
|
142
142
|
end
|
143
143
|
end
|
144
144
|
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
require_relative
|
2
|
-
require_relative
|
1
|
+
require_relative "../../spec_helper"
|
2
|
+
require_relative "./shared"
|
3
3
|
|
4
|
-
require_relative
|
5
|
-
require_relative
|
6
|
-
require_relative
|
4
|
+
require_relative "../../../lib/ruby-handlebars"
|
5
|
+
require_relative "../../../lib/ruby-handlebars/tree"
|
6
|
+
require_relative "../../../lib/ruby-handlebars/helpers/each_helper"
|
7
7
|
|
8
8
|
|
9
9
|
describe Handlebars::Helpers::EachHelper do
|
@@ -13,55 +13,55 @@ describe Handlebars::Helpers::EachHelper do
|
|
13
13
|
|
14
14
|
it_behaves_like "a registerable helper", "each"
|
15
15
|
|
16
|
-
context
|
16
|
+
context ".apply" do
|
17
17
|
include_context "shared apply helper"
|
18
18
|
|
19
|
-
let(:values) { [Handlebars::Tree::String.new(
|
19
|
+
let(:values) { [Handlebars::Tree::String.new("a"), Handlebars::Tree::String.new("b"), Handlebars::Tree::String.new("c") ]}
|
20
20
|
|
21
|
-
it
|
21
|
+
it "applies the block on all values" do
|
22
22
|
subject.apply(ctx, values, block, else_block)
|
23
23
|
|
24
24
|
expect(block).to have_received(:fn).exactly(3).times
|
25
25
|
expect(else_block).not_to have_received(:fn)
|
26
26
|
end
|
27
27
|
|
28
|
-
context
|
28
|
+
context "when values is nil" do
|
29
29
|
let(:values) { nil }
|
30
30
|
|
31
|
-
it
|
31
|
+
it "uses the else_block if provided" do
|
32
32
|
subject.apply(ctx, values, block, else_block)
|
33
33
|
|
34
34
|
expect(block).not_to have_received(:fn)
|
35
35
|
expect(else_block).to have_received(:fn).once
|
36
36
|
end
|
37
37
|
|
38
|
-
it
|
38
|
+
it "returns nil if no else_block is provided" do
|
39
39
|
expect(subject.apply(ctx, values, block, nil)).to be nil
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
-
context
|
43
|
+
context "when values is empty" do
|
44
44
|
let(:values) { [] }
|
45
45
|
|
46
|
-
it
|
46
|
+
it "uses the else_block if provided" do
|
47
47
|
subject.apply(ctx, values, block, else_block)
|
48
48
|
|
49
49
|
expect(block).not_to have_received(:fn)
|
50
50
|
expect(else_block).to have_received(:fn).once
|
51
51
|
end
|
52
52
|
|
53
|
-
it
|
53
|
+
it "returns nil if no else_block is provided" do
|
54
54
|
expect(subject.apply(ctx, values, block, nil)).to be nil
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
|
-
context
|
59
|
+
context "integration" do
|
60
60
|
include_context "shared helpers integration tests"
|
61
61
|
|
62
|
-
let(:ducks) {[{name:
|
62
|
+
let(:ducks) {[{name: "Huey"}, {name: "Dewey"}, {name: "Louis"}]}
|
63
63
|
|
64
|
-
it
|
64
|
+
it "simple case" do
|
65
65
|
template = [
|
66
66
|
"<ul>",
|
67
67
|
"{{#each items}} <li>{{this.name}}</li>",
|
@@ -84,7 +84,7 @@ describe Handlebars::Helpers::EachHelper do
|
|
84
84
|
].join("\n"))
|
85
85
|
end
|
86
86
|
|
87
|
-
it
|
87
|
+
it "considers not found items as an empty list and does not raise an error" do
|
88
88
|
template = [
|
89
89
|
"<ul>",
|
90
90
|
"{{#each stuff}} <li>{{this.name}}</li>",
|
@@ -97,7 +97,7 @@ describe Handlebars::Helpers::EachHelper do
|
|
97
97
|
].join("\n"))
|
98
98
|
end
|
99
99
|
|
100
|
-
it
|
100
|
+
it "considers not found items as an empty list and uses else block if provided" do
|
101
101
|
template = [
|
102
102
|
"<ul>",
|
103
103
|
"{{#each stuff}} <li>{{this.name}}</li>",
|
@@ -112,7 +112,7 @@ describe Handlebars::Helpers::EachHelper do
|
|
112
112
|
].join("\n"))
|
113
113
|
end
|
114
114
|
|
115
|
-
it
|
115
|
+
it "works with non-hash data" do
|
116
116
|
template = [
|
117
117
|
"<ul>",
|
118
118
|
"{{#each items}} <li>{{this.name}}</li>",
|
@@ -135,7 +135,7 @@ describe Handlebars::Helpers::EachHelper do
|
|
135
135
|
].join("\n"))
|
136
136
|
end
|
137
137
|
|
138
|
-
it
|
138
|
+
it "using an else statement" do
|
139
139
|
template = [
|
140
140
|
"<ul>",
|
141
141
|
"{{#each items}} <li>{{this.name}}</li>",
|
@@ -160,17 +160,17 @@ describe Handlebars::Helpers::EachHelper do
|
|
160
160
|
].join("\n"))
|
161
161
|
end
|
162
162
|
|
163
|
-
it
|
163
|
+
it "imbricated" do
|
164
164
|
data = {people: [
|
165
165
|
{
|
166
|
-
name:
|
167
|
-
email:
|
168
|
-
phones: [
|
166
|
+
name: "Huey",
|
167
|
+
email: "huey@junior-woodchucks.example.com",
|
168
|
+
phones: ["1234", "5678"],
|
169
169
|
},
|
170
170
|
{
|
171
|
-
name:
|
172
|
-
email:
|
173
|
-
phones: [
|
171
|
+
name: "Dewey",
|
172
|
+
email: "dewey@junior-woodchucks.example.com",
|
173
|
+
phones: ["4321"],
|
174
174
|
}
|
175
175
|
]}
|
176
176
|
|
@@ -215,8 +215,8 @@ describe Handlebars::Helpers::EachHelper do
|
|
215
215
|
].join("\n"))
|
216
216
|
end
|
217
217
|
|
218
|
-
context
|
219
|
-
it
|
218
|
+
context "special variables" do
|
219
|
+
it "@first" do
|
220
220
|
template = [
|
221
221
|
"{{#each items}}",
|
222
222
|
"{{this}}",
|
@@ -228,7 +228,7 @@ describe Handlebars::Helpers::EachHelper do
|
|
228
228
|
expect(evaluate(template, {items: %w(a b c)})).to eq("a first\nb\nc\n")
|
229
229
|
end
|
230
230
|
|
231
|
-
it
|
231
|
+
it "@last" do
|
232
232
|
template = [
|
233
233
|
"{{#each items}}",
|
234
234
|
"{{this}}",
|
@@ -240,7 +240,7 @@ describe Handlebars::Helpers::EachHelper do
|
|
240
240
|
expect(evaluate(template, {items: %w(a b c)})).to eq("a\nb\nc last\n")
|
241
241
|
end
|
242
242
|
|
243
|
-
it
|
243
|
+
it "@index" do
|
244
244
|
template = [
|
245
245
|
"{{#each items}}",
|
246
246
|
"{{this}} {{@index}}\n",
|
@@ -254,9 +254,9 @@ describe Handlebars::Helpers::EachHelper do
|
|
254
254
|
context 'integration with "as |value|" notation' do
|
255
255
|
include_context "shared helpers integration tests"
|
256
256
|
|
257
|
-
let(:ducks) {[{name:
|
257
|
+
let(:ducks) {[{name: "Huey"}, {name: "Dewey"}, {name: "Louis"}]}
|
258
258
|
|
259
|
-
it
|
259
|
+
it "simple case" do
|
260
260
|
template = [
|
261
261
|
"<ul>",
|
262
262
|
"{{#each items as |item|}} <li>{{item.name}}</li>",
|
@@ -273,17 +273,17 @@ describe Handlebars::Helpers::EachHelper do
|
|
273
273
|
].join("\n"))
|
274
274
|
end
|
275
275
|
|
276
|
-
it
|
276
|
+
it "imbricated" do
|
277
277
|
data = {people: [
|
278
278
|
{
|
279
|
-
name:
|
280
|
-
email:
|
281
|
-
phones: [
|
279
|
+
name: "Huey",
|
280
|
+
email: "huey@junior-woodchucks.example.com",
|
281
|
+
phones: ["1234", "5678"],
|
282
282
|
},
|
283
283
|
{
|
284
|
-
name:
|
285
|
-
email:
|
286
|
-
phones: [
|
284
|
+
name: "Dewey",
|
285
|
+
email: "dewey@junior-woodchucks.example.com",
|
286
|
+
phones: ["4321"],
|
287
287
|
}
|
288
288
|
]}
|
289
289
|
|
@@ -1,9 +1,9 @@
|
|
1
|
-
require_relative
|
2
|
-
require_relative
|
1
|
+
require_relative "../../spec_helper"
|
2
|
+
require_relative "./shared"
|
3
3
|
|
4
|
-
require_relative
|
5
|
-
require_relative
|
6
|
-
require_relative
|
4
|
+
require_relative "../../../lib/ruby-handlebars"
|
5
|
+
require_relative "../../../lib/ruby-handlebars/tree"
|
6
|
+
require_relative "../../../lib/ruby-handlebars/helpers/helper_missing_helper"
|
7
7
|
|
8
8
|
|
9
9
|
describe Handlebars::Helpers::HelperMissingHelper do
|
@@ -13,29 +13,29 @@ describe Handlebars::Helpers::HelperMissingHelper do
|
|
13
13
|
|
14
14
|
it_behaves_like "a registerable helper", "helperMissing"
|
15
15
|
|
16
|
-
context
|
16
|
+
context ".apply" do
|
17
17
|
let(:name) { "missing_helper" }
|
18
18
|
|
19
|
-
it
|
19
|
+
it "raises a Handlebars::UnknownHelper exception with the name given as a parameter" do
|
20
20
|
expect { subject.apply(ctx, name, nil, nil) }.to raise_exception(Handlebars::UnknownHelper, "Helper \"#{name}\" does not exist")
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
context
|
24
|
+
context "integration" do
|
25
25
|
include_context "shared helpers integration tests"
|
26
26
|
|
27
|
-
context
|
28
|
-
it
|
27
|
+
context "is called when an unknown helper is called in a template" do
|
28
|
+
it "should provide a useful error message with inline helpers" do
|
29
29
|
expect { evaluate('{{unknown "This will hardly work" }}') }.to raise_exception(Handlebars::UnknownHelper, 'Helper "unknown" does not exist')
|
30
30
|
end
|
31
31
|
|
32
|
-
it
|
33
|
-
expect { evaluate(
|
32
|
+
it "should provide a useful error message with block helpers" do
|
33
|
+
expect { evaluate("{{#unknown}}This will hardly work{{/unknown}}") }.to raise_exception(Handlebars::UnknownHelper, 'Helper "unknown" does not exist')
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
it
|
38
|
-
hbs.register_helper(
|
37
|
+
it "can be overriden easily" do
|
38
|
+
hbs.register_helper("helperMissing") do |context, name|
|
39
39
|
# Do nothing
|
40
40
|
end
|
41
41
|
|
@@ -1,8 +1,8 @@
|
|
1
|
-
require_relative
|
2
|
-
require_relative
|
1
|
+
require_relative "../../spec_helper"
|
2
|
+
require_relative "./shared"
|
3
3
|
|
4
|
-
require_relative
|
5
|
-
require_relative
|
4
|
+
require_relative "../../../lib/ruby-handlebars"
|
5
|
+
require_relative "../../../lib/ruby-handlebars/helpers/if_helper"
|
6
6
|
|
7
7
|
|
8
8
|
describe Handlebars::Helpers::IfHelper do
|
@@ -12,23 +12,23 @@ describe Handlebars::Helpers::IfHelper do
|
|
12
12
|
|
13
13
|
it_behaves_like "a registerable helper", "if"
|
14
14
|
|
15
|
-
context
|
16
|
-
it_behaves_like "a helper running the main block",
|
17
|
-
it_behaves_like "a helper running the main block",
|
18
|
-
it_behaves_like "a helper running the main block",
|
19
|
-
it_behaves_like "a helper running the main block",
|
15
|
+
context ".apply" do
|
16
|
+
it_behaves_like "a helper running the main block", "true", true
|
17
|
+
it_behaves_like "a helper running the main block", "a non-empty string", "something"
|
18
|
+
it_behaves_like "a helper running the main block", "a non-empty list", ["a"]
|
19
|
+
it_behaves_like "a helper running the main block", "a non-empty hash", {a: "b"}
|
20
20
|
|
21
21
|
it_behaves_like "a helper running the else block", "false", false
|
22
22
|
it_behaves_like "a helper running the else block", "an empty string", ""
|
23
23
|
it_behaves_like "a helper running the else block", "an empty list", []
|
24
24
|
it_behaves_like "a helper running the else block", "an empty hash", {}
|
25
25
|
|
26
|
-
context
|
26
|
+
context "when else_block is not present" do
|
27
27
|
include_context "shared apply helper"
|
28
28
|
let(:params) { false }
|
29
29
|
let(:else_block) { nil }
|
30
30
|
|
31
|
-
it
|
31
|
+
it "returns an empty-string" do
|
32
32
|
expect(subject.apply(ctx, params, block, else_block)).to eq("")
|
33
33
|
|
34
34
|
expect(block).not_to have_received(:fn)
|
@@ -37,11 +37,11 @@ describe Handlebars::Helpers::IfHelper do
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
-
context
|
40
|
+
context "integration" do
|
41
41
|
include_context "shared helpers integration tests"
|
42
42
|
|
43
|
-
context
|
44
|
-
it
|
43
|
+
context "if" do
|
44
|
+
it "without else" do
|
45
45
|
template = [
|
46
46
|
"{{#if condition}}",
|
47
47
|
" Show something",
|
@@ -51,7 +51,7 @@ describe Handlebars::Helpers::IfHelper do
|
|
51
51
|
expect(evaluate(template, {condition: false})).to eq("")
|
52
52
|
end
|
53
53
|
|
54
|
-
it
|
54
|
+
it "with an else" do
|
55
55
|
template = [
|
56
56
|
"{{#if condition}}",
|
57
57
|
" Show something",
|
@@ -63,7 +63,7 @@ describe Handlebars::Helpers::IfHelper do
|
|
63
63
|
expect(evaluate(template, {condition: false})).to eq("\n Do not show something\n")
|
64
64
|
end
|
65
65
|
|
66
|
-
it
|
66
|
+
it "imbricated ifs" do
|
67
67
|
template = [
|
68
68
|
"{{#if first_condition}}",
|
69
69
|
" {{#if second_condition}}",
|
@@ -1,12 +1,12 @@
|
|
1
|
-
require_relative
|
1
|
+
require_relative "../../spec_helper"
|
2
2
|
|
3
|
-
require_relative
|
4
|
-
require_relative
|
3
|
+
require_relative "../../../lib/ruby-handlebars"
|
4
|
+
require_relative "../../../lib/ruby-handlebars/helpers/register_default_helpers"
|
5
5
|
|
6
6
|
|
7
7
|
describe Handlebars::Helpers do
|
8
|
-
context
|
9
|
-
it
|
8
|
+
context ".register_default_helpers" do
|
9
|
+
it "registers the default helpers" do
|
10
10
|
hbs = double(Handlebars::Handlebars)
|
11
11
|
allow(hbs).to receive(:register_helper)
|
12
12
|
allow(hbs).to receive(:register_as_helper)
|
@@ -17,18 +17,18 @@ describe Handlebars::Helpers do
|
|
17
17
|
expect(hbs)
|
18
18
|
.to have_received(:register_helper)
|
19
19
|
.once
|
20
|
-
.with(
|
20
|
+
.with("if")
|
21
21
|
.once
|
22
|
-
.with(
|
22
|
+
.with("unless")
|
23
23
|
.once
|
24
|
-
.with(
|
24
|
+
.with("each")
|
25
25
|
.once
|
26
|
-
.with(
|
26
|
+
.with("helperMissing")
|
27
27
|
|
28
28
|
expect(hbs)
|
29
29
|
.to have_received(:register_as_helper)
|
30
30
|
.once
|
31
|
-
.with(
|
31
|
+
.with("each")
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|