flavour_saver 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +16 -0
- data/.travis.yml +11 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +81 -0
- data/Guardfile +12 -0
- data/LICENSE +22 -0
- data/README.md +339 -0
- data/Rakefile +2 -0
- data/flavour_saver.gemspec +28 -0
- data/lib/flavour_saver/helpers.rb +118 -0
- data/lib/flavour_saver/lexer.rb +127 -0
- data/lib/flavour_saver/nodes.rb +177 -0
- data/lib/flavour_saver/parser.rb +183 -0
- data/lib/flavour_saver/partial.rb +29 -0
- data/lib/flavour_saver/rails_partial.rb +10 -0
- data/lib/flavour_saver/runtime.rb +269 -0
- data/lib/flavour_saver/template.rb +19 -0
- data/lib/flavour_saver/version.rb +3 -0
- data/lib/flavour_saver.rb +78 -0
- data/spec/acceptance/backtrack_spec.rb +14 -0
- data/spec/acceptance/comment_spec.rb +12 -0
- data/spec/acceptance/custom_block_helper_spec.rb +35 -0
- data/spec/acceptance/custom_helper_spec.rb +15 -0
- data/spec/acceptance/ensure_no_rce_spec.rb +26 -0
- data/spec/acceptance/handlebars_qunit_spec.rb +911 -0
- data/spec/acceptance/if_else_spec.rb +17 -0
- data/spec/acceptance/multi_level_with_spec.rb +15 -0
- data/spec/acceptance/one_character_identifier_spec.rb +13 -0
- data/spec/acceptance/runtime_run_spec.rb +27 -0
- data/spec/acceptance/sections_spec.rb +25 -0
- data/spec/acceptance/segment_literals_spec.rb +26 -0
- data/spec/acceptance/simple_expression_spec.rb +13 -0
- data/spec/fixtures/backtrack.hbs +4 -0
- data/spec/fixtures/comment.hbs +1 -0
- data/spec/fixtures/custom_block_helper.hbs +3 -0
- data/spec/fixtures/custom_helper.hbs +1 -0
- data/spec/fixtures/if_else.hbs +5 -0
- data/spec/fixtures/multi_level_if.hbs +12 -0
- data/spec/fixtures/multi_level_with.hbs +11 -0
- data/spec/fixtures/one_character_identifier.hbs +1 -0
- data/spec/fixtures/sections.hbs +9 -0
- data/spec/fixtures/simple_expression.hbs +1 -0
- data/spec/lib/flavour_saver/lexer_spec.rb +187 -0
- data/spec/lib/flavour_saver/parser_spec.rb +277 -0
- data/spec/lib/flavour_saver/runtime_spec.rb +190 -0
- data/spec/lib/flavour_saver/template_spec.rb +5 -0
- metadata +243 -0
@@ -0,0 +1,190 @@
|
|
1
|
+
require 'flavour_saver'
|
2
|
+
|
3
|
+
describe FlavourSaver::Runtime do
|
4
|
+
let(:template) { '' }
|
5
|
+
let(:tokens) { FlavourSaver.lex(template) }
|
6
|
+
let(:ast) { FlavourSaver.parse(tokens) }
|
7
|
+
let(:context) { double(:context) }
|
8
|
+
subject { FlavourSaver::Runtime.new(ast, context) }
|
9
|
+
|
10
|
+
describe '#evaluate_node' do
|
11
|
+
describe 'when passed a TemplateNode' do
|
12
|
+
let(:template) { "hello world" }
|
13
|
+
|
14
|
+
it "concatenates all the nodes items together" do
|
15
|
+
subject.evaluate_node(ast).should == 'hello world'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe 'when passed an OutputNode' do
|
20
|
+
let(:template) { "hello world" }
|
21
|
+
|
22
|
+
it "returns the value of OutputNodes" do
|
23
|
+
node = ast.items.first
|
24
|
+
subject.evaluate_node(node).should == 'hello world'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe 'when passed a StringNode' do
|
29
|
+
let(:template) { "{{foo \"WAT\"}}" }
|
30
|
+
let(:node) { ast.items.select { |n| n.class == FlavourSaver::ExpressionNode }.first.method.first.arguments.first }
|
31
|
+
|
32
|
+
it 'returns the value of the string' do
|
33
|
+
subject.evaluate_node(node).should == 'WAT'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe 'when passed an ExpressionNode' do
|
38
|
+
let(:node) { ast.items.select { |n| n.class == FlavourSaver::ExpressionNode }.first }
|
39
|
+
let (:template) { "{{foo}}" }
|
40
|
+
|
41
|
+
it 'calls evaluate_node with the node' do
|
42
|
+
subject.should_receive(:evaluate_expression).with(node)
|
43
|
+
subject.evaluate_node(node)
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should HTML escape the output' do
|
47
|
+
context.should_receive(:foo).and_return("<html>LOL</html>")
|
48
|
+
subject.evaluate_node(node).should == '<html>LOL</html>'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe 'when passed a SafeExpressionNode' do
|
53
|
+
let(:node) { ast.items.select { |n| n.class == FlavourSaver::SafeExpressionNode }.first }
|
54
|
+
let (:template) { "{{{foo}}}" }
|
55
|
+
|
56
|
+
it 'should not HTML escape the output' do
|
57
|
+
context.should_receive(:foo).and_return("<html>LOL</html>")
|
58
|
+
subject.evaluate_node(node).should == '<html>LOL</html>'
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe 'when passed a CommentNode' do
|
63
|
+
let(:template) { "{{! I am a comment}}" }
|
64
|
+
let(:node) { ast.items.select { |n| n.class == FlavourSaver::CommentNode }.first }
|
65
|
+
|
66
|
+
it 'should return zilch' do
|
67
|
+
subject.evaluate_node(node).should == ''
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe 'when passed a BlockExpressionStartNode' do
|
72
|
+
let(:template) { "{{#foo}}bar{{/foo}}baz" }
|
73
|
+
|
74
|
+
it 'snatches up the block contents and skips them from evaluation' do
|
75
|
+
context.stub(:foo)
|
76
|
+
subject.evaluate_node(ast).should == 'baz'
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe '#evaluate_expression' do
|
82
|
+
let(:node) { ast.items.select { |n| n.class == FlavourSaver::ExpressionNode }.first }
|
83
|
+
let(:expr) { node }
|
84
|
+
|
85
|
+
describe 'when called with a simple method expression' do
|
86
|
+
let (:template) { "{{foo}}" }
|
87
|
+
|
88
|
+
it 'calls the method and return the result' do
|
89
|
+
context.should_receive(:foo).and_return('foo result')
|
90
|
+
subject.evaluate_expression(expr).should == 'foo result'
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe 'when called with a simple method with arguments' do
|
95
|
+
let(:template) { "{{hello \"world\"}}" }
|
96
|
+
|
97
|
+
it 'calls the method with the arguments and return the result' do
|
98
|
+
context.should_receive(:hello).with("world").and_return("hello world")
|
99
|
+
subject.evaluate_expression(expr).should == 'hello world'
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
describe 'when called with a simple method with another simple method argument' do
|
104
|
+
let(:template) { "{{hello world}}" }
|
105
|
+
|
106
|
+
it 'calls hello & world on the context and return the result' do
|
107
|
+
context.should_receive(:world).and_return('world')
|
108
|
+
context.should_receive(:hello).with('world').and_return('hello world')
|
109
|
+
subject.evaluate_expression(expr).should == 'hello world'
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
describe 'when called with an object path' do
|
114
|
+
let(:template) { "{{hello.world}}" }
|
115
|
+
|
116
|
+
it 'calls world on the result of hello' do
|
117
|
+
context.stub_chain(:hello, :world).and_return('hello world')
|
118
|
+
subject.evaluate_expression(expr).should == 'hello world'
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
describe 'when called with a literal' do
|
123
|
+
let(:template) { "{{[WAT]}}" }
|
124
|
+
|
125
|
+
it 'indexes the context with WAT' do
|
126
|
+
context.should_receive(:[]).with('WAT').and_return 'w00t'
|
127
|
+
subject.evaluate_expression(expr).should == 'w00t'
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
describe 'when called with an object path containing a literal' do
|
132
|
+
let (:template) { "{{hello.[WAT].world}}" }
|
133
|
+
|
134
|
+
it 'indexes the result of hello and calls world on it' do
|
135
|
+
world = double(:world)
|
136
|
+
world.should_receive(:world).and_return('vr00m')
|
137
|
+
hash = double(:hash)
|
138
|
+
hash.should_receive(:[]).with('WAT').and_return(world)
|
139
|
+
context.should_receive(:hello).and_return(hash)
|
140
|
+
subject.evaluate_expression(expr).should == 'vr00m'
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
describe 'when called with a parent call node without a surrounding block' do
|
145
|
+
let (:template) { "{{../foo}}" }
|
146
|
+
|
147
|
+
it 'raises an error' do
|
148
|
+
-> { subject.evaluate_expression(expr) }.should raise_error(FlavourSaver::UnknownContextException)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
describe 'when called with a hash argument containing a string value' do
|
153
|
+
let (:template) { '{{foo bar="baz"}}' }
|
154
|
+
|
155
|
+
it 'receives the argument as a hash' do
|
156
|
+
context.should_receive(:foo).with({:bar => 'baz'})
|
157
|
+
subject.evaluate_expression(expr)
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
describe 'when called with a hash argument containing a method reference' do
|
162
|
+
let (:template) { "{{foo bar=baz}}" }
|
163
|
+
|
164
|
+
it 'calls the value and returns it\'s result in the hash' do
|
165
|
+
context.should_receive(:baz).and_return('OMGLOLWAT')
|
166
|
+
context.should_receive(:foo).with({:bar => 'OMGLOLWAT'})
|
167
|
+
subject.evaluate_expression(expr)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
end
|
172
|
+
|
173
|
+
describe '#evaluate_block' do
|
174
|
+
let(:template) { "{{#foo}}hello world{{/foo}}" }
|
175
|
+
let(:block) { ast.items.first }
|
176
|
+
|
177
|
+
it 'creates a new runtime' do
|
178
|
+
subject.should_receive(:create_child_runtime)
|
179
|
+
context.stub(:foo)
|
180
|
+
subject.evaluate_block(block, context)
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
describe '#create_child_runtime' do
|
185
|
+
it 'creates a new runtime' do
|
186
|
+
subject.create_child_runtime([]).should be_a(FlavourSaver::Runtime)
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
end
|
metadata
ADDED
@@ -0,0 +1,243 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: flavour_saver
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- James Harton
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-09-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: guard-rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec-core
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec-mocks
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec-expectations
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: guard-bundler
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: activesupport
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rltk
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ~>
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 2.2.0
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ~>
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 2.2.0
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: tilt
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
description: FlavourSaver is a pure-ruby implimentation of the Handlebars templating
|
140
|
+
language
|
141
|
+
email:
|
142
|
+
- james@resistor.io
|
143
|
+
executables: []
|
144
|
+
extensions: []
|
145
|
+
extra_rdoc_files: []
|
146
|
+
files:
|
147
|
+
- .gitignore
|
148
|
+
- .travis.yml
|
149
|
+
- Gemfile
|
150
|
+
- Gemfile.lock
|
151
|
+
- Guardfile
|
152
|
+
- LICENSE
|
153
|
+
- README.md
|
154
|
+
- Rakefile
|
155
|
+
- flavour_saver.gemspec
|
156
|
+
- lib/flavour_saver.rb
|
157
|
+
- lib/flavour_saver/helpers.rb
|
158
|
+
- lib/flavour_saver/lexer.rb
|
159
|
+
- lib/flavour_saver/nodes.rb
|
160
|
+
- lib/flavour_saver/parser.rb
|
161
|
+
- lib/flavour_saver/partial.rb
|
162
|
+
- lib/flavour_saver/rails_partial.rb
|
163
|
+
- lib/flavour_saver/runtime.rb
|
164
|
+
- lib/flavour_saver/template.rb
|
165
|
+
- lib/flavour_saver/version.rb
|
166
|
+
- spec/acceptance/backtrack_spec.rb
|
167
|
+
- spec/acceptance/comment_spec.rb
|
168
|
+
- spec/acceptance/custom_block_helper_spec.rb
|
169
|
+
- spec/acceptance/custom_helper_spec.rb
|
170
|
+
- spec/acceptance/ensure_no_rce_spec.rb
|
171
|
+
- spec/acceptance/handlebars_qunit_spec.rb
|
172
|
+
- spec/acceptance/if_else_spec.rb
|
173
|
+
- spec/acceptance/multi_level_with_spec.rb
|
174
|
+
- spec/acceptance/one_character_identifier_spec.rb
|
175
|
+
- spec/acceptance/runtime_run_spec.rb
|
176
|
+
- spec/acceptance/sections_spec.rb
|
177
|
+
- spec/acceptance/segment_literals_spec.rb
|
178
|
+
- spec/acceptance/simple_expression_spec.rb
|
179
|
+
- spec/fixtures/backtrack.hbs
|
180
|
+
- spec/fixtures/comment.hbs
|
181
|
+
- spec/fixtures/custom_block_helper.hbs
|
182
|
+
- spec/fixtures/custom_helper.hbs
|
183
|
+
- spec/fixtures/if_else.hbs
|
184
|
+
- spec/fixtures/multi_level_if.hbs
|
185
|
+
- spec/fixtures/multi_level_with.hbs
|
186
|
+
- spec/fixtures/one_character_identifier.hbs
|
187
|
+
- spec/fixtures/sections.hbs
|
188
|
+
- spec/fixtures/simple_expression.hbs
|
189
|
+
- spec/lib/flavour_saver/lexer_spec.rb
|
190
|
+
- spec/lib/flavour_saver/parser_spec.rb
|
191
|
+
- spec/lib/flavour_saver/runtime_spec.rb
|
192
|
+
- spec/lib/flavour_saver/template_spec.rb
|
193
|
+
homepage: http://jamesotron.github.com/FlavourSaver/
|
194
|
+
licenses: []
|
195
|
+
metadata: {}
|
196
|
+
post_install_message:
|
197
|
+
rdoc_options: []
|
198
|
+
require_paths:
|
199
|
+
- lib
|
200
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
201
|
+
requirements:
|
202
|
+
- - '>='
|
203
|
+
- !ruby/object:Gem::Version
|
204
|
+
version: '0'
|
205
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
206
|
+
requirements:
|
207
|
+
- - '>='
|
208
|
+
- !ruby/object:Gem::Version
|
209
|
+
version: '0'
|
210
|
+
requirements: []
|
211
|
+
rubyforge_project:
|
212
|
+
rubygems_version: 2.2.2
|
213
|
+
signing_key:
|
214
|
+
specification_version: 4
|
215
|
+
summary: Handlebars.js without the .js
|
216
|
+
test_files:
|
217
|
+
- spec/acceptance/backtrack_spec.rb
|
218
|
+
- spec/acceptance/comment_spec.rb
|
219
|
+
- spec/acceptance/custom_block_helper_spec.rb
|
220
|
+
- spec/acceptance/custom_helper_spec.rb
|
221
|
+
- spec/acceptance/ensure_no_rce_spec.rb
|
222
|
+
- spec/acceptance/handlebars_qunit_spec.rb
|
223
|
+
- spec/acceptance/if_else_spec.rb
|
224
|
+
- spec/acceptance/multi_level_with_spec.rb
|
225
|
+
- spec/acceptance/one_character_identifier_spec.rb
|
226
|
+
- spec/acceptance/runtime_run_spec.rb
|
227
|
+
- spec/acceptance/sections_spec.rb
|
228
|
+
- spec/acceptance/segment_literals_spec.rb
|
229
|
+
- spec/acceptance/simple_expression_spec.rb
|
230
|
+
- spec/fixtures/backtrack.hbs
|
231
|
+
- spec/fixtures/comment.hbs
|
232
|
+
- spec/fixtures/custom_block_helper.hbs
|
233
|
+
- spec/fixtures/custom_helper.hbs
|
234
|
+
- spec/fixtures/if_else.hbs
|
235
|
+
- spec/fixtures/multi_level_if.hbs
|
236
|
+
- spec/fixtures/multi_level_with.hbs
|
237
|
+
- spec/fixtures/one_character_identifier.hbs
|
238
|
+
- spec/fixtures/sections.hbs
|
239
|
+
- spec/fixtures/simple_expression.hbs
|
240
|
+
- spec/lib/flavour_saver/lexer_spec.rb
|
241
|
+
- spec/lib/flavour_saver/parser_spec.rb
|
242
|
+
- spec/lib/flavour_saver/runtime_spec.rb
|
243
|
+
- spec/lib/flavour_saver/template_spec.rb
|