handlebarsjs 0.4.0 → 0.5.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 +4 -4
- data/CHANGELOG.md +7 -0
- data/lib/handlebarsjs/base_helper.rb +24 -0
- data/lib/handlebarsjs/handlebars_snapshot.rb +15 -5
- data/lib/handlebarsjs/version.rb +1 -1
- data/lib/handlebarsjs.rb +1 -0
- data/package-lock.json +2 -2
- data/package.json +1 -1
- metadata +2 -2
- data/lib/handlebarsjs/helpers/comparison/and.rb +0 -45
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 151163c301c19424a48a278b6685d86f01c9cde58244de9343a17834d40cef3a
|
4
|
+
data.tar.gz: a857eea83005555d1541e623f081950e739d394a3b511de944e62dbd8d4851b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b9f7e84df1bb4afe9c3a651de43f775c27a18072ce060d4045b33b2ed0704f8992491d58c87d2d7b2b9461fdbb0a78167674963e66c1b0c9d2aa3c24ea61d62
|
7
|
+
data.tar.gz: dd8774994fe3dd4b2093d7cdffdf6e708de847c790e9ad44420a65b3b9430dc58369e31f5efe5bb483aa6eb3e560936d26fd07aac4855ece300e0c1c60371b31
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
# [0.4.0](https://github.com/klueless-io/handlebarsjs/compare/v0.3.0...v0.4.0) (2022-07-06)
|
2
|
+
|
3
|
+
|
4
|
+
### Features
|
5
|
+
|
6
|
+
* add handlebars add_helper support ([19a5636](https://github.com/klueless-io/handlebarsjs/commit/19a5636698515c6c3128040d708d54527ba62dec))
|
7
|
+
|
1
8
|
# [0.3.0](https://github.com/klueless-io/handlebarsjs/compare/v0.2.0...v0.3.0) (2022-07-06)
|
2
9
|
|
3
10
|
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Handlebarsjs
|
4
|
+
# Extend base helper for each of your custom handlebars-helpers
|
5
|
+
class BaseHelper
|
6
|
+
# Wrap the parse method in a handlebars context aware block
|
7
|
+
# and return as a lambda/proc so that it is available to the
|
8
|
+
# Handlebars template engine
|
9
|
+
def to_proc
|
10
|
+
->(value, _opts) { wrapper(parse(value)) }
|
11
|
+
end
|
12
|
+
|
13
|
+
# All child classes will generally implement this method
|
14
|
+
def parse(value)
|
15
|
+
value
|
16
|
+
end
|
17
|
+
|
18
|
+
# If you need to wrap the return value in a specific
|
19
|
+
# Handlebars Type, eg. SafeString, then you can override this method
|
20
|
+
def wrapper(value)
|
21
|
+
value
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -22,11 +22,14 @@ module Handlebarsjs
|
|
22
22
|
add_script(name, 'snippet', script: script, path: path)
|
23
23
|
end
|
24
24
|
|
25
|
-
def add_helper(name,
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
25
|
+
def add_helper(name, helper)
|
26
|
+
callback = nil
|
27
|
+
callback = helper if helper.is_a?(Proc)
|
28
|
+
callback = helper.to_proc if callback.nil? && helper.respond_to?(:to_proc)
|
29
|
+
|
30
|
+
raise Handlebarsjs::Error, 'helper must be a callback or implement to_proc method' if callback.nil?
|
31
|
+
|
32
|
+
add_helper_callback(name, callback)
|
30
33
|
end
|
31
34
|
|
32
35
|
def register_helper(name)
|
@@ -73,6 +76,13 @@ module Handlebarsjs
|
|
73
76
|
add_script_item(name, type, script, path)
|
74
77
|
end
|
75
78
|
|
79
|
+
def add_helper_callback(name, callback)
|
80
|
+
@helpers << {
|
81
|
+
name: name,
|
82
|
+
callback: callback
|
83
|
+
}
|
84
|
+
end
|
85
|
+
|
76
86
|
def add_script_item(name, type, script, path = nil)
|
77
87
|
@snapshot = nil
|
78
88
|
scripts << {
|
data/lib/handlebarsjs/version.rb
CHANGED
data/lib/handlebarsjs.rb
CHANGED
@@ -5,6 +5,7 @@ require_relative 'handlebarsjs/version'
|
|
5
5
|
require_relative 'handlebarsjs/javascript'
|
6
6
|
require_relative 'handlebarsjs/handlebars_snapshot'
|
7
7
|
require_relative 'handlebarsjs/handlebars'
|
8
|
+
require_relative 'handlebarsjs/base_helper'
|
8
9
|
|
9
10
|
module Handlebarsjs
|
10
11
|
HANDLEBARS_LIBRARY_PATH = 'lib/handlebarsjs/javascript/handlebars-4.7.7.js'
|
data/package-lock.json
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
{
|
2
2
|
"name": "handlebarsjs",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.5.0",
|
4
4
|
"lockfileVersion": 2,
|
5
5
|
"requires": true,
|
6
6
|
"packages": {
|
7
7
|
"": {
|
8
8
|
"name": "handlebarsjs",
|
9
|
-
"version": "0.
|
9
|
+
"version": "0.5.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
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: handlebarsjs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Cruwys
|
@@ -71,9 +71,9 @@ files:
|
|
71
71
|
- docs/project-plan/project_in_progress.svg
|
72
72
|
- lib/handlebarsjs.rb
|
73
73
|
- lib/handlebarsjs/api.rb
|
74
|
+
- lib/handlebarsjs/base_helper.rb
|
74
75
|
- lib/handlebarsjs/handlebars.rb
|
75
76
|
- lib/handlebarsjs/handlebars_snapshot.rb
|
76
|
-
- lib/handlebarsjs/helpers/comparison/and.rb
|
77
77
|
- lib/handlebarsjs/javascript.rb
|
78
78
|
- lib/handlebarsjs/javascript/handlebars-4.7.7.js
|
79
79
|
- lib/handlebarsjs/javascript/handlebars-api.js
|
@@ -1,45 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# reference: https://github.com/rails/rails/blob/master/activesupport/lib/active_support/inflector/methods.rb
|
4
|
-
# require 'active_support/core_ext/string'
|
5
|
-
|
6
|
-
# require 'handlebars/helpers/base_helper'
|
7
|
-
|
8
|
-
module Handlebarsjs
|
9
|
-
module Helpers
|
10
|
-
# Comparison helpers, eg. or, and, equal, not equal, less than, greater than etc.
|
11
|
-
module Comparison
|
12
|
-
# And: Block helper that renders a block if **all of** the given values are truthy. If an inverse block is specified it will be rendered when falsy.
|
13
|
-
# < Handlebars::Helpers::BaseHelper
|
14
|
-
class And
|
15
|
-
# Parse will And: Block helper that renders a block if **all of** the given values are truthy. If an inverse block is specified it will be rendered when falsy.
|
16
|
-
#
|
17
|
-
# @example
|
18
|
-
#
|
19
|
-
# {{#if (and p1 p2 p3 p4 p5)}}
|
20
|
-
# found
|
21
|
-
# {{/if}}
|
22
|
-
#
|
23
|
-
# @example
|
24
|
-
#
|
25
|
-
# @example
|
26
|
-
# {{#if (and name age)}}
|
27
|
-
# {{name}}-{{age}}
|
28
|
-
# {{else}}
|
29
|
-
# no name or age
|
30
|
-
# {{/if}}
|
31
|
-
#
|
32
|
-
# @param values list of values (via *splat) to be checked via AND condition
|
33
|
-
# @return [String] return block when every value is truthy
|
34
|
-
def parse(values)
|
35
|
-
values.all? { |value| value }
|
36
|
-
end
|
37
|
-
|
38
|
-
def handlebars_helper
|
39
|
-
# Exclude last paramater which is the context V8::Object
|
40
|
-
proc { |_context, *values| wrapper(parse(values[0..-2])) }
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|