ruby-handlebars 0.3.0 → 0.4.0

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: c95697b3d0cf8b3500b7249cb254cfb97eb38bf2
4
- data.tar.gz: 9e1549cddad55b384bcda6fda8e9284c158159de
3
+ metadata.gz: f93c26821bf737456fef8ce9f7ed20ccfe75570b
4
+ data.tar.gz: 811122aa09f231331a952d7b808ecfc9bd598e81
5
5
  SHA512:
6
- metadata.gz: 6f602263f74b2a2cbc186643288f6b7c636969bb3ce07480de9a0f3c7ec00064d7df5c86138764c32c640781f07686099b7abadfbeb8f4d1a8da926240ac76c4
7
- data.tar.gz: bb6ff52d41ae7c6b1f8d9dbb2c8b0a54370c3f483457eef30e86e692166b2151993354c39d6765db854e7ac77711feb2275a7549431e546c53f979e77174f500
6
+ metadata.gz: d574182f8f5ce5a2532f1186f6ba3e0b17fcc81a60e5c4d0b6b00ebb71a3ded05ad00600aee756e46d12a7431a36ea75237298646110bd1686f7e88ab6fbeacd
7
+ data.tar.gz: 67761e1aeee7c4673b5ca5517409e48d4ed1e5b453c9b2c54bd896cad56d6014cf110aab3b9fec4d8b94caebd681a4f30e2e8c1e837f00ac73742d4e81daac07
data/README.md CHANGED
@@ -41,6 +41,13 @@ hbs.compile("Hello {{> full_name}}").call({person: {first_name: 'Pinkie', last_n
41
41
  # Gives: "Hello Pinkie Pie"
42
42
  ```
43
43
 
44
+ Partials support parameters:
45
+ ```ruby
46
+ hbs.register_partial('full_name', "{{fname}} {{lname}}")
47
+ hbs.compile("Hello {{> full_name fname='jon' lname='doe'}}")
48
+ # Gives: "Hello jon doe")
49
+ ```
50
+
44
51
  You can also register inline helpers:
45
52
 
46
53
  ```ruby
@@ -11,6 +11,7 @@ module Handlebars
11
11
  rule(:ocurly) { str('{')}
12
12
  rule(:ccurly) { str('}')}
13
13
  rule(:pipe) { str('|')}
14
+ rule(:eq) { str('=')}
14
15
 
15
16
 
16
17
  rule(:docurly) { ocurly >> ocurly }
@@ -22,6 +23,7 @@ module Handlebars
22
23
  rule(:as_kw) { str('as') }
23
24
 
24
25
  rule(:identifier) { (else_kw >> space? >> dccurly).absent? >> match['@\-a-zA-Z0-9_\?'].repeat(1) }
26
+ rule(:directory) { (else_kw >> space? >> dccurly).absent? >> match['@\-a-zA-Z0-9_\/\?'].repeat(1) }
25
27
  rule(:path) { identifier >> (dot >> (identifier | else_kw)).repeat }
26
28
 
27
29
  rule(:nocurly) { match('[^{}]') }
@@ -50,6 +52,9 @@ module Handlebars
50
52
  }
51
53
  rule(:parameters) { parameter >> (space >> parameter).repeat }
52
54
 
55
+ rule(:argument) { identifier.as(:key) >> space? >> eq >> space? >> parameter.as(:value) }
56
+ rule(:arguments) { argument >> (space >> argument).repeat }
57
+
53
58
  rule(:unsafe_helper) { docurly >> space? >> identifier.as(:unsafe_helper_name) >> (space? >> parameters.as(:parameters)).maybe >> space? >> dccurly }
54
59
  rule(:safe_helper) { tocurly >> space? >> identifier.as(:safe_helper_name) >> (space? >> parameters.as(:parameters)).maybe >> space? >> tccurly }
55
60
 
@@ -96,7 +101,9 @@ module Handlebars
96
101
  docurly >>
97
102
  gt >>
98
103
  space? >>
99
- identifier.as(:partial_name) >>
104
+ directory.as(:partial_name) >>
105
+ space? >>
106
+ arguments.as(:arguments).maybe >>
100
107
  space? >>
101
108
  dccurly
102
109
  }
@@ -78,6 +78,15 @@ module Handlebars
78
78
  end
79
79
  end
80
80
 
81
+ class PartialWithArgs < TreeItem.new(:partial_name, :arguments)
82
+ def _eval(context)
83
+ [arguments].flatten.map(&:values).map do |vals|
84
+ context.add_item vals.first.to_s, vals.last._eval(context)
85
+ end
86
+ context.get_partial(partial_name.to_s).call
87
+ end
88
+ end
89
+
81
90
  class Block < TreeItem.new(:items)
82
91
  def _eval(context)
83
92
  items.map {|item| item._eval(context)}.join()
@@ -162,6 +171,13 @@ module Handlebars
162
171
  ) {
163
172
  Tree::AsHelper.new(name, parameters, as_parameters, block_items, else_block_items)
164
173
  }
174
+
175
+ rule(
176
+ partial_name: simple(:partial_name),
177
+ arguments: subtree(:arguments)
178
+ ) {
179
+ Tree::PartialWithArgs.new(partial_name, arguments)
180
+ }
165
181
 
166
182
  rule(partial_name: simple(:partial_name)) {Tree::Partial.new(partial_name)}
167
183
  rule(block_items: subtree(:block_items)) {Tree::Block.new(block_items)}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-handlebars
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vincent Pretre
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-10-11 00:00:00.000000000 Z
12
+ date: 2019-10-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: parslet