ruby-handlebars 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +72 -0
- data/README.md +1 -1
- data/lib/ruby-handlebars/context.rb +22 -1
- data/lib/ruby-handlebars/escapers/html_escaper.rb +3 -1
- data/lib/ruby-handlebars/helpers/register_default_helpers.rb +2 -0
- data/lib/ruby-handlebars/helpers/with_helper.rb +25 -0
- data/lib/ruby-handlebars/parser.rb +2 -2
- data/lib/ruby-handlebars/template.rb +6 -4
- data/lib/ruby-handlebars/tree.rb +2 -2
- data/lib/ruby-handlebars.rb +0 -5
- metadata +43 -47
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8504965f0af446e8722e221cf88adf7b4c1268c9900817cbd6485c0e4d4d62d5
|
4
|
+
data.tar.gz: 54254d370a06fbd6baed8f1eb6a7b0fc80b668f61bd3971ea6acf381afbca592
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b5a6f3c377ed3bc265093d9eb55c17c9bca7204c8a0911b348047f3bc184eebc2297d8cbc4155fc0d30a4858b4e55307d48237b583275972ef1b5db8a5ab89d
|
7
|
+
data.tar.gz: a141269c77826d0821eb7bb34b955a9265476e4fc2fef0b2c18ab592b48f4b1c16a8003753fe8895f3e8bc1abab3e85ca47326ac433b3e6b45aeb9bc4d006167
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
ruby-handlebars changelog
|
2
|
+
=========================
|
3
|
+
|
4
|
+
[Unreleased]
|
5
|
+
------------
|
6
|
+
|
7
|
+
|
8
|
+
[0.4.1] (2022/06/01)
|
9
|
+
--------------------
|
10
|
+
|
11
|
+
- bump dependencies
|
12
|
+
- move CI to GitHub actions
|
13
|
+
- use separate context for each template evaluation ([#33](https://github.com/SmartBear/ruby-handlebars/pull/33) [@mvz])
|
14
|
+
- added `with`helper ([#28](https://github.com/SmartBear/ruby-handlebars/pull/28) [@creature])
|
15
|
+
- Faster parsing ([#26](https://github.com/SmartBear/ruby-handlebars/pull/26) - [@mvz])
|
16
|
+
|
17
|
+
[0.4.0] (2019/10/22)
|
18
|
+
--------------------
|
19
|
+
|
20
|
+
- Allow slash character in partial names ([#18](https://github.com/SmartBear/ruby-handlebars/pull/18) - [@d316])
|
21
|
+
- Add parameters for partials ([#19](https://github.com/SmartBear/ruby-handlebars/pull/19) [#20](https://github.com/SmartBear/ruby-handlebars/pull/20) - [@d316])
|
22
|
+
|
23
|
+
[0.3.0] (2019/10/11)
|
24
|
+
--------------------
|
25
|
+
|
26
|
+
- Support helpers with "as" notation (`{{each items as |item|}}`)
|
27
|
+
|
28
|
+
[0.2.1] (2019/8/30)
|
29
|
+
-------------------
|
30
|
+
|
31
|
+
- allow "else" word as being part of a path (eg: {{ my.something.else }} is okay)
|
32
|
+
|
33
|
+
[0.2.0] (2019/8/30)
|
34
|
+
-------------------
|
35
|
+
|
36
|
+
- allow dash in identifiers ([#15](https://github.com/SmartBear/ruby-handlebars/pull/15) - [@stewartmckee])
|
37
|
+
- add "unless" helper
|
38
|
+
- add "helperMissing" helper, called when a helper is missing
|
39
|
+
- "else" keyword is now handled by the parser directly
|
40
|
+
|
41
|
+
[0.1.1] (2019/6/26)
|
42
|
+
-------------------
|
43
|
+
|
44
|
+
- with_temporary_context returns the result produced by the block
|
45
|
+
|
46
|
+
[0.1.0] (2019/6/26)
|
47
|
+
-------------------
|
48
|
+
|
49
|
+
- add 'with_temporary_context' in context to define temporary variables
|
50
|
+
- enable @index, @first and @last variables in "each" helper ([#10](https://github.com/SmartBear/ruby-handlebars/pull/10) - [@schuetzm])
|
51
|
+
- allow specifying escaper when using double curly braces
|
52
|
+
- allow using helper calls as arguments ([#11](https://github.com/SmartBear/ruby-handlebars/pull/11) - [@schuetzm])
|
53
|
+
- escape trice-braces replacements ([#9](https://github.com/SmartBear/ruby-handlebars/pull/9) - [@schuetzm])
|
54
|
+
- allow non-hash data ([#8](https://github.com/SmartBear/ruby-handlebars/pull/8) - [@mvz])
|
55
|
+
- allow single curly braces in content ([#7](https://github.com/SmartBear/ruby-handlebars/pull/7) - [@mvz])
|
56
|
+
- allow empty literal string arguments ([pr6]https://github.com/SmartBear/ruby-handlebars/pull/6) - [@mvz])
|
57
|
+
|
58
|
+
<!-- Contributors lists -->
|
59
|
+
[@stewartmckee]: https://github.com/stewartmckee
|
60
|
+
[@schuetzm]: https://github.com/schuetzm
|
61
|
+
[@mvz]: https://github.com/mvz
|
62
|
+
[@d316]: https://github.com/d316
|
63
|
+
[@creature]: https://github.com/creature
|
64
|
+
|
65
|
+
<!-- Releases diffs -->
|
66
|
+
[Unreleased]: https://github.com/smartbear/ruby-handlebars/compare/v0.4.0...master
|
67
|
+
[0.4.0]: https://github.com/smartbear/ruby-handlebars/compare/v0.3.0...v0.4.0
|
68
|
+
[0.3.0]: https://github.com/smartbear/ruby-handlebars/compare/v0.2.1...v0.3.0
|
69
|
+
[0.2.1]: https://github.com/smartbear/ruby-handlebars/compare/v0.2.0...v0.2.1
|
70
|
+
[0.2.0]: https://github.com/smartbear/ruby-handlebars/compare/v0.1.1...v0.2.0
|
71
|
+
[0.1.1]: https://github.com/smartbear/ruby-handlebars/compare/v0.1.0...v0.1.1
|
72
|
+
[0.1.0]: https://github.com/smartbear/ruby-handlebars/compare/v0.0.6...v0.1.0
|
data/README.md
CHANGED
@@ -45,7 +45,7 @@ Partials support parameters:
|
|
45
45
|
```ruby
|
46
46
|
hbs.register_partial('full_name', "{{fname}} {{lname}}")
|
47
47
|
hbs.compile("Hello {{> full_name fname='jon' lname='doe'}}")
|
48
|
-
# Gives: "Hello jon doe"
|
48
|
+
# Gives: "Hello jon doe"
|
49
49
|
```
|
50
50
|
|
51
51
|
You can also register inline helpers:
|
@@ -1,5 +1,10 @@
|
|
1
1
|
module Handlebars
|
2
|
-
|
2
|
+
class Context
|
3
|
+
def initialize(hbs, data)
|
4
|
+
@hbs = hbs
|
5
|
+
@data = data
|
6
|
+
end
|
7
|
+
|
3
8
|
def get(path)
|
4
9
|
items = path.split('.'.freeze)
|
5
10
|
if locals.key? items.first.to_sym
|
@@ -15,6 +20,22 @@ module Handlebars
|
|
15
20
|
current
|
16
21
|
end
|
17
22
|
|
23
|
+
def escaper
|
24
|
+
@hbs.escaper
|
25
|
+
end
|
26
|
+
|
27
|
+
def get_helper(name)
|
28
|
+
@hbs.get_helper(name)
|
29
|
+
end
|
30
|
+
|
31
|
+
def get_as_helper(name)
|
32
|
+
@hbs.get_as_helper(name)
|
33
|
+
end
|
34
|
+
|
35
|
+
def get_partial(name)
|
36
|
+
@hbs.get_partial(name)
|
37
|
+
end
|
38
|
+
|
18
39
|
def add_item(key, value)
|
19
40
|
locals[key.to_sym] = value
|
20
41
|
end
|
@@ -2,6 +2,7 @@ require_relative 'each_helper'
|
|
2
2
|
require_relative 'helper_missing_helper'
|
3
3
|
require_relative 'if_helper'
|
4
4
|
require_relative 'unless_helper'
|
5
|
+
require_relative 'with_helper'
|
5
6
|
|
6
7
|
module Handlebars
|
7
8
|
module Helpers
|
@@ -10,6 +11,7 @@ module Handlebars
|
|
10
11
|
HelperMissingHelper.register(hbs)
|
11
12
|
IfHelper.register(hbs)
|
12
13
|
UnlessHelper.register(hbs)
|
14
|
+
WithHelper.register(hbs)
|
13
15
|
end
|
14
16
|
end
|
15
17
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require_relative 'default_helper'
|
2
|
+
|
3
|
+
module Handlebars
|
4
|
+
module Helpers
|
5
|
+
class WithHelper < DefaultHelper
|
6
|
+
def self.registry_name
|
7
|
+
'with'
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.apply(context, data, block, else_block)
|
11
|
+
if data
|
12
|
+
context.with_temporary_context(data) do
|
13
|
+
block.fn(context)
|
14
|
+
end
|
15
|
+
else
|
16
|
+
else_block.fn(context)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.apply_as(context, data, name, block, else_block)
|
21
|
+
self.apply(context, { name.to_sym => data }, block, else_block)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -30,10 +30,10 @@ module Handlebars
|
|
30
30
|
rule(:eof) { any.absent? }
|
31
31
|
rule(:template_content) {
|
32
32
|
(
|
33
|
+
nocurly.repeat(1) | # A sequence of non-curlies
|
33
34
|
ocurly >> nocurly | # Opening curly that doesn't start a {{}}
|
34
|
-
ocurly >> eof | # Opening curly that doesn't start a {{}} because it's the end
|
35
35
|
ccurly | # Closing curly that is not inside a {{}}
|
36
|
-
|
36
|
+
ocurly >> eof # Opening curly that doesn't start a {{}} because it's the end
|
37
37
|
).repeat(1).as(:template_content) }
|
38
38
|
|
39
39
|
rule(:unsafe_replacement) { docurly >> space? >> path.as(:replaced_unsafe_item) >> space? >> dccurly }
|
@@ -8,11 +8,13 @@ module Handlebars
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def call(args = nil)
|
11
|
-
|
12
|
-
@hbs.set_context(args)
|
13
|
-
end
|
11
|
+
ctx = Context.new(@hbs, args)
|
14
12
|
|
15
|
-
@ast.eval(
|
13
|
+
@ast.eval(ctx)
|
14
|
+
end
|
15
|
+
|
16
|
+
def call_with_context(ctx)
|
17
|
+
@ast.eval(ctx)
|
16
18
|
end
|
17
19
|
end
|
18
20
|
end
|
data/lib/ruby-handlebars/tree.rb
CHANGED
@@ -74,7 +74,7 @@ module Handlebars
|
|
74
74
|
|
75
75
|
class Partial < TreeItem.new(:partial_name)
|
76
76
|
def _eval(context)
|
77
|
-
context.get_partial(partial_name.to_s).
|
77
|
+
context.get_partial(partial_name.to_s).call_with_context(context)
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
@@ -83,7 +83,7 @@ module Handlebars
|
|
83
83
|
[arguments].flatten.map(&:values).map do |vals|
|
84
84
|
context.add_item vals.first.to_s, vals.last._eval(context)
|
85
85
|
end
|
86
|
-
context.get_partial(partial_name.to_s).
|
86
|
+
context.get_partial(partial_name.to_s).call_with_context(context)
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
data/lib/ruby-handlebars.rb
CHANGED
@@ -7,7 +7,6 @@ require_relative 'ruby-handlebars/escapers/html_escaper'
|
|
7
7
|
|
8
8
|
module Handlebars
|
9
9
|
class Handlebars
|
10
|
-
include Context
|
11
10
|
attr_reader :escaper
|
12
11
|
|
13
12
|
def initialize()
|
@@ -46,10 +45,6 @@ module Handlebars
|
|
46
45
|
@partials[name.to_s]
|
47
46
|
end
|
48
47
|
|
49
|
-
def set_context(ctx)
|
50
|
-
@data = ctx
|
51
|
-
end
|
52
|
-
|
53
48
|
def set_escaper(escaper = nil)
|
54
49
|
@escaper = escaper || Escapers::HTMLEscaper
|
55
50
|
end
|
metadata
CHANGED
@@ -1,144 +1,140 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-handlebars
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vincent Pretre
|
8
8
|
- Hiptest R&D
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2022-06-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: parslet
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- - ">="
|
19
|
-
- !ruby/object:Gem::Version
|
20
|
-
version: 1.6.2
|
21
18
|
- - "~>"
|
22
19
|
- !ruby/object:Gem::Version
|
23
20
|
version: '1.6'
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.6.2
|
24
24
|
type: :runtime
|
25
25
|
prerelease: false
|
26
26
|
version_requirements: !ruby/object:Gem::Requirement
|
27
27
|
requirements:
|
28
|
-
- - ">="
|
29
|
-
- !ruby/object:Gem::Version
|
30
|
-
version: 1.6.2
|
31
28
|
- - "~>"
|
32
29
|
- !ruby/object:Gem::Version
|
33
30
|
version: '1.6'
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.6.2
|
34
34
|
- !ruby/object:Gem::Dependency
|
35
35
|
name: pry
|
36
36
|
requirement: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: 0.10.1
|
41
38
|
- - "~>"
|
42
39
|
- !ruby/object:Gem::Version
|
43
40
|
version: '0.10'
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.10.1
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
46
|
version_requirements: !ruby/object:Gem::Requirement
|
47
47
|
requirements:
|
48
|
-
- - ">="
|
49
|
-
- !ruby/object:Gem::Version
|
50
|
-
version: 0.10.1
|
51
48
|
- - "~>"
|
52
49
|
- !ruby/object:Gem::Version
|
53
50
|
version: '0.10'
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.10.1
|
54
54
|
- !ruby/object:Gem::Dependency
|
55
55
|
name: pry-stack_explorer
|
56
56
|
requirement: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
|
-
- - ">="
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
version: 0.4.9.1
|
61
58
|
- - "~>"
|
62
59
|
- !ruby/object:Gem::Version
|
63
60
|
version: '0.4'
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: 0.4.9.1
|
64
64
|
type: :development
|
65
65
|
prerelease: false
|
66
66
|
version_requirements: !ruby/object:Gem::Requirement
|
67
67
|
requirements:
|
68
|
-
- - ">="
|
69
|
-
- !ruby/object:Gem::Version
|
70
|
-
version: 0.4.9.1
|
71
68
|
- - "~>"
|
72
69
|
- !ruby/object:Gem::Version
|
73
70
|
version: '0.4'
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: 0.4.9.1
|
74
74
|
- !ruby/object:Gem::Dependency
|
75
75
|
name: rspec
|
76
76
|
requirement: !ruby/object:Gem::Requirement
|
77
77
|
requirements:
|
78
|
-
- - ">="
|
79
|
-
- !ruby/object:Gem::Version
|
80
|
-
version: 3.1.0
|
81
78
|
- - "~>"
|
82
79
|
- !ruby/object:Gem::Version
|
83
80
|
version: '3.1'
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: 3.1.0
|
84
84
|
type: :development
|
85
85
|
prerelease: false
|
86
86
|
version_requirements: !ruby/object:Gem::Requirement
|
87
87
|
requirements:
|
88
|
-
- - ">="
|
89
|
-
- !ruby/object:Gem::Version
|
90
|
-
version: 3.1.0
|
91
88
|
- - "~>"
|
92
89
|
- !ruby/object:Gem::Version
|
93
90
|
version: '3.1'
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 3.1.0
|
94
94
|
- !ruby/object:Gem::Dependency
|
95
95
|
name: rspec-mocks
|
96
96
|
requirement: !ruby/object:Gem::Requirement
|
97
97
|
requirements:
|
98
|
-
- - ">="
|
99
|
-
- !ruby/object:Gem::Version
|
100
|
-
version: 3.1.3
|
101
98
|
- - "~>"
|
102
99
|
- !ruby/object:Gem::Version
|
103
100
|
version: '3.1'
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 3.1.3
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- - ">="
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: 3.1.3
|
111
108
|
- - "~>"
|
112
109
|
- !ruby/object:Gem::Version
|
113
110
|
version: '3.1'
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: 3.1.3
|
114
114
|
- !ruby/object:Gem::Dependency
|
115
|
-
name:
|
115
|
+
name: juwelier
|
116
116
|
requirement: !ruby/object:Gem::Requirement
|
117
117
|
requirements:
|
118
|
-
- - ">="
|
119
|
-
- !ruby/object:Gem::Version
|
120
|
-
version: 2.0.1
|
121
118
|
- - "~>"
|
122
119
|
- !ruby/object:Gem::Version
|
123
|
-
version: '2.
|
120
|
+
version: '2.4'
|
124
121
|
type: :development
|
125
122
|
prerelease: false
|
126
123
|
version_requirements: !ruby/object:Gem::Requirement
|
127
124
|
requirements:
|
128
|
-
- - ">="
|
129
|
-
- !ruby/object:Gem::Version
|
130
|
-
version: 2.0.1
|
131
125
|
- - "~>"
|
132
126
|
- !ruby/object:Gem::Version
|
133
|
-
version: '2.
|
134
|
-
description:
|
127
|
+
version: '2.4'
|
128
|
+
description:
|
135
129
|
email: v.pretre@hiptest.net
|
136
130
|
executables: []
|
137
131
|
extensions: []
|
138
132
|
extra_rdoc_files:
|
133
|
+
- CHANGELOG.md
|
139
134
|
- LICENSE
|
140
135
|
- README.md
|
141
136
|
files:
|
137
|
+
- CHANGELOG.md
|
142
138
|
- LICENSE
|
143
139
|
- README.md
|
144
140
|
- lib/ruby-handlebars.rb
|
@@ -152,13 +148,14 @@ files:
|
|
152
148
|
- lib/ruby-handlebars/helpers/if_helper.rb
|
153
149
|
- lib/ruby-handlebars/helpers/register_default_helpers.rb
|
154
150
|
- lib/ruby-handlebars/helpers/unless_helper.rb
|
151
|
+
- lib/ruby-handlebars/helpers/with_helper.rb
|
155
152
|
- lib/ruby-handlebars/parser.rb
|
156
153
|
- lib/ruby-handlebars/template.rb
|
157
154
|
- lib/ruby-handlebars/tree.rb
|
158
155
|
homepage: https://github.com/smartbear/ruby-handlebars
|
159
156
|
licenses: []
|
160
157
|
metadata: {}
|
161
|
-
post_install_message:
|
158
|
+
post_install_message:
|
162
159
|
rdoc_options: []
|
163
160
|
require_paths:
|
164
161
|
- lib
|
@@ -173,9 +170,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
173
170
|
- !ruby/object:Gem::Version
|
174
171
|
version: '0'
|
175
172
|
requirements: []
|
176
|
-
|
177
|
-
|
178
|
-
signing_key:
|
173
|
+
rubygems_version: 3.2.33
|
174
|
+
signing_key:
|
179
175
|
specification_version: 4
|
180
176
|
summary: Pure Ruby library for Handlebars templates
|
181
177
|
test_files: []
|