handlebarsjs 0.1.2 → 0.2.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: 8048e42043ef2254d3c7e271e3469f6609b19ad08c9e92cf39ac5c1419b457c6
4
- data.tar.gz: 51e120956c3b647d250e0ec49a2d2ef6eb6591cdcc98c526cbf33a40726f034f
3
+ metadata.gz: 596f9e558bf5308c4fe912079507eb42a0ad15647ffb298f7400487d4d545146
4
+ data.tar.gz: e0b7380f763e9fbb808a0246f03c2870f608a860369f621253b5789e20122d7e
5
5
  SHA512:
6
- metadata.gz: 36ebcfef4508ed601fa5297970b7dadc17daa18da2cd65ab1345c742e0367138ccdf11d48e759efec54aad93733fba3d1564b05f451ba8536b928a428b52af52
7
- data.tar.gz: 315e2de217dc22e97b6bff861ddb255ec75dfde16d76627250f01677b6e471e562b76a9be9f310dab2e90162c6c2404753ee7f97e54eec0ecd445cb1bc614596
6
+ metadata.gz: 665d312a9a202e08085879dd57b9ed6577318de92e29f3843297ca68f4a506c203fc082ad78dbb8574f200489dba0d835c5c32ef6e66fab083d05392b3b54525
7
+ data.tar.gz: a3f4b97ab1ac479428bb972c7350767a74a83337da1e03e6612bda7494ed1cac9121f02d62df2de405778c9a2909c47a029309ba0fb5d905f8613eeae8f4957e
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## [0.1.2](https://github.com/klueless-io/handlebarsjs/compare/v0.1.1...v0.1.2) (2022-07-01)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * add snapshot builder ([f4dd8e8](https://github.com/klueless-io/handlebarsjs/commit/f4dd8e8e6a1c40da3e232bce93a33f252cc02a08))
7
+ * add snapshot builder ([c1e31c7](https://github.com/klueless-io/handlebarsjs/commit/c1e31c7e0f4402873fcbd1c3b065564bcb9457a4))
8
+
1
9
  ## [0.1.1](https://github.com/klueless-io/handlebarsjs/compare/v0.1.0...v0.1.1) (2022-04-17)
2
10
 
3
11
 
@@ -1,15 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Handlebarsjs
4
- class Handlebars
5
- # @helpers = {}
6
- # @partials = {}
7
- # @partial_missing = nil
8
- # @precompile = nil
9
- # @template_cache = {}
4
+ # API for interacting with Handlebars.js while providing native Ruby helpers
5
+ class Handlebars < Handlebarsjs::Javascript
6
+ def initialize
7
+ super
8
+ # Handlebars 4.7.7
9
+ snapshot_builder.add_library('handlebars', path: Handlebarsjs::HANDLEBARS_LIBRARY_PATH)
10
10
 
11
- attr_reader :snapshot
11
+ # Support functions for working with
12
+ snapshot_builder.add_library('handlebars-api', path: Handlebarsjs::HANDLEBARS_API_PATH)
13
+ end
12
14
 
13
- # def initialize
15
+ def process_template(template, options = {})
16
+ context.call('process_template', template, options)
17
+ end
14
18
  end
15
19
  end
@@ -1,10 +1,9 @@
1
- // Is this name ok? would compile_and_process_template be better?
2
- // Also, should this be at the top level namespace?
3
-
4
- function compile_template(template) {
5
- return Handlebars.compile(template);
6
- }
1
+ // This function will be needed in future when I can figure out how to cache templates.
2
+ // function compile_template(template) {
3
+ // return Handlebars.compile(template);
4
+ // }
7
5
 
6
+ // This is the main function that is called by the client.
8
7
  function process_template(template, data) {
9
8
  const compiled_template = Handlebars.compile(template);
10
9
  return compiled_template(data);
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Handlebarsjs
4
+ # API for interacting with Javascript while providing native Ruby helpers
5
+ class Javascript
6
+ attr_reader :snapshot_builder
7
+
8
+ def initialize
9
+ @snapshot_builder = SnapshotBuilder.new
10
+ end
11
+
12
+ def eval(script)
13
+ context.eval(script)
14
+ end
15
+
16
+ def attach(script, block)
17
+ context.attach(script, block)
18
+ end
19
+
20
+ def call(function_name, *arguments)
21
+ context.call(function_name, *arguments)
22
+ end
23
+
24
+ private
25
+
26
+ def context
27
+ @context ||= MiniRacer::Context.new(snapshot: snapshot_builder.build)
28
+ end
29
+ end
30
+ end
@@ -9,10 +9,6 @@ module Handlebarsjs
9
9
  @scripts = []
10
10
  end
11
11
 
12
- def add_handlebars_js
13
- add_script('handlebars', 'library', path: Handlebarsjs::JAVASCRIPT_PATH)
14
- end
15
-
16
12
  def add_library(name, script: nil, path: nil)
17
13
  add_script(name, 'library', script: script, path: path)
18
14
  end
@@ -22,11 +18,11 @@ module Handlebarsjs
22
18
  end
23
19
 
24
20
  def script
25
- scripts.map { |script| "# #{script[:type]} - #{script[:name]}\n#{script[:script]}" }.join("\n\n")
21
+ scripts.map { |script| "// #{script[:type]} - #{script[:name]}\n#{script[:script]}" }.join("\n\n")
26
22
  end
27
23
 
28
24
  def build
29
- MiniRacer::Snapshot.new(script)
25
+ @build ||= MiniRacer::Snapshot.new(script)
30
26
  end
31
27
 
32
28
  private
@@ -40,6 +36,7 @@ module Handlebarsjs
40
36
  end
41
37
 
42
38
  def add_script_item(name, type, script, path = nil)
39
+ @build = nil
43
40
  scripts << {
44
41
  name: name,
45
42
  type: type,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Handlebarsjs
4
- VERSION = '0.1.2'
4
+ VERSION = '0.2.0'
5
5
  end
data/lib/handlebarsjs.rb CHANGED
@@ -3,10 +3,12 @@
3
3
  require 'mini_racer'
4
4
  require_relative 'handlebarsjs/version'
5
5
  require_relative 'handlebarsjs/snapshot_builder'
6
+ require_relative 'handlebarsjs/javascript'
6
7
  require_relative 'handlebarsjs/handlebars'
7
8
 
8
9
  module Handlebarsjs
9
- JAVASCRIPT_PATH = 'lib/handlebarsjs/javascript/handlebars-4.7.7.js'
10
+ HANDLEBARS_LIBRARY_PATH = 'lib/handlebarsjs/javascript/handlebars-4.7.7.js'
11
+ HANDLEBARS_API_PATH = 'lib/handlebarsjs/javascript/handlebars-api.js'
10
12
 
11
13
  # raise Handlebarsjs::Error, 'Sample message'
12
14
  Error = Class.new(StandardError)
data/package-lock.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "handlebarsjs",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "lockfileVersion": 2,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "handlebarsjs",
9
- "version": "0.1.2",
9
+ "version": "0.2.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.1.2",
3
+ "version": "0.2.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.1.2
4
+ version: 0.2.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-01 00:00:00.000000000 Z
11
+ date: 2022-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: k_log
@@ -73,6 +73,7 @@ files:
73
73
  - lib/handlebarsjs/api.rb
74
74
  - lib/handlebarsjs/handlebars.rb
75
75
  - lib/handlebarsjs/helpers/comparison/and.rb
76
+ - lib/handlebarsjs/javascript.rb
76
77
  - lib/handlebarsjs/javascript/handlebars-4.7.7.js
77
78
  - lib/handlebarsjs/javascript/handlebars-api.js
78
79
  - lib/handlebarsjs/javascript/handlebars-helpers.js