handlebarsjs 0.5.5 → 0.6.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: 54e7659dac2a8cf398062a6d60ab21cb9532fd1f5bdac94d8b1ba203b0f69718
4
- data.tar.gz: 2af427025be5ca3b734be0bb3d184d9bdc17d7fe56e6a6ef2bcd7cdc6d59750e
3
+ metadata.gz: be20a900e92e33b726da6c5807cba1e183e15c3642fc75493370230ef7f04326
4
+ data.tar.gz: '069b8b8358aefa0b753d55883e1c52b53698d94dcf7c9660a019f7d3713789b3'
5
5
  SHA512:
6
- metadata.gz: 3d180450d15b7d6a700189d147e850466e78d8252fe0d4bed01e335cd294a2cda3f2bd206bc8bc34cfd334c2f102c28e50862d10846f55e47d9d4fcca2019827
7
- data.tar.gz: 51d88ab43e2a2c5c3bc80a453dcf9178d1c39859bdb5540d86bb667032f2ec197d0eb64a6cdf6861464296591e570df64cd7a13eb458d1cdafa274cd90acb557
6
+ metadata.gz: 79cf9b5f22b8d20fab6d626c11ebedb8d31a52d0c7122f9587d86bd925b3792a9af91aad2ea27d29d360414f91710a9f85ac7e4f3191cd95dda8c6f514c28fa8
7
+ data.tar.gz: d29ad4299dc2d9579dd2e31ffbb2abc653fe4d65b9f2ed013e67f0cc20801ca1a8e0d39e72e61ef0b5118bdcb05c5a4c5181f1a293f88bc03400199f2d32cac6
data/CHANGELOG.md CHANGED
@@ -1,3 +1,24 @@
1
+ ## [0.5.7](https://github.com/klueless-io/handlebarsjs/compare/v0.5.6...v0.5.7) (2022-07-13)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * add catgegory default configurations ([8046805](https://github.com/klueless-io/handlebarsjs/commit/80468055f94e36ea682dbbfd26e7eb527db9ff82))
7
+
8
+ ## [0.5.6](https://github.com/klueless-io/handlebarsjs/compare/v0.5.5...v0.5.6) (2022-07-13)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * add configuration capability to handlebars_snapshot ([06f7ca6](https://github.com/klueless-io/handlebarsjs/commit/06f7ca628018d4a89c9b068c8cae4565a624a3db))
14
+
15
+ ## [0.5.5](https://github.com/klueless-io/handlebarsjs/compare/v0.5.4...v0.5.5) (2022-07-12)
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * add configuration ([ab16612](https://github.com/klueless-io/handlebarsjs/commit/ab16612500b1cf61094b128e14fcecbe1aacde5b))
21
+
1
22
  ## [0.5.4](https://github.com/klueless-io/handlebarsjs/compare/v0.5.3...v0.5.4) (2022-07-12)
2
23
 
3
24
 
@@ -5,6 +5,19 @@ module Handlebarsjs
5
5
  class Handlebars < Handlebarsjs::Javascript
6
6
  def initialize
7
7
  super
8
+
9
+ add_libraries
10
+ add_configured_helpers
11
+ end
12
+
13
+ def process_template(template, options = {})
14
+ # TODO: process template function may be improved with some type of caching
15
+ context.call('process_template', template, options)
16
+ end
17
+
18
+ private
19
+
20
+ def add_libraries
8
21
  # Handlebars 4.7.7
9
22
  gem_path = Gem.loaded_specs['handlebarsjs'].full_gem_path
10
23
 
@@ -17,9 +30,10 @@ module Handlebarsjs
17
30
  handlebars_snapshot.add_library('handlebars-api', path: handlebars_api_path)
18
31
  end
19
32
 
20
- def process_template(template, options = {})
21
- # TODO: process template function may be improved with some type of caching
22
- context.call('process_template', template, options)
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
23
37
  end
24
38
  end
25
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.5'
4
+ VERSION = '0.6.0'
5
5
  end
data/lib/handlebarsjs.rb CHANGED
@@ -10,6 +10,7 @@ require_relative 'handlebarsjs/handlebars'
10
10
  require_relative 'handlebarsjs/base_helper'
11
11
  require_relative '_'
12
12
 
13
+ # Handlebarsjs is a Ruby wrapper for the Handlebars.js templating engine.
13
14
  module Handlebarsjs
14
15
  HANDLEBARS_LIBRARY_PATH = 'lib/handlebarsjs/javascript/handlebars-4.7.7.js'
15
16
  HANDLEBARS_API_PATH = 'lib/handlebarsjs/javascript/handlebars-api.js'
@@ -17,7 +18,27 @@ module Handlebarsjs
17
18
  # raise Handlebarsjs::Error, 'Sample message'
18
19
  Error = Class.new(StandardError)
19
20
 
20
- # 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 render(template, options = {})
39
+ @engine.process_template(template, options)
40
+ end
41
+ end
21
42
  end
22
43
 
23
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.5",
3
+ "version": "0.6.0",
4
4
  "lockfileVersion": 2,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "handlebarsjs",
9
- "version": "0.5.5",
9
+ "version": "0.6.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.5.5",
3
+ "version": "0.6.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.5.5
4
+ version: 0.6.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-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
@@ -95,6 +95,7 @@ files:
95
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