handlebarsjs 0.5.4 → 0.5.7

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: 1ae80a08fb0257c2b9f0ad6f48cd7c907bc15388b8a68d02ddd1b05ac69bff96
4
- data.tar.gz: 84a1eb1d565250f52346f7454e3122759e795d7801a0c1d4cd106af71b7dae8b
3
+ metadata.gz: 11fa1ae2d5651494b88fba96cffddf5fbf61a4a4bca2d558af4bf4c9bdab7051
4
+ data.tar.gz: ba0da5f90e25cb0d9aa93d3b0da33c1a7bd46051d194f37a6423831cad83e39b
5
5
  SHA512:
6
- metadata.gz: f308dce020f6a57b9d6c2b21997abb5add4b9ad040b8217ab033b7f1ac990a94ca2c74e2ad1ebde394a16ffce031dc40341333d50705d83b91fc62ac570cdf47
7
- data.tar.gz: 2a6253654fcbd9c3ca30a2b4c071667bfe16814d72fa1a465edc2845fc658b88d23482b3521e9520d0585301d6a757ee4c69a8088deb49454cb869e12ef3c8e9
6
+ metadata.gz: 9c56cb2167139c856225497aa504d8bd4c3352b262427eeb812491a9dbe67d7a334c7034b48e16d55e7c455adff584e978894812971e75379e964fbc37880ad6
7
+ data.tar.gz: e3534532930b1ed409d34c8ab48444c7313016c01d928043650d2c84e5203ff34a5a7ada22ea2bf15c9525ca931c35712f31d331bf90af2758eef99dfb08f826
data/CHANGELOG.md CHANGED
@@ -1,3 +1,24 @@
1
+ ## [0.5.6](https://github.com/klueless-io/handlebarsjs/compare/v0.5.5...v0.5.6) (2022-07-13)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * add configuration capability to handlebars_snapshot ([06f7ca6](https://github.com/klueless-io/handlebarsjs/commit/06f7ca628018d4a89c9b068c8cae4565a624a3db))
7
+
8
+ ## [0.5.5](https://github.com/klueless-io/handlebarsjs/compare/v0.5.4...v0.5.5) (2022-07-12)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * add configuration ([ab16612](https://github.com/klueless-io/handlebarsjs/commit/ab16612500b1cf61094b128e14fcecbe1aacde5b))
14
+
15
+ ## [0.5.4](https://github.com/klueless-io/handlebarsjs/compare/v0.5.3...v0.5.4) (2022-07-12)
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * add inflection: pluralize_number and pluralize_number_word ([33ba59a](https://github.com/klueless-io/handlebarsjs/commit/33ba59a7b0ec86e29ed8ddd5bfd3bb5e91d18123))
21
+
1
22
  ## [0.5.3](https://github.com/klueless-io/handlebarsjs/compare/v0.5.2...v0.5.3) (2022-07-12)
2
23
 
3
24
 
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Handlebarsjs
4
+ # Register this configuration access extension for Handlebars configuration
5
+ module HandlebarsConfigurationExtension
6
+ def handlebars
7
+ return @handlebars if defined? @handlebars
8
+
9
+ @handlebars = HandlebarsConfiguration.new
10
+ end
11
+ end
12
+
13
+ # handlebars.handlebars_snapshot.add_helper(helper_name, helper)
14
+ # Structure for storing Cmdlet configuration
15
+ class HandlebarsConfiguration
16
+ include KLog::Logging
17
+
18
+ attr_accessor :helpers
19
+
20
+ def initialize
21
+ @helpers = []
22
+ end
23
+
24
+ HelperConfig = Struct.new(:name, :helper)
25
+
26
+ def helper(name, helper)
27
+ @helpers << HelperConfig.new(name, helper)
28
+ end
29
+ end
30
+ end
31
+
32
+ KConfig::Configuration.register(:handlebars, Handlebarsjs::HandlebarsConfigurationExtension)
@@ -5,16 +5,35 @@ module Handlebarsjs
5
5
  class Handlebars < Handlebarsjs::Javascript
6
6
  def initialize
7
7
  super
8
- # Handlebars 4.7.7
9
- handlebars_snapshot.add_library('handlebars', path: Handlebarsjs::HANDLEBARS_LIBRARY_PATH)
10
8
 
11
- # Support functions for working with
12
- handlebars_snapshot.add_library('handlebars-api', path: Handlebarsjs::HANDLEBARS_API_PATH)
9
+ add_libraries
10
+ add_configured_helpers
13
11
  end
14
12
 
15
13
  def process_template(template, options = {})
16
14
  # TODO: process template function may be improved with some type of caching
17
15
  context.call('process_template', template, options)
18
16
  end
17
+
18
+ private
19
+
20
+ def add_libraries
21
+ # Handlebars 4.7.7
22
+ gem_path = Gem.loaded_specs['handlebarsjs'].full_gem_path
23
+
24
+ handlebars_lib_path = File.join(gem_path, Handlebarsjs::HANDLEBARS_LIBRARY_PATH)
25
+ handlebars_api_path = File.join(gem_path, Handlebarsjs::HANDLEBARS_API_PATH)
26
+
27
+ handlebars_snapshot.add_library('handlebars', path: handlebars_lib_path)
28
+
29
+ # Support functions for working with
30
+ handlebars_snapshot.add_library('handlebars-api', path: handlebars_api_path)
31
+ end
32
+
33
+ def add_configured_helpers
34
+ KConfig.configuration.handlebars.helpers.each do |helper_config|
35
+ handlebars_snapshot.add_helper(helper_config.name, helper_config.helper)
36
+ end
37
+ end
19
38
  end
20
39
  end
@@ -6,6 +6,8 @@ module Handlebarsjs
6
6
  # in the correct order. So that new contexts are preloaded
7
7
  # with the handlebars library and the configured helpers.
8
8
  class HandlebarsSnapshot
9
+ include KLog::Logging
10
+
9
11
  attr_reader :scripts
10
12
  attr_reader :helpers
11
13
 
@@ -60,7 +62,8 @@ module Handlebarsjs
60
62
  end
61
63
 
62
64
  def debug
63
- puts script
65
+ data = { scripts: scripts, helpers: helpers }
66
+ log.structure(data)
64
67
  end
65
68
 
66
69
  private
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ KConfig.configure do |config|
4
+ config.handlebars.helper(:join, Handlebarsjs::Helpers::Array::Join.new)
5
+ config.handlebars.helper(:join_pre, Handlebarsjs::Helpers::Array::JoinPre.new)
6
+ config.handlebars.helper(:join_post, Handlebarsjs::Helpers::Array::JoinPost.new)
7
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ KConfig.configure do |config|
4
+ config.handlebars.helper(:back_slash, Handlebarsjs::Helpers::Case::BackSlash.new)
5
+ config.handlebars.helper(:camel, Handlebarsjs::Helpers::Case::Camel.new)
6
+ config.handlebars.helper(:constant, Handlebarsjs::Helpers::Case::Constant.new)
7
+ config.handlebars.helper(:dash, Handlebarsjs::Helpers::Case::Dash.new)
8
+ config.handlebars.helper(:dot, Handlebarsjs::Helpers::Case::Dot.new)
9
+ config.handlebars.helper(:double_colon, Handlebarsjs::Helpers::Case::DoubleColon.new)
10
+ config.handlebars.helper(:human, Handlebarsjs::Helpers::Case::Human.new)
11
+ config.handlebars.helper(:lamel, Handlebarsjs::Helpers::Case::Lamel.new)
12
+ config.handlebars.helper(:lower, Handlebarsjs::Helpers::Case::Lower.new)
13
+ config.handlebars.helper(:slash, Handlebarsjs::Helpers::Case::Slash.new)
14
+ config.handlebars.helper(:snake, Handlebarsjs::Helpers::Case::Snake.new)
15
+ config.handlebars.helper(:title, Handlebarsjs::Helpers::Case::Title.new)
16
+ config.handlebars.helper(:upper, Handlebarsjs::Helpers::Case::Upper.new)
17
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ KConfig.configure do |config|
4
+ config.handlebars.helper(:and, Handlebarsjs::Helpers::Comparison::And.new)
5
+ config.handlebars.helper(:default, Handlebarsjs::Helpers::Comparison::Default.new)
6
+ config.handlebars.helper(:eq, Handlebarsjs::Helpers::Comparison::Eq.new)
7
+ config.handlebars.helper(:gt, Handlebarsjs::Helpers::Comparison::Gt.new)
8
+ config.handlebars.helper(:gte, Handlebarsjs::Helpers::Comparison::Gte.new)
9
+ config.handlebars.helper(:lt, Handlebarsjs::Helpers::Comparison::Lt.new)
10
+ config.handlebars.helper(:lte, Handlebarsjs::Helpers::Comparison::Lte.new)
11
+ config.handlebars.helper(:ne, Handlebarsjs::Helpers::Comparison::Ne.new)
12
+ config.handlebars.helper(:or, Handlebarsjs::Helpers::Comparison::Or.new)
13
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ KConfig.configure do |config|
4
+ config.handlebars.helper(:ordinal, Handlebarsjs::Helpers::Inflection::Ordinal.new)
5
+ config.handlebars.helper(:ordinalize, Handlebarsjs::Helpers::Inflection::Ordinalize.new)
6
+ config.handlebars.helper(:pluralize, Handlebarsjs::Helpers::Inflection::Pluralize.new)
7
+ config.handlebars.helper(:pluralize_number, Handlebarsjs::Helpers::Inflection::PluralizeNumber.new)
8
+ config.handlebars.helper(:pluralize_number_word, Handlebarsjs::Helpers::Inflection::PluralizeNumberWord.new)
9
+ config.handlebars.helper(:singularize, Handlebarsjs::Helpers::Inflection::Singularize.new)
10
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Handlebarsjs
4
- VERSION = '0.5.4'
4
+ VERSION = '0.5.7'
5
5
  end
data/lib/handlebarsjs.rb CHANGED
@@ -3,12 +3,14 @@
3
3
  require 'mini_racer'
4
4
  require 'cmdlet'
5
5
  require_relative 'handlebarsjs/version'
6
+ require_relative 'handlebarsjs/configuration'
6
7
  require_relative 'handlebarsjs/javascript'
7
8
  require_relative 'handlebarsjs/handlebars_snapshot'
8
9
  require_relative 'handlebarsjs/handlebars'
9
10
  require_relative 'handlebarsjs/base_helper'
10
11
  require_relative '_'
11
12
 
13
+ # Handlebarsjs is a Ruby wrapper for the Handlebars.js templating engine.
12
14
  module Handlebarsjs
13
15
  HANDLEBARS_LIBRARY_PATH = 'lib/handlebarsjs/javascript/handlebars-4.7.7.js'
14
16
  HANDLEBARS_API_PATH = 'lib/handlebarsjs/javascript/handlebars-api.js'
@@ -16,7 +18,27 @@ module Handlebarsjs
16
18
  # raise Handlebarsjs::Error, 'Sample message'
17
19
  Error = Class.new(StandardError)
18
20
 
19
- # Your code goes here...
21
+ class << self
22
+ # Get a singleton instance of the Handlebars engine.
23
+ #
24
+ # The engine is exposed as a singleton and that means that if you
25
+ # alter the configuration after calling Handlebarsjs.engine,
26
+ # you will have old helper state attached to the engine.
27
+ #
28
+ # If you need to update your helper state, then run Handlebarsjs.reset
29
+ # to clear the singleton
30
+ def engine
31
+ @engine ||= Handlebarsjs::Handlebars.new
32
+ end
33
+
34
+ def reset
35
+ @engine = nil
36
+ end
37
+
38
+ def process_template(template, options = {})
39
+ @engine.process_template(template, options)
40
+ end
41
+ end
20
42
  end
21
43
 
22
44
  if ENV.fetch('KLUE_DEBUG', 'false').downcase == 'true'
data/package-lock.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "handlebarsjs",
3
- "version": "0.5.4",
3
+ "version": "0.5.7",
4
4
  "lockfileVersion": 2,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "handlebarsjs",
9
- "version": "0.5.4",
9
+ "version": "0.5.7",
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.5.4",
3
+ "version": "0.5.7",
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.5.4
4
+ version: 0.5.7
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-12 00:00:00.000000000 Z
11
+ date: 2022-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cmdlet
@@ -91,10 +91,11 @@ files:
91
91
  - docs/project-plan/project_in_progress.svg
92
92
  - lib/_.rb
93
93
  - lib/handlebarsjs.rb
94
- - lib/handlebarsjs/api.rb
95
94
  - lib/handlebarsjs/base_helper.rb
95
+ - lib/handlebarsjs/configuration.rb
96
96
  - lib/handlebarsjs/handlebars.rb
97
97
  - lib/handlebarsjs/handlebars_snapshot.rb
98
+ - lib/handlebarsjs/helpers/array/default_configuration.rb
98
99
  - lib/handlebarsjs/helpers/array/join.rb
99
100
  - lib/handlebarsjs/helpers/array/join_post.rb
100
101
  - lib/handlebarsjs/helpers/array/join_pre.rb
@@ -102,6 +103,7 @@ files:
102
103
  - lib/handlebarsjs/helpers/case/camel.rb
103
104
  - lib/handlebarsjs/helpers/case/constant.rb
104
105
  - lib/handlebarsjs/helpers/case/dash.rb
106
+ - lib/handlebarsjs/helpers/case/default_configuration.rb
105
107
  - lib/handlebarsjs/helpers/case/dot.rb
106
108
  - lib/handlebarsjs/helpers/case/double_colon.rb
107
109
  - lib/handlebarsjs/helpers/case/human.rb
@@ -113,6 +115,7 @@ files:
113
115
  - lib/handlebarsjs/helpers/case/upper.rb
114
116
  - lib/handlebarsjs/helpers/comparison/and.rb
115
117
  - lib/handlebarsjs/helpers/comparison/default.rb
118
+ - lib/handlebarsjs/helpers/comparison/default_configuration.rb
116
119
  - lib/handlebarsjs/helpers/comparison/eq.rb
117
120
  - lib/handlebarsjs/helpers/comparison/gt.rb
118
121
  - lib/handlebarsjs/helpers/comparison/gte.rb
@@ -120,6 +123,7 @@ files:
120
123
  - lib/handlebarsjs/helpers/comparison/lte.rb
121
124
  - lib/handlebarsjs/helpers/comparison/ne.rb
122
125
  - lib/handlebarsjs/helpers/comparison/or.rb
126
+ - lib/handlebarsjs/helpers/inflection/default_configuration.rb
123
127
  - lib/handlebarsjs/helpers/inflection/ordinal.rb
124
128
  - lib/handlebarsjs/helpers/inflection/ordinalize.rb
125
129
  - lib/handlebarsjs/helpers/inflection/pluralize.rb
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # module Handlebarsjs
4
- # class Handlebars
5
-
6
- # end
7
- # end