handlebars-engine 0.3.3 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/lib/handlebars/engine/function.rb +3 -1
- data/lib/handlebars/engine/init.js +13 -4
- data/lib/handlebars/engine/version.rb +1 -1
- data/lib/handlebars/engine.rb +16 -3
- metadata +4 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c0b3a91d4ae32afb2ef716bb86c5991620a7a5671b0e687a3064b3dcfedac590
|
4
|
+
data.tar.gz: f0067ebf10b733bdc4859a67f36b3d5094376459377e91e452e8c3fb78d6b831
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '083916774bcf8207e3ea40cb5957e9cf633956c07769997ba21d7302b9479f2ec2c1a3e8011702adfc708178a3ce1dcb5d02fc4ef70b93b950958d59ab94eff3'
|
7
|
+
data.tar.gz: b2047c755344c0157730878a2dcedae9bb5624c7c06a080fa32306032e4ba816031736739498f583b2c03a0b61196d15da9fb86d572b9f1575131cc94b0a349d
|
data/CHANGELOG.md
CHANGED
@@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
7
7
|
|
8
8
|
## [Unreleased]
|
9
9
|
|
10
|
+
## [0.3.4] - 2025-08-12
|
11
|
+
|
12
|
+
### Changed
|
13
|
+
- `engine`: fixed issue with serialization of functions ([#26](https://github.com/gi/handlebars-ruby/pull/26))
|
14
|
+
- `engine`: include optional logging ([#24](https://github.com/gi/handlebars-ruby/pull/24))
|
15
|
+
- `ci`: test against macOS 14, Ubuntu 22.04, and ruby 3.1-3.4 ([#27](https://github.com/gi/handlebars-ruby/pull/27))
|
16
|
+
|
10
17
|
## [0.3.3] - 2022-02-17
|
11
18
|
|
12
19
|
### Changed
|
@@ -4,12 +4,14 @@ module Handlebars
|
|
4
4
|
class Engine
|
5
5
|
# A proxy for a JavaScript function defined in the context.
|
6
6
|
class Function
|
7
|
-
def initialize(context, name)
|
7
|
+
def initialize(context, name, logger: nil)
|
8
8
|
@context = context
|
9
|
+
@logger = logger
|
9
10
|
@name = name
|
10
11
|
end
|
11
12
|
|
12
13
|
def call(*args)
|
14
|
+
@logger&.debug { "[handlebars] calling #{@name} with args #{args}" }
|
13
15
|
@context.call(@name, *args)
|
14
16
|
end
|
15
17
|
end
|
@@ -16,14 +16,23 @@ var template = (spec) => {
|
|
16
16
|
var registerPartial = Handlebars.registerPartial.bind(Handlebars);
|
17
17
|
var unregisterPartial = Handlebars.unregisterPartial.bind(Handlebars);
|
18
18
|
|
19
|
-
var
|
20
|
-
|
19
|
+
var registerJsHelper = Handlebars.registerHelper.bind(Handlebars);
|
20
|
+
|
21
|
+
var registerRbHelper = (name, fn) => {
|
21
22
|
function wrapper(...args) {
|
23
|
+
// Ruby cannot access the `this` context, so pass it as the first argument.
|
22
24
|
args.unshift(this);
|
25
|
+
const { ...options } = args[args.length-1];
|
26
|
+
Object.entries(options).forEach(([key, value]) => {
|
27
|
+
if (typeof value === "function") {
|
28
|
+
// functions are cannot be passed back to Ruby
|
29
|
+
options[key] = "function";
|
30
|
+
}
|
31
|
+
});
|
32
|
+
args[args.length-1] = options
|
23
33
|
return fn(...args);
|
24
34
|
}
|
25
|
-
|
26
|
-
return Handlebars.registerHelper(...args);
|
35
|
+
return registerJsHelper(name, wrapper);
|
27
36
|
};
|
28
37
|
|
29
38
|
var unregisterHelper = Handlebars.unregisterHelper.bind(Handlebars);
|
data/lib/handlebars/engine.rb
CHANGED
@@ -21,7 +21,8 @@ module Handlebars
|
|
21
21
|
# environment.
|
22
22
|
# @param path [String, nil] the path to the version of Handlebars to load.
|
23
23
|
# If `nil`, the contents of `Handlebars::Source.bundled_path` is loaded.
|
24
|
-
def initialize(lazy: false, path: nil)
|
24
|
+
def initialize(lazy: false, logger: nil, path: nil)
|
25
|
+
@logger = logger
|
25
26
|
@path = path
|
26
27
|
init! unless lazy
|
27
28
|
end
|
@@ -84,9 +85,9 @@ module Handlebars
|
|
84
85
|
case f
|
85
86
|
when Proc
|
86
87
|
attach(n, &f)
|
87
|
-
evaluate("
|
88
|
+
evaluate("registerRbHelper('#{n}', #{n})")
|
88
89
|
when String, Symbol
|
89
|
-
evaluate("
|
90
|
+
evaluate("registerJsHelper('#{n}', #{f})")
|
90
91
|
end
|
91
92
|
end
|
92
93
|
end
|
@@ -175,6 +176,7 @@ module Handlebars
|
|
175
176
|
|
176
177
|
def attach(name, &block)
|
177
178
|
init!
|
179
|
+
@logger&.debug { "[handlebars] attaching #{name}" }
|
178
180
|
@context.attach(name.to_s, block)
|
179
181
|
end
|
180
182
|
|
@@ -182,6 +184,8 @@ module Handlebars
|
|
182
184
|
init!
|
183
185
|
name = name.to_s
|
184
186
|
|
187
|
+
@logger&.debug { "[handlebars] calling #{name} with args #{args}" }
|
188
|
+
|
185
189
|
if assign || eval
|
186
190
|
call_via_eval(name, args, assign: assign)
|
187
191
|
else
|
@@ -207,6 +211,7 @@ module Handlebars
|
|
207
211
|
end
|
208
212
|
|
209
213
|
def evaluate(code)
|
214
|
+
@logger&.debug { "[handlebars] evaluating #{code}" }
|
210
215
|
@context.eval(code)
|
211
216
|
end
|
212
217
|
|
@@ -222,10 +227,18 @@ module Handlebars
|
|
222
227
|
def init!
|
223
228
|
return if @init
|
224
229
|
|
230
|
+
@logger&.debug { "[handlebars] initializing" }
|
231
|
+
|
225
232
|
@context = MiniRacer::Context.new
|
233
|
+
@context.attach(
|
234
|
+
"console.log",
|
235
|
+
->(*args) { @logger&.debug { "[handlebars] #{args.join(" ")}" } },
|
236
|
+
)
|
226
237
|
@context.load(@path || ::Handlebars::Source.bundled_path)
|
227
238
|
@context.load(File.absolute_path("engine/init.js", __dir__))
|
228
239
|
|
240
|
+
@logger&.debug { "[handlebars] initialized" }
|
241
|
+
|
229
242
|
@init = true
|
230
243
|
end
|
231
244
|
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: handlebars-engine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zach Gianos
|
8
|
-
autorequire:
|
9
8
|
bindir: exe
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: handlebars-source
|
@@ -72,7 +71,6 @@ metadata:
|
|
72
71
|
github_repo: https://github.com/gi/handlebars-ruby
|
73
72
|
homepage_uri: https://github.com/gi/handlebars-ruby
|
74
73
|
source_code_uri: https://github.com/gi/handlebars-ruby
|
75
|
-
post_install_message:
|
76
74
|
rdoc_options: []
|
77
75
|
require_paths:
|
78
76
|
- lib
|
@@ -80,15 +78,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
80
78
|
requirements:
|
81
79
|
- - ">="
|
82
80
|
- !ruby/object:Gem::Version
|
83
|
-
version:
|
81
|
+
version: '3.0'
|
84
82
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
83
|
requirements:
|
86
84
|
- - ">="
|
87
85
|
- !ruby/object:Gem::Version
|
88
86
|
version: '0'
|
89
87
|
requirements: []
|
90
|
-
rubygems_version: 3.
|
91
|
-
signing_key:
|
88
|
+
rubygems_version: 3.6.9
|
92
89
|
specification_version: 4
|
93
90
|
summary: A complete interface to Handlebars.js for Ruby.
|
94
91
|
test_files: []
|