flavour_saver 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9d12597ba5058729046ad752a861932197e839cf
4
- data.tar.gz: e1975090088071c306eff750d6f45b9155bf0cce
3
+ metadata.gz: 708bf93bee827c63e9ea791c7ec51131835623e3
4
+ data.tar.gz: 2c7acc4e4d901efc04e53c0b4633765f482a7b58
5
5
  SHA512:
6
- metadata.gz: d09d2f9c685d5fb79c1e86df08d01865f4b108551c67e45e754dae94483f8f739e133cf744ba0d0d9548e9365e83f579b47bad21043927b80694bba36cc6e493
7
- data.tar.gz: 97dc6cd9a74bca558a20f0cca63ff552e7fc0a69a9a94ea38dedbc21c74e4b25c5433f288823e74db8ac69b5e36a6b9607ee9f4493347f66e909cce99eb6d37e
6
+ metadata.gz: 5937a5b5728312a8396a5915a3c83888660ab90f988b5c4bbb60e2657134bda14d05cbe298c8066050c160bcedcc36a68d11e5b8f35edb9176972249c70d493d
7
+ data.tar.gz: 5d3c50a7690aa653425abd793a922735274775b87ea15ca130f32ef7cc3e5364acfd7bbf8e253bc59e51ddc50dbcef09097a7bf56a2bbfb86776c9ec9180df21
data/.travis.yml CHANGED
@@ -2,6 +2,7 @@ language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
4
  - 2.0.0
5
+ - 2.1.5
5
6
  - jruby-19mode
6
7
  - rbx-19mode
7
8
  script: 'bundle exec rspec'
data/Gemfile.lock CHANGED
@@ -1,20 +1,19 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- flavour_saver (0.3.3)
4
+ flavour_saver (0.3.4)
5
5
  rltk (~> 2.2.0)
6
6
  tilt
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activesupport (4.0.0)
12
- i18n (~> 0.6, >= 0.6.4)
11
+ activesupport (4.0.13)
12
+ i18n (~> 0.6, >= 0.6.9)
13
13
  minitest (~> 4.2)
14
14
  multi_json (~> 1.3)
15
15
  thread_safe (~> 0.1)
16
16
  tzinfo (~> 0.3.37)
17
- atomic (1.1.14)
18
17
  coderay (1.0.9)
19
18
  diff-lcs (1.2.4)
20
19
  ffi (1.9.0)
@@ -31,7 +30,7 @@ GEM
31
30
  guard-rspec (3.1.0)
32
31
  guard (>= 1.8)
33
32
  rspec (~> 2.13)
34
- i18n (0.6.5)
33
+ i18n (0.7.0)
35
34
  listen (1.3.1)
36
35
  rb-fsevent (>= 0.9.3)
37
36
  rb-inotify (>= 0.9)
@@ -39,7 +38,7 @@ GEM
39
38
  lumberjack (1.0.4)
40
39
  method_source (0.8.2)
41
40
  minitest (4.7.5)
42
- multi_json (1.8.0)
41
+ multi_json (1.10.1)
43
42
  pry (0.9.12.2)
44
43
  coderay (~> 1.0.5)
45
44
  method_source (~> 0.8)
@@ -62,16 +61,15 @@ GEM
62
61
  rspec-mocks (2.14.3)
63
62
  slop (3.4.6)
64
63
  thor (0.18.1)
65
- thread_safe (0.1.3)
66
- atomic
67
- tilt (1.4.1)
68
- tzinfo (0.3.37)
64
+ thread_safe (0.3.4)
65
+ tilt (2.0.1)
66
+ tzinfo (0.3.42)
69
67
 
70
68
  PLATFORMS
71
69
  ruby
72
70
 
73
71
  DEPENDENCIES
74
- activesupport
72
+ activesupport (~> 4.0.2)
75
73
  flavour_saver!
76
74
  guard-bundler
77
75
  guard-rspec
@@ -21,7 +21,7 @@ Gem::Specification.new do |gem|
21
21
  gem.add_development_dependency 'rspec-mocks'
22
22
  gem.add_development_dependency 'rspec-expectations'
23
23
  gem.add_development_dependency 'guard-bundler'
24
- gem.add_development_dependency 'activesupport'
24
+ gem.add_development_dependency 'activesupport', '~> 4.0.2'
25
25
 
26
26
  gem.add_dependency 'rltk', '~> 2.2.0'
27
27
  gem.add_dependency 'tilt'
@@ -72,7 +72,7 @@ module FlavourSaver
72
72
 
73
73
  def method_missing(name,*args,&b)
74
74
  # I would rather have it raise a NameError, but Moustache
75
- # compatibility requires that missing helpers return
75
+ # compatibility requires that missing helpers return
76
76
  # nothing. A good place for bugs to hide.
77
77
  @source.send(name, *args, &b) if @source.respond_to? name
78
78
  end
@@ -67,7 +67,7 @@ module FlavourSaver
67
67
  [ :IDENT, name ]
68
68
  end
69
69
 
70
- rule /\./, :expression do
70
+ rule /\./, :expression do
71
71
  :DOT
72
72
  end
73
73
 
@@ -78,7 +78,7 @@ module FlavourSaver
78
78
  rule /"/, :expression do
79
79
  push_state :string
80
80
  end
81
-
81
+
82
82
  rule /(\\"|[^"])*/, :string do |str|
83
83
  [ :STRING, str ]
84
84
  end
@@ -87,6 +87,18 @@ module FlavourSaver
87
87
  pop_state
88
88
  end
89
89
 
90
+ rule /'/, :expression do
91
+ push_state :s_string
92
+ end
93
+
94
+ rule /(\\'|[^'])*/, :s_string do |str|
95
+ [ :S_STRING, str ]
96
+ end
97
+
98
+ rule /'/, :s_string do
99
+ pop_state
100
+ end
101
+
90
102
  # Handlebars allows methods with hyphens in them. Ruby doesn't, so
91
103
  # we'll assume you're trying to index the context with the identifier
92
104
  # and call the result.
@@ -81,7 +81,7 @@ module FlavourSaver
81
81
  arguments_to_str(name)
82
82
  end
83
83
  end
84
-
84
+
85
85
  class LocalVarNode < CallNode
86
86
  def to_s
87
87
  arguments_to_str("@#{name}")
@@ -91,12 +91,12 @@ module FlavourSaver
91
91
 
92
92
  production(:expr_bl_start) do
93
93
  clause('EXPRST HASH WHITE? IDENT WHITE? EXPRE') { |_,_,_,e,_,_| push_block CallNode.new(e,[]) }
94
- clause('EXPRST HASH WHITE? IDENT WHITE arguments EXPRE') { |_,_,_,e,_,a,_| push_block CallNode.new(e,a) }
94
+ clause('EXPRST HASH WHITE? IDENT WHITE arguments WHITE? EXPRE') { |_,_,_,e,_,a,_,_| push_block CallNode.new(e,a) }
95
95
  end
96
96
 
97
97
  production(:expr_bl_inv_start) do
98
98
  clause('EXPRST HAT WHITE? IDENT WHITE? EXPRE') { |_,_,_,e,_,_| push_block CallNode.new(e,[]) }
99
- clause('EXPRST HAT WHITE? IDENT WHITE arguments EXPRE') { |_,_,_,e,_,a,_| push_block CallNode.new(e,a) }
99
+ clause('EXPRST HAT WHITE? IDENT WHITE arguments WHITE? EXPRE') { |_,_,_,e,_,a,_,_| push_block CallNode.new(e,a) }
100
100
  end
101
101
 
102
102
  production(:expr_bl_end) do
@@ -134,6 +134,7 @@ module FlavourSaver
134
134
 
135
135
  production(:string) do
136
136
  clause('STRING') { |e| StringNode.new(e) }
137
+ clause('S_STRING') { |e| StringNode.new(e) }
137
138
  end
138
139
 
139
140
  production(:number) do
@@ -151,6 +152,7 @@ module FlavourSaver
151
152
 
152
153
  production(:hash_item) do
153
154
  clause('IDENT EQ string') { |e0,_,e1| { e0.to_sym => e1 } }
155
+ clause('IDENT EQ number') { |e0,_,e1| { e0.to_sym => e1 } }
154
156
  clause('IDENT EQ object_path') { |e0,_,e1| { e0.to_sym => e1 } }
155
157
  end
156
158
 
@@ -10,7 +10,7 @@ module FlavourSaver
10
10
  partials[name.to_s] = Parser.parse(Lexer.lex(content))
11
11
  end
12
12
  end
13
-
13
+
14
14
  def self.reset_partials
15
15
  @partials = {}
16
16
  end
@@ -1,5 +1,5 @@
1
1
  module FlavourSaver
2
- class RailsPartial
2
+ class RailsPartial
3
3
  def self.register_partial(*args)
4
4
  raise RuntimeError, "No need to register partials inside Rails."
5
5
  end
@@ -103,7 +103,7 @@ module FlavourSaver
103
103
  def evaluate_partial(node)
104
104
  _context = context
105
105
  _context = evaluate_argument(node.context) if node.context
106
- if defined?(::Rails)
106
+ if defined?(::Rails)
107
107
  context.send(:render, :partial => node.name, :object => _context)
108
108
  else
109
109
  partial = Partial.fetch(node.name)
@@ -128,7 +128,9 @@ module FlavourSaver
128
128
  when LocalVarNode
129
129
  result = private_variable_get(call.name)
130
130
  else
131
- raise UnknownHelperException, "Template context doesn't respond to method #{call.name.inspect}." unless context.respond_to? call.name
131
+ if call.parent.is_a? BlockExpressionNode and !context.respond_to? call.name
132
+ raise UnknownHelperException, "Template context doesn't respond to method #{call.name.inspect}."
133
+ end
132
134
  context.public_send(call.name, *call.arguments.map { |a| evaluate_argument(a) }, &block)
133
135
  end
134
136
  end
@@ -166,14 +168,14 @@ module FlavourSaver
166
168
 
167
169
  # If the result is collectiony then act as an implicit
168
170
  # "each"
169
- if result && result.respond_to?(:each)
171
+ if result && result.respond_to?(:each)
170
172
  if result.respond_to?(:size) && (result.size > 0)
171
173
  r = []
172
174
  # Not using #each_with_index because the object might
173
175
  # not actually be an Enumerable
174
176
  count = 0
175
- result.each do |e|
176
- r << block_runtime.contents(e, {'index' => count})
177
+ result.each do |e|
178
+ r << block_runtime.contents(e, {'index' => count})
177
179
  count += 1
178
180
  end
179
181
  result = r.join('')
@@ -1,3 +1,3 @@
1
1
  module FlavourSaver
2
- VERSION = "0.3.3"
2
+ VERSION = "0.3.4"
3
3
  end
data/lib/flavour_saver.rb CHANGED
@@ -17,7 +17,7 @@ module FlavourSaver
17
17
  end
18
18
 
19
19
  ActiveSupport.on_load(:action_view) do
20
- handler = proc do |template|
20
+ handler = proc do |template|
21
21
  # I'd rather be caching the Runtime object ready to fire, but apparently I don't get that luxury.
22
22
  <<-SOURCE
23
23
  FlavourSaver.evaluate((begin;#{template.source.inspect};end),self)
@@ -177,7 +177,7 @@ describe FlavourSaver do
177
177
 
178
178
  it "should be escaped" do
179
179
  context.stub(:awesome).and_return("&\"'`\\<>")
180
- if RUBY_VERSION == '2.0.0'
180
+ if RUBY_VERSION >= '2.0.0'
181
181
  subject.should == "&amp;&quot;&#39;&#x60;\\&lt;&gt;"
182
182
  else
183
183
  subject.should == "&amp;&quot;&#x27;&#x60;\\&lt;&gt;"
@@ -559,7 +559,7 @@ describe FlavourSaver do
559
559
  describe 'block helper for undefined value' do
560
560
  let(:template) { "{{#empty}}shoulnd't render{{/empty}}" }
561
561
  example do
562
- subject.should == ""
562
+ -> { subject }.should raise_exception(FlavourSaver::UnknownHelperException)
563
563
  end
564
564
  end
565
565
 
@@ -612,6 +612,7 @@ describe FlavourSaver do
612
612
  let(:template) { "{{#people}}{{name}}{{^}}{{none}}{{/people}}" }
613
613
  example do
614
614
  context.stub(:none).and_return("No people")
615
+ context.stub(:people).and_return(false)
615
616
  subject.should == "No people"
616
617
  end
617
618
  end
@@ -655,7 +656,7 @@ describe FlavourSaver do
655
656
  example do
656
657
  context.stub(:people).and_return([])
657
658
  context.stub(:message).and_return("Nobody's here")
658
- if RUBY_VERSION == '2.0.0'
659
+ if RUBY_VERSION >= '2.0.0'
659
660
  subject.should == "<p>Nobody&#39;s here</p>"
660
661
  else
661
662
  subject.should == "<p>Nobody&#x27;s here</p>"
@@ -11,7 +11,7 @@ describe 'Fixture: if_else.hbs' do
11
11
  subject.should == "Say hello to Alan."
12
12
  end
13
13
 
14
- it 'renders correcrtly when not given a name' do
14
+ it 'renders correctly when not given a name' do
15
15
  subject.should == "Nobody to say hi to."
16
16
  end
17
17
  end
@@ -10,4 +10,8 @@ describe 'Fixture: simple_expression.hbs' do
10
10
  context.should_receive(:hello).and_return('hello world')
11
11
  subject.should == "hello world"
12
12
  end
13
+
14
+ it 'renders nothing if undefined' do
15
+ subject.should == ""
16
+ end
13
17
  end
@@ -126,8 +126,8 @@ describe FlavourSaver::Lexer do
126
126
  end
127
127
 
128
128
  describe 'Backtrack expression' do
129
- subject { FlavourSaver::Lexer.lex "{{../foo}}" }
130
-
129
+ subject { FlavourSaver::Lexer.lex "{{../foo}}" }
130
+
131
131
  it 'has tokens in the correct order' do
132
132
  subject.map(&:type).should == [:EXPRST, :DOT, :DOT, :FWSL, :IDENT, :EXPRE, :EOS]
133
133
  end
@@ -147,7 +147,7 @@ describe FlavourSaver::Lexer do
147
147
  describe '{{#foo}}{{bar}}{{/foo}}' do
148
148
  it 'has tokens in the correct order' do
149
149
  subject.map(&:type).should == [
150
- :EXPRST, :HASH, :IDENT, :EXPRE,
150
+ :EXPRST, :HASH, :IDENT, :EXPRE,
151
151
  :EXPRST, :IDENT, :EXPRE,
152
152
  :EXPRST, :FWSL, :IDENT, :EXPRE,
153
153
  :EOS
@@ -154,6 +154,21 @@ describe FlavourSaver::Parser do
154
154
  end
155
155
  end
156
156
 
157
+ describe "{{foo bar=1}}" do
158
+ subject { FlavourSaver::Parser.parse(FlavourSaver::Lexer.lex("{{foo bar=1}}")) }
159
+
160
+ it "doesn't throw a NotInLanguage exception" do
161
+ -> { subject }.should_not raise_error
162
+ end
163
+
164
+ it 'calls the method "foo" with the hash {:bar => 1} as arguments' do
165
+ items.first.method.first.should be_a(FlavourSaver::CallNode)
166
+ items.first.method.first.name.should == 'foo'
167
+ items.first.method.first.arguments.first.should be_a(Hash)
168
+ items.first.method.first.arguments.first.should == { :bar => FlavourSaver::NumberNode.new('1') }
169
+ end
170
+ end
171
+
157
172
  describe '{{foo bar="baz" fred="wilma"}}' do
158
173
  subject { FlavourSaver::Parser.parse(FlavourSaver::Lexer.lex('{{foo bar="baz" fred="wilma"}}')) }
159
174
 
@@ -266,6 +281,22 @@ describe FlavourSaver::Parser do
266
281
  end
267
282
  end
268
283
 
284
+ describe "{{#foo bar 'baz'}}{{/foo}}" do
285
+ subject { FlavourSaver::Parser.parse(FlavourSaver::Lexer.lex("{{#foo bar 'baz'}}{{/foo}}")) }
286
+
287
+ it "doesn't throw a NotInLanguage exception" do
288
+ -> { subject }.should_not raise_error
289
+ end
290
+ end
291
+
292
+ describe "{{#foo bar 'baz' }}{{/foo}}" do
293
+ subject { FlavourSaver::Parser.parse(FlavourSaver::Lexer.lex("{{#foo bar 'baz' }}{{/foo}}")) }
294
+
295
+ it "doesn't throw a NotInLanguage exception" do
296
+ -> { subject }.should_not raise_error
297
+ end
298
+ end
299
+
269
300
  describe '' do
270
301
  subject { FlavourSaver::Parser.parse(FlavourSaver::Lexer.lex('')) }
271
302
 
metadata CHANGED
@@ -1,139 +1,139 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flavour_saver
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Harton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-06 00:00:00.000000000 Z
11
+ date: 2015-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: guard-rspec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec-core
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec-mocks
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec-expectations
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: guard-bundler
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: activesupport
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - '>='
101
+ - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '0'
103
+ version: 4.0.2
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - '>='
108
+ - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '0'
110
+ version: 4.0.2
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: rltk
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ~>
115
+ - - "~>"
116
116
  - !ruby/object:Gem::Version
117
117
  version: 2.2.0
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - ~>
122
+ - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: 2.2.0
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: tilt
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - '>='
129
+ - - ">="
130
130
  - !ruby/object:Gem::Version
131
131
  version: '0'
132
132
  type: :runtime
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - '>='
136
+ - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
139
  description: FlavourSaver is a pure-ruby implimentation of the Handlebars templating
@@ -144,8 +144,8 @@ executables: []
144
144
  extensions: []
145
145
  extra_rdoc_files: []
146
146
  files:
147
- - .gitignore
148
- - .travis.yml
147
+ - ".gitignore"
148
+ - ".travis.yml"
149
149
  - Gemfile
150
150
  - Gemfile.lock
151
151
  - Guardfile
@@ -199,17 +199,17 @@ require_paths:
199
199
  - lib
200
200
  required_ruby_version: !ruby/object:Gem::Requirement
201
201
  requirements:
202
- - - '>='
202
+ - - ">="
203
203
  - !ruby/object:Gem::Version
204
204
  version: '0'
205
205
  required_rubygems_version: !ruby/object:Gem::Requirement
206
206
  requirements:
207
- - - '>='
207
+ - - ">="
208
208
  - !ruby/object:Gem::Version
209
209
  version: '0'
210
210
  requirements: []
211
211
  rubyforge_project:
212
- rubygems_version: 2.2.2
212
+ rubygems_version: 2.4.3
213
213
  signing_key:
214
214
  specification_version: 4
215
215
  summary: Handlebars.js without the .js