handlebars-engine 0.3.2 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 93107a1a86ac4a02cadbbfd8221cba9515ff839e948e39dc37c61a3de1d15400
4
- data.tar.gz: '0091362554954a3f86ab24b7c0bc701595818b9b72af4b8780bccd3d6e4193ec'
3
+ metadata.gz: c0b3a91d4ae32afb2ef716bb86c5991620a7a5671b0e687a3064b3dcfedac590
4
+ data.tar.gz: f0067ebf10b733bdc4859a67f36b3d5094376459377e91e452e8c3fb78d6b831
5
5
  SHA512:
6
- metadata.gz: 7cd86ebb6fbeb64acd29dc3c4cb0f6853a7193983c53e05d32e42490a38b70f37c8d99ae7b214e3f76923c7931b46c1d3dcda1326339dfcdfa00ec29be745ae9
7
- data.tar.gz: 6f5fd77a08e73e9f2b9f40c1c769f2eca5a0359a35e9aa02ca9fd7d430e83e8f61d6c26541f0b2bbaf5caf3ff990663962cdedfc5dd61e8892c842a8b6404fec
6
+ metadata.gz: '083916774bcf8207e3ea40cb5957e9cf633956c07769997ba21d7302b9479f2ec2c1a3e8011702adfc708178a3ce1dcb5d02fc4ef70b93b950958d59ab94eff3'
7
+ data.tar.gz: b2047c755344c0157730878a2dcedae9bb5624c7c06a080fa32306032e4ba816031736739498f583b2c03a0b61196d15da9fb86d572b9f1575131cc94b0a349d
data/CHANGELOG.md CHANGED
@@ -7,6 +7,18 @@ 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
+
17
+ ## [0.3.3] - 2022-02-17
18
+
19
+ ### Changed
20
+ - `engine/function`: remove object finalizer (fixes [#14](https://github.com/gi/handlebars-ruby/issues/14))
21
+
10
22
  ## [0.3.2] - 2022-02-17
11
23
 
12
24
  ### Changed
@@ -4,24 +4,16 @@ 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
- ObjectSpace.define_finalizer(self, self.class.finalizer(context, name))
11
11
  end
12
12
 
13
13
  def call(*args)
14
+ @logger&.debug { "[handlebars] calling #{@name} with args #{args}" }
14
15
  @context.call(@name, *args)
15
16
  end
16
-
17
- def self.finalizer(context, name)
18
- proc {
19
- begin
20
- context.eval("delete #{name}")
21
- rescue ThreadError # rubocop:disable Lint/SuppressedException
22
- end
23
- }
24
- end
25
17
  end
26
18
  end
27
19
  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 registerHelper = (...args) => {
20
- const fn = args[args.length - 1];
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
- args[args.length - 1] = wrapper;
26
- return Handlebars.registerHelper(...args);
35
+ return registerJsHelper(name, wrapper);
27
36
  };
28
37
 
29
38
  var unregisterHelper = Handlebars.unregisterHelper.bind(Handlebars);
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Handlebars
4
4
  class Engine
5
- VERSION = "0.3.2"
5
+ VERSION = "0.3.4"
6
6
  end
7
7
  end
@@ -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("registerHelper('#{n}', #{n})")
88
+ evaluate("registerRbHelper('#{n}', #{n})")
88
89
  when String, Symbol
89
- evaluate("Handlebars.registerHelper('#{n}', #{f})")
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.2
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: 2022-02-17 00:00:00.000000000 Z
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: 2.6.0
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.3.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: []