handlebarsjs 0.2.0 → 0.3.0

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: 596f9e558bf5308c4fe912079507eb42a0ad15647ffb298f7400487d4d545146
4
- data.tar.gz: e0b7380f763e9fbb808a0246f03c2870f608a860369f621253b5789e20122d7e
3
+ metadata.gz: 15c79e4eeab6a4fd09c9bd0cea9e7026915b0ebda02cb674f5b6f9452cebbdfb
4
+ data.tar.gz: d6585183a584d0547012feebb57c8e2fb80168bc91d1e7a153022f71c7c346e4
5
5
  SHA512:
6
- metadata.gz: 665d312a9a202e08085879dd57b9ed6577318de92e29f3843297ca68f4a506c203fc082ad78dbb8574f200489dba0d835c5c32ef6e66fab083d05392b3b54525
7
- data.tar.gz: a3f4b97ab1ac479428bb972c7350767a74a83337da1e03e6612bda7494ed1cac9121f02d62df2de405778c9a2909c47a029309ba0fb5d905f8613eeae8f4957e
6
+ metadata.gz: 0be0808881aa15b12ffecce41193bb6a293440e71f0b197c8f2844cba51c635080e13db93bf445a97fb462811404a14733c8ee46b58eb7aa41b669630ab87f54
7
+ data.tar.gz: 4c5c159dec697cf909c17eb5e28582f6eb04d87381444c8c963b024bbfd62517dbe98c561c98b5dbe4d09835281c6e992154bdbf11ca90e60aa9e385ec273936
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ # [0.2.0](https://github.com/klueless-io/handlebarsjs/compare/v0.1.2...v0.2.0) (2022-07-02)
2
+
3
+
4
+ ### Features
5
+
6
+ * add support for basic template processing ([13d9649](https://github.com/klueless-io/handlebarsjs/commit/13d9649c03fa7de0326bed71d08441453194e4e1))
7
+ * add support for basic template processing ([64966e5](https://github.com/klueless-io/handlebarsjs/commit/64966e5ad396910dd0e7edc11a4d8427a10cae29))
8
+
1
9
  ## [0.1.2](https://github.com/klueless-io/handlebarsjs/compare/v0.1.1...v0.1.2) (2022-07-01)
2
10
 
3
11
 
@@ -6,13 +6,14 @@ module Handlebarsjs
6
6
  def initialize
7
7
  super
8
8
  # Handlebars 4.7.7
9
- snapshot_builder.add_library('handlebars', path: Handlebarsjs::HANDLEBARS_LIBRARY_PATH)
9
+ handlebars_snapshot.add_library('handlebars', path: Handlebarsjs::HANDLEBARS_LIBRARY_PATH)
10
10
 
11
11
  # Support functions for working with
12
- snapshot_builder.add_library('handlebars-api', path: Handlebarsjs::HANDLEBARS_API_PATH)
12
+ handlebars_snapshot.add_library('handlebars-api', path: Handlebarsjs::HANDLEBARS_API_PATH)
13
13
  end
14
14
 
15
15
  def process_template(template, options = {})
16
+ # TODO: process template function may be improved with some type of caching
16
17
  context.call('process_template', template, options)
17
18
  end
18
19
  end
@@ -1,18 +1,34 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Handlebarsjs
4
- # Wraps MiniRacer snapshot and provides clean API
5
- class SnapshotBuilder
4
+ # Wraps MiniRacer snapshot with specific emphasis on
5
+ # loading Handlebars helpers onto the MiniRacer context
6
+ # in the correct order. So that new contexts are preloaded
7
+ # with the handlebars library and the configured helpers.
8
+ class HandlebarsSnapshot
6
9
  attr_reader :scripts
10
+ attr_reader :helpers
7
11
 
8
12
  def initialize
9
13
  @scripts = []
14
+ @helpers = []
10
15
  end
11
16
 
12
17
  def add_library(name, script: nil, path: nil)
13
18
  add_script(name, 'library', script: script, path: path)
14
19
  end
15
20
 
21
+ def add_snippet(name, script: nil, path: nil)
22
+ add_script(name, 'snippet', script: script, path: path)
23
+ end
24
+
25
+ def add_helper(name, callback)
26
+ @helpers << {
27
+ name: name,
28
+ callback: callback
29
+ }
30
+ end
31
+
16
32
  def register_helper(name)
17
33
  add_script(name, 'helper', script: "Handlebars.registerHelper('#{name}', ruby_#{name})")
18
34
  end
@@ -21,8 +37,16 @@ module Handlebarsjs
21
37
  scripts.map { |script| "// #{script[:type]} - #{script[:name]}\n#{script[:script]}" }.join("\n\n")
22
38
  end
23
39
 
24
- def build
25
- @build ||= MiniRacer::Snapshot.new(script)
40
+ def snapshot
41
+ @snapshot ||= MiniRacer::Snapshot.new(script)
42
+ end
43
+
44
+ def dirty?
45
+ @snapshot.nil?
46
+ end
47
+
48
+ def debug
49
+ puts script
26
50
  end
27
51
 
28
52
  private
@@ -36,7 +60,7 @@ module Handlebarsjs
36
60
  end
37
61
 
38
62
  def add_script_item(name, type, script, path = nil)
39
- @build = nil
63
+ @snapshot = nil
40
64
  scripts << {
41
65
  name: name,
42
66
  type: type,
@@ -5,6 +5,7 @@
5
5
 
6
6
  // This is the main function that is called by the client.
7
7
  function process_template(template, data) {
8
+ // The process template function may be improved with some type of caching
8
9
  const compiled_template = Handlebars.compile(template);
9
10
  return compiled_template(data);
10
11
  }
@@ -3,10 +3,10 @@
3
3
  module Handlebarsjs
4
4
  # API for interacting with Javascript while providing native Ruby helpers
5
5
  class Javascript
6
- attr_reader :snapshot_builder
6
+ attr_reader :handlebars_snapshot
7
7
 
8
8
  def initialize
9
- @snapshot_builder = SnapshotBuilder.new
9
+ @handlebars_snapshot = HandlebarsSnapshot.new
10
10
  end
11
11
 
12
12
  def eval(script)
@@ -24,7 +24,8 @@ module Handlebarsjs
24
24
  private
25
25
 
26
26
  def context
27
- @context ||= MiniRacer::Context.new(snapshot: snapshot_builder.build)
27
+ puts 'Snapshot and context are out of date, calls to snapshot should happen before any calls to context' if !@context.nil? && handlebars_snapshot.dirty?
28
+ @context ||= MiniRacer::Context.new(snapshot: handlebars_snapshot.snapshot)
28
29
  end
29
30
  end
30
31
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Handlebarsjs
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.0'
5
5
  end
data/lib/handlebarsjs.rb CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  require 'mini_racer'
4
4
  require_relative 'handlebarsjs/version'
5
- require_relative 'handlebarsjs/snapshot_builder'
6
5
  require_relative 'handlebarsjs/javascript'
6
+ require_relative 'handlebarsjs/handlebars_snapshot'
7
7
  require_relative 'handlebarsjs/handlebars'
8
8
 
9
9
  module Handlebarsjs
data/package-lock.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "handlebarsjs",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "lockfileVersion": 2,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "handlebarsjs",
9
- "version": "0.2.0",
9
+ "version": "0.3.0",
10
10
  "devDependencies": {
11
11
  "@klueless-js/semantic-release-rubygem": "github:klueless-js/semantic-release-rubygem",
12
12
  "@semantic-release/changelog": "^6.0.1",
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "handlebarsjs",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "handlebarsjs GEM wraps the handlebars.js library and provides ruby/javascript interoperability",
5
5
  "scripts": {
6
6
  "release": "semantic-release"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: handlebarsjs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Cruwys
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-07-02 00:00:00.000000000 Z
11
+ date: 2022-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: k_log
@@ -72,12 +72,12 @@ files:
72
72
  - lib/handlebarsjs.rb
73
73
  - lib/handlebarsjs/api.rb
74
74
  - lib/handlebarsjs/handlebars.rb
75
+ - lib/handlebarsjs/handlebars_snapshot.rb
75
76
  - lib/handlebarsjs/helpers/comparison/and.rb
76
77
  - lib/handlebarsjs/javascript.rb
77
78
  - lib/handlebarsjs/javascript/handlebars-4.7.7.js
78
79
  - lib/handlebarsjs/javascript/handlebars-api.js
79
80
  - lib/handlebarsjs/javascript/handlebars-helpers.js
80
- - lib/handlebarsjs/snapshot_builder.rb
81
81
  - lib/handlebarsjs/version.rb
82
82
  - package-lock.json
83
83
  - package.json