curlybars 1.8.0 → 1.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/lib/curlybars/error/lex.rb +1 -1
  3. data/lib/curlybars/error/parse.rb +1 -1
  4. data/lib/curlybars/node/path.rb +11 -13
  5. data/lib/curlybars/presenter.rb +2 -2
  6. data/lib/curlybars/rendering_support.rb +2 -1
  7. data/lib/curlybars/template_handler.rb +3 -15
  8. data/lib/curlybars/version.rb +1 -1
  9. metadata +32 -108
  10. data/spec/acceptance/application_layout_spec.rb +0 -60
  11. data/spec/acceptance/collection_blocks_spec.rb +0 -28
  12. data/spec/acceptance/global_helper_spec.rb +0 -25
  13. data/spec/curlybars/configuration_spec.rb +0 -57
  14. data/spec/curlybars/error/base_spec.rb +0 -41
  15. data/spec/curlybars/error/compile_spec.rb +0 -19
  16. data/spec/curlybars/error/lex_spec.rb +0 -25
  17. data/spec/curlybars/error/parse_spec.rb +0 -74
  18. data/spec/curlybars/error/render_spec.rb +0 -19
  19. data/spec/curlybars/error/validate_spec.rb +0 -19
  20. data/spec/curlybars/lexer_spec.rb +0 -490
  21. data/spec/curlybars/method_whitelist_spec.rb +0 -299
  22. data/spec/curlybars/processor/tilde_spec.rb +0 -60
  23. data/spec/curlybars/rendering_support_spec.rb +0 -421
  24. data/spec/curlybars/safe_buffer_spec.rb +0 -46
  25. data/spec/curlybars/template_handler_spec.rb +0 -225
  26. data/spec/integration/cache_spec.rb +0 -126
  27. data/spec/integration/comment_spec.rb +0 -60
  28. data/spec/integration/exception_spec.rb +0 -31
  29. data/spec/integration/node/block_helper_else_spec.rb +0 -420
  30. data/spec/integration/node/each_else_spec.rb +0 -408
  31. data/spec/integration/node/each_spec.rb +0 -289
  32. data/spec/integration/node/escape_spec.rb +0 -27
  33. data/spec/integration/node/helper_spec.rb +0 -186
  34. data/spec/integration/node/if_else_spec.rb +0 -170
  35. data/spec/integration/node/if_spec.rb +0 -153
  36. data/spec/integration/node/output_spec.rb +0 -66
  37. data/spec/integration/node/partial_spec.rb +0 -64
  38. data/spec/integration/node/path_spec.rb +0 -296
  39. data/spec/integration/node/root_spec.rb +0 -13
  40. data/spec/integration/node/sub_expression_spec.rb +0 -426
  41. data/spec/integration/node/template_spec.rb +0 -84
  42. data/spec/integration/node/unless_else_spec.rb +0 -139
  43. data/spec/integration/node/unless_spec.rb +0 -128
  44. data/spec/integration/node/with_spec.rb +0 -178
  45. data/spec/integration/processor/tilde_spec.rb +0 -38
  46. data/spec/integration/processors_spec.rb +0 -29
  47. data/spec/integration/visitor_spec.rb +0 -154
@@ -1,186 +0,0 @@
1
- describe "{{helper context key=value}}" 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 "passes two arguments" do
9
- template = Curlybars.compile(<<-HBS)
10
- {{print_args_and_options 'first' 'second'}}
11
- HBS
12
-
13
- expect(eval(template)).to resemble(<<-HTML)
14
- first, second, key=
15
- HTML
16
- end
17
-
18
- it "calls a helper without arguments in an if statement" do
19
- template = Curlybars.compile(<<-HBS)
20
- {{#if print_args_and_options}}
21
- {{print_args_and_options 'first' 'second'}}
22
- {{/if}}
23
- HBS
24
-
25
- expect(eval(template)).to resemble(<<-HTML)
26
- first, second, key=
27
- HTML
28
- end
29
-
30
- it "passes two arguments and options" do
31
- template = Curlybars.compile(<<-HBS)
32
- {{print_args_and_options 'first' 'second' key='value'}}
33
- HBS
34
-
35
- expect(eval(template)).to resemble(<<-HTML)
36
- first, second, key=value
37
- HTML
38
- end
39
-
40
- it "renders a helper with expression and options" do
41
- template = Curlybars.compile(<<-HBS)
42
- {{date user.created_at class='metadata'}}
43
- HBS
44
-
45
- expect(eval(template)).to resemble(<<-HTML)
46
- <time datetime="2015-02-03T13:25:06Z" class="metadata">
47
- February 3, 2015 13:25
48
- </time>
49
- HTML
50
- end
51
-
52
- it "renders a helper with only expression" do
53
- template = Curlybars.compile(<<-HBS)
54
- <script src="{{asset "jquery_plugin.js"}}"></script>
55
- HBS
56
-
57
- expect(eval(template)).to resemble(<<-HTML)
58
- <script src="http://cdn.example.com/jquery_plugin.js"></script>
59
- HTML
60
- end
61
-
62
- it "renders a helper with only options" do
63
- template = Curlybars.compile(<<-HBS)
64
- {{#with new_comment_form}}
65
- {{input title class="form-control"}}
66
- {{/with}}
67
- HBS
68
-
69
- expect(eval(template)).to resemble(<<-HTML)
70
- <input name="community_post[title]"
71
- id="community_post_title"
72
- type="text"
73
- class="form-control"
74
- value="some value persisted in the DB">
75
- HTML
76
- end
77
-
78
- it "renders correctly a return type of integer" do
79
- template = Curlybars.compile(<<-HBS)
80
- {{integer 'ignored'}}
81
- HBS
82
-
83
- expect(eval(template)).to resemble(<<-HTML)
84
- 0
85
- HTML
86
- end
87
-
88
- it "renders correctly a return type of boolean" do
89
- template = Curlybars.compile(<<-HBS)
90
- {{boolean 'ignored'}}
91
- HBS
92
-
93
- expect(eval(template)).to resemble(<<-HTML)
94
- true
95
- HTML
96
- end
97
-
98
- it "handles correctly a method that invokes `yield`, returning empty string" do
99
- template = Curlybars.compile(<<-HBS)
100
- {{this_method_yields}}
101
- HBS
102
-
103
- expect(eval(template)).to resemble("")
104
- end
105
-
106
- it "doesn't render if the path returns a presenter" do
107
- template = Curlybars.compile(<<-HBS)
108
- {{user}}
109
- HBS
110
-
111
- expect(eval(template)).to resemble("")
112
- end
113
-
114
- it "doesn't render if the path returns a collection of presenters" do
115
- template = Curlybars.compile(<<-HBS)
116
- {{array_of_users}}
117
- HBS
118
-
119
- expect(eval(template)).to resemble("")
120
- end
121
- end
122
-
123
- describe "#validate" do
124
- it "with errors" do
125
- dependency_tree = {}
126
-
127
- source = <<-HBS
128
- {{helper}}
129
- HBS
130
-
131
- errors = Curlybars.validate(dependency_tree, source)
132
-
133
- expect(errors).not_to be_empty
134
- end
135
-
136
- it "raises when using a partial as an helper" do
137
- dependency_tree = { partial: :partial }
138
-
139
- source = <<-HBS
140
- {{partial}}
141
- HBS
142
-
143
- errors = Curlybars.validate(dependency_tree, source)
144
-
145
- expect(errors).not_to be_empty
146
- end
147
-
148
- it "without errors" do
149
- dependency_tree = { helper: :helper }
150
-
151
- source = <<-HBS
152
- {{helper}}
153
- HBS
154
-
155
- errors = Curlybars.validate(dependency_tree, source)
156
-
157
- expect(errors).to be_empty
158
- end
159
-
160
- it "validates {{helper.invoked_on_nil}} with errors" do
161
- dependency_tree = { helper: :helper }
162
-
163
- source = <<-HBS
164
- {{helper.invoked_on_nil}}
165
- HBS
166
-
167
- errors = Curlybars.validate(dependency_tree, source)
168
-
169
- expect(errors).not_to be_empty
170
- end
171
-
172
- describe "with context" do
173
- it "without errors in block_helper" do
174
- dependency_tree = { helper: :helper, context: nil }
175
-
176
- source = <<-HBS
177
- {{helper context}}
178
- HBS
179
-
180
- errors = Curlybars.validate(dependency_tree, source)
181
-
182
- expect(errors).to be_empty
183
- end
184
- end
185
- end
186
- end
@@ -1,170 +0,0 @@
1
- describe "{{#if}}...{{else}}...{{/if}}" 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 "renders the if_template" do
9
- allow(IntegrationTest::Presenter).to receive(:allows_method?).with(:return_true).and_return(true)
10
- allow(presenter).to receive(:return_true).and_return(true)
11
-
12
- template = Curlybars.compile(<<-HBS)
13
- {{#if return_true}}
14
- if_template
15
- {{else}}
16
- else_template
17
- {{/if}}
18
- HBS
19
-
20
- expect(eval(template)).to resemble(<<-HTML)
21
- if_template
22
- HTML
23
- end
24
-
25
- it "renders the else_template" do
26
- allow(IntegrationTest::Presenter).to receive(:allows_method?).with(:return_false).and_return(true)
27
- allow(presenter).to receive(:return_false).and_return(false)
28
-
29
- template = Curlybars.compile(<<-HBS)
30
- {{#if return_false}}
31
- if_template
32
- {{else}}
33
- else_template
34
- {{/if}}
35
- HBS
36
-
37
- expect(eval(template)).to resemble(<<-HTML)
38
- else_template
39
- HTML
40
- end
41
-
42
- it "allows empty if_template" do
43
- allow(IntegrationTest::Presenter).to receive(:allows_method?).with(:valid).and_return(true)
44
- allow(presenter).to receive(:valid).and_return(false)
45
-
46
- template = Curlybars.compile(<<-HBS)
47
- {{#if valid}}{{else}}
48
- else_template
49
- {{/if}}
50
- HBS
51
-
52
- expect(eval(template)).to resemble(<<-HTML)
53
- else_template
54
- HTML
55
- end
56
-
57
- it "allows empty else_template" do
58
- allow(IntegrationTest::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
- {{#if valid}}
63
- if_template
64
- {{else}}{{/if}}
65
- HBS
66
-
67
- expect(eval(template)).to resemble(<<-HTML)
68
- if_template
69
- HTML
70
- end
71
-
72
- it "allows empty if_template and else_template" do
73
- allow(IntegrationTest::Presenter).to receive(:allows_method?).with(:valid).and_return(true)
74
- allow(presenter).to receive(:valid).and_return(true)
75
-
76
- template = Curlybars.compile(<<-HBS)
77
- {{#if valid}}{{else}}{{/if}}
78
- HBS
79
-
80
- expect(eval(template)).to resemble("")
81
- end
82
- end
83
-
84
- describe "#validate" do
85
- it "validates without errors the literal condition" do
86
- dependency_tree = {}
87
-
88
- source = <<-HBS
89
- {{#if 42}}{{else}}{{/if}}
90
- HBS
91
-
92
- errors = Curlybars.validate(dependency_tree, source)
93
-
94
- expect(errors).to be_empty
95
- end
96
-
97
- it "validates with errors the condition" do
98
- dependency_tree = {}
99
-
100
- source = <<-HBS
101
- {{#if condition}}{{else}}{{/if}}
102
- HBS
103
-
104
- errors = Curlybars.validate(dependency_tree, source)
105
-
106
- expect(errors).not_to be_empty
107
- end
108
-
109
- it "validates with errors the nested if_template" do
110
- dependency_tree = { condition: nil }
111
-
112
- source = <<-HBS
113
- {{#if condition}}
114
- {{unallowed_method}}
115
- {{else}}
116
- {{/if}}
117
- HBS
118
-
119
- errors = Curlybars.validate(dependency_tree, source)
120
-
121
- expect(errors).not_to be_empty
122
- end
123
-
124
- it "validates with errors the nested else_template" do
125
- dependency_tree = { condition: nil }
126
-
127
- source = <<-HBS
128
- {{#if condition}}
129
- {{else}}
130
- {{unallowed_method}}
131
- {{/if}}
132
- HBS
133
-
134
- errors = Curlybars.validate(dependency_tree, source)
135
-
136
- expect(errors).not_to be_empty
137
- end
138
-
139
- it "validates errors the nested else_template when out of context" do
140
- dependency_tree = { condition: nil }
141
-
142
- source = <<-HBS
143
- {{#if ../condition}}
144
- {{else}}
145
- {{unallowed_ELSE_method}}
146
- {{/if}}
147
- HBS
148
-
149
- errors = Curlybars.validate(dependency_tree, source)
150
-
151
- expect(errors.count).to eq(2)
152
- end
153
-
154
- it "gives all possible errors found in validation" do
155
- dependency_tree = { condition: nil }
156
-
157
- source = <<-HBS
158
- {{#if ../condition}}
159
- {{unallowed_IF_method}}
160
- {{else}}
161
- {{unallowed_ELSE_method}}
162
- {{/if}}
163
- HBS
164
-
165
- errors = Curlybars.validate(dependency_tree, source)
166
-
167
- expect(errors.count).to eq(3)
168
- end
169
- end
170
- end
@@ -1,153 +0,0 @@
1
- describe "{{#if}}...{{/if}}" 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 positive branch when condition is true" do
9
- allow(presenter).to receive(:allows_method?).with(:valid).and_return(true)
10
- allow(presenter).to receive(:valid).and_return(true)
11
-
12
- template = Curlybars.compile(<<-HBS)
13
- {{#if valid}}
14
- if_template
15
- {{/if}}
16
- HBS
17
-
18
- expect(eval(template)).to resemble(<<-HTML)
19
- if_template
20
- HTML
21
- end
22
-
23
- it "doesn't return positive branch when condition is false" do
24
- allow(presenter).to receive(:allows_method?).with(:valid).and_return(true)
25
- allow(presenter).to receive(:valid).and_return(false)
26
-
27
- template = Curlybars.compile(<<-HBS)
28
- {{#if valid}}
29
- if_template
30
- {{/if}}
31
- HBS
32
-
33
- expect(eval(template)).to resemble("")
34
- end
35
-
36
- it "doesn't return positive branch when condition is empty array" do
37
- allow(presenter).to receive(:allows_method?).with(:collection).and_return(true)
38
- allow(presenter).to receive(:collection).and_return([])
39
-
40
- template = Curlybars.compile(<<-HBS)
41
- {{#if collection}}
42
- if_template
43
- {{/if}}
44
- HBS
45
-
46
- expect(eval(template)).to resemble("")
47
- end
48
-
49
- it "works with nested `if blocks` (double positive)" do
50
- allow(presenter).to receive(:allows_method?).with(:valid).and_return(true)
51
- allow(presenter).to receive(:allows_method?).with(:visible).and_return(true)
52
- allow(presenter).to receive(:valid).and_return(true)
53
- allow(presenter).to receive(:visible).and_return(true)
54
-
55
- template = Curlybars.compile(<<-HBS)
56
- {{#if valid}}
57
- {{#if visible}}
58
- inner_if_template
59
- {{/if}}
60
- outer_if_template
61
- {{/if}}
62
- HBS
63
-
64
- expect(eval(template)).to resemble(<<-HTML)
65
- inner_if_template
66
- outer_if_template
67
- HTML
68
- end
69
-
70
- it "works with nested `if blocks` (positive and negative)" do
71
- allow(presenter).to receive(:allows_method?).with(:valid).and_return(true)
72
- allow(presenter).to receive(:allows_method?).with(:visible).and_return(true)
73
- allow(presenter).to receive(:valid).and_return(true)
74
- allow(presenter).to receive(:visible).and_return(false)
75
-
76
- template = Curlybars.compile(<<-HBS)
77
- {{#if valid}}
78
- {{#if visible}}
79
- inner_if_template
80
- {{/if}}
81
- outer_if_template
82
- {{/if}}
83
- HBS
84
-
85
- expect(eval(template)).to resemble(<<-HTML)
86
- outer_if_template
87
- HTML
88
- end
89
-
90
- it "allows empty if_template" do
91
- allow(presenter).to receive(:allows_method?).with(:valid).and_return(true)
92
- allow(presenter).to receive(:valid).and_return(true)
93
-
94
- template = Curlybars.compile(<<-HBS)
95
- {{#if valid}}{{/if}}
96
- HBS
97
-
98
- expect(eval(template)).to resemble("")
99
- end
100
-
101
- it "allows usage of variables in condition" do
102
- template = Curlybars.compile(<<-HBS)
103
- {{#each two_elements}}
104
- {{#if @first}}I am the first!{{/if}}
105
- {{/each}}
106
- HBS
107
-
108
- expect(eval(template)).to resemble(<<-HTML)
109
- I am the first!
110
- HTML
111
- end
112
- end
113
-
114
- describe "#validate" do
115
- it "validates with errors the condition" do
116
- dependency_tree = {}
117
-
118
- source = <<-HBS
119
- {{#if condition}}{{/if}}
120
- HBS
121
-
122
- errors = Curlybars.validate(dependency_tree, source)
123
-
124
- expect(errors).not_to be_empty
125
- end
126
-
127
- it "validates with errors the nested template" do
128
- dependency_tree = { condition: nil }
129
-
130
- source = <<-HBS
131
- {{#if condition}}
132
- {{unallowed_method}}
133
- {{/if}}
134
- HBS
135
-
136
- errors = Curlybars.validate(dependency_tree, source)
137
-
138
- expect(errors).not_to be_empty
139
- end
140
-
141
- it "validates without errors the helper as condition" do
142
- dependency_tree = { helper: :helper }
143
-
144
- source = <<-HBS
145
- {{#if helper}}{{/if}}
146
- HBS
147
-
148
- errors = Curlybars.validate(dependency_tree, source)
149
-
150
- expect(errors).to be_empty
151
- end
152
- end
153
- end
@@ -1,66 +0,0 @@
1
- describe '{{value}}' 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 "prints out a string" do
9
- template = Curlybars.compile(<<-HBS)
10
- {{'hello world!'}}
11
- HBS
12
-
13
- expect(eval(template)).to resemble('hello world!')
14
- end
15
-
16
- it "prints out a boolean" do
17
- template = Curlybars.compile(<<-HBS)
18
- {{true}}
19
- HBS
20
-
21
- expect(eval(template)).to resemble('true')
22
- end
23
-
24
- it "prints out an integer" do
25
- template = Curlybars.compile(<<-HBS)
26
- {{7}}
27
- HBS
28
-
29
- expect(eval(template)).to resemble('7')
30
- end
31
-
32
- it "prints out a variable" do
33
- template = Curlybars.compile(<<-HBS)
34
- {{#each two_elements}}
35
- Index: {{@index}}
36
- First: {{@first}}
37
- Last: {{@last}}
38
- {{/each}}
39
- HBS
40
-
41
- expect(eval(template)).to resemble(<<-HTML)
42
- Index: 0
43
- First: true
44
- Last: false
45
-
46
- Index: 1
47
- First: false
48
- Last: true
49
- HTML
50
- end
51
- end
52
-
53
- describe "#validate" do
54
- it "validates the path with errors" do
55
- dependency_tree = {}
56
-
57
- source = <<-HBS
58
- {{unallowed_path}}
59
- HBS
60
-
61
- errors = Curlybars.validate(dependency_tree, source)
62
-
63
- expect(errors).not_to be_empty
64
- end
65
- end
66
- end
@@ -1,64 +0,0 @@
1
- describe "{{> partial}}" 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 "evaluates the methods chain call" do
9
- template = Curlybars.compile(<<-HBS)
10
- {{> partial}}
11
- HBS
12
-
13
- expect(eval(template)).to resemble(<<-HTML)
14
- partial
15
- HTML
16
- end
17
-
18
- it "renders nothing when the partial returns `nil`" do
19
- template = Curlybars.compile(<<-HBS)
20
- {{> return_nil}}
21
- HBS
22
-
23
- expect(eval(template)).to resemble("")
24
- end
25
- end
26
-
27
- describe "#validate" do
28
- it "validates the path with errors" do
29
- dependency_tree = {}
30
-
31
- source = <<-HBS
32
- {{> unallowed_partial}}
33
- HBS
34
-
35
- errors = Curlybars.validate(dependency_tree, source)
36
-
37
- expect(errors).not_to be_empty
38
- end
39
-
40
- it "raises when using a helper as a partial" do
41
- dependency_tree = { helper: nil }
42
-
43
- source = <<-HBS
44
- {{> helper}}
45
- HBS
46
-
47
- errors = Curlybars.validate(dependency_tree, source)
48
-
49
- expect(errors).not_to be_empty
50
- end
51
-
52
- it "does not raise with a valid partial" do
53
- dependency_tree = { partial: :partial }
54
-
55
- source = <<-HBS
56
- {{> partial}}
57
- HBS
58
-
59
- errors = Curlybars.validate(dependency_tree, source)
60
-
61
- expect(errors).to be_empty
62
- end
63
- end
64
- end