handlebars-helpers 0.0.71 → 0.0.77
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.handlebars_helpers.json +20 -0
- data/README.md +3 -1
- data/STORIES.md +1 -1
- data/USAGE.md +1 -1
- data/handlebars-helpers.gemspec +13 -7
- data/lib/handlebars/helpers.rb +2 -0
- data/lib/handlebars/helpers/misc/json.rb +99 -0
- data/lib/handlebars/helpers/statistics.rb +9 -0
- data/lib/handlebars/helpers/version.rb +1 -1
- metadata +16 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef6712aacb680e54f0ef3127506c404319ce38bec06bf00f7f1a7d082cfc7d87
|
4
|
+
data.tar.gz: 181568f89da2c8c78121d8e8e2777906dacd3c714bef1af165cc006022fdacc3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff8f9e14297e84a9b42e2c020de73ac1e65ff4d69d3eb6a72f11bad76d3d66eb914cb6a05ac8767f537055d552161dba053ee0ae75b3a62e1d3449a11396347a
|
7
|
+
data.tar.gz: 25c0733abc52e39a5d46b1234b2d07226f5fdad40e2499d7b2acfc2271260ef6642561e41175edf2ce58e402306ec4984bc8fc5e48458d6b058ef2bcac419178
|
data/.handlebars_helpers.json
CHANGED
@@ -364,6 +364,26 @@
|
|
364
364
|
"https://github.com/helpers/handlebars-helpers/blob/master/test/misc.js"
|
365
365
|
],
|
366
366
|
"helpers": [
|
367
|
+
{
|
368
|
+
"name": "json",
|
369
|
+
"description": "value as JSON string",
|
370
|
+
"test_in": null,
|
371
|
+
"test_out": null,
|
372
|
+
"tests": [
|
373
|
+
{
|
374
|
+
"alias": "json",
|
375
|
+
"expected_value": "{ \"david\": \"was here\" }",
|
376
|
+
"params": [
|
377
|
+
{ "name": "value", "value": "{ \"david\": \"was here\" }" }
|
378
|
+
],
|
379
|
+
"template": "{{json value}}"
|
380
|
+
}
|
381
|
+
],
|
382
|
+
"aliases": ["json"],
|
383
|
+
"require_path": "handlebars/helpers/misc/json",
|
384
|
+
"class_namespace": "Handlebars::Helpers::Misc::Json",
|
385
|
+
"is_string_formatter": null
|
386
|
+
},
|
367
387
|
{
|
368
388
|
"name": "safe",
|
369
389
|
"description": "value in safe string format",
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Handlebars Helpers
|
2
2
|
|
3
|
-
> Handlebars Helpers is a library that provides <b
|
3
|
+
> Handlebars Helpers is a library that provides <b>42</b> handlebars helpers across <b>5</b> categories, it was built to complement [cowboyd/handlebars.rb](https://github.com/cowboyd/handlebars.rb) with Ruby helpers commonly found in the Javascript community
|
4
4
|
|
5
5
|
This GEM is inspired by the Javascript Library [handlebars-helpers](https://github.com/helpers/handlebars-helpers).
|
6
6
|
|
@@ -76,6 +76,8 @@ To release a new version, update the version number in `version.rb`, build the g
|
|
76
76
|
```bash
|
77
77
|
gem build
|
78
78
|
gem push rspec-usecases-?.?.??.gem
|
79
|
+
# or push the latest gem
|
80
|
+
ls *.gem | sort -r | head -1 | xargs gem push
|
79
81
|
```
|
80
82
|
|
81
83
|
## Contributing
|
data/STORIES.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Handlebars Helpers
|
2
2
|
|
3
|
-
> Handlebars Helpers is a library that provides <b>
|
3
|
+
> Handlebars Helpers is a library that provides <b>42</b> handlebars helpers across <b>5</b> categories, it was built to complement [cowboyd/handlebars.rb](https://github.com/cowboyd/handlebars.rb) with Ruby helpers commonly found in the Javascript community
|
4
4
|
|
5
5
|
As a Ruby Developer, I want to use HandlebarsJS with useful helpers, so that I have a rich templating experience
|
6
6
|
|
data/USAGE.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Handlebars Helpers
|
2
2
|
|
3
|
-
> Handlebars Helpers is a library that provides <b>
|
3
|
+
> Handlebars Helpers is a library that provides <b>42</b> handlebars helpers across <b>5</b> categories, it was built to complement [cowboyd/handlebars.rb](https://github.com/cowboyd/handlebars.rb) with Ruby helpers commonly found in the Javascript community
|
4
4
|
|
5
5
|
As a Ruby Developer, I want to use HandlebarsJS with useful helpers, so that I have a rich templating experience
|
6
6
|
|
data/handlebars-helpers.gemspec
CHANGED
@@ -1,18 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative 'lib/handlebars/helpers/version'
|
4
|
+
require_relative 'lib/handlebars/helpers/statistics'
|
4
5
|
|
5
6
|
Gem::Specification.new do |spec|
|
7
|
+
description = "Handlebars Helpers provides (#{Handlebars::Helpers::HANDLER_COUNT}) handlebars helpers across (#{Handlebars::Helpers::CATEGORY_COUNT}) categories"
|
8
|
+
|
6
9
|
spec.required_ruby_version = '>= 2.5'
|
7
10
|
spec.name = 'handlebars-helpers'
|
8
11
|
spec.version = Handlebars::Helpers::VERSION
|
9
12
|
spec.authors = ['David Cruwys']
|
10
13
|
spec.email = ['david@ideasmen.com.au']
|
11
14
|
|
12
|
-
spec.summary =
|
13
|
-
spec.description =
|
14
|
-
Handlebars Helpers provides (Nx) handlebars helpers across (Ny) categories
|
15
|
-
TEXT
|
15
|
+
spec.summary = description
|
16
|
+
spec.description = description
|
16
17
|
spec.homepage = 'http://appydave.com/gems/handlebars-helpers'
|
17
18
|
spec.license = 'MIT'
|
18
19
|
|
@@ -25,6 +26,7 @@ Gem::Specification.new do |spec|
|
|
25
26
|
spec.metadata['homepage_uri'] = spec.homepage
|
26
27
|
spec.metadata['source_code_uri'] = 'https://github.com/klueless-io/handlebars-helpers'
|
27
28
|
spec.metadata['changelog_uri'] = 'https://github.com/klueless-io/handlebars-helpers/commits/master'
|
29
|
+
spec.metadata['documentation_uri'] = 'https://rubydoc.info/github/klueless-io/handlebars-helpers/master'
|
28
30
|
|
29
31
|
# Specify which files should be added to the gem when it is released.
|
30
32
|
# The `git ls-files -z` loads the RubyGem files that have been added into git.
|
@@ -33,6 +35,10 @@ Gem::Specification.new do |spec|
|
|
33
35
|
f.match(%r{^(test|spec|features)/})
|
34
36
|
end
|
35
37
|
end
|
38
|
+
|
39
|
+
# spec.files.each do |file|
|
40
|
+
# puts file
|
41
|
+
# end
|
36
42
|
spec.bindir = 'exe'
|
37
43
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
38
44
|
spec.require_paths = ['lib']
|
@@ -41,10 +47,10 @@ Gem::Specification.new do |spec|
|
|
41
47
|
spec.rdoc_options += [
|
42
48
|
'--title', 'handlebars-helpers by appydave.com',
|
43
49
|
'--main', 'README.md',
|
44
|
-
'--files
|
50
|
+
'--files STORIES.MD USAGE.MD'
|
45
51
|
]
|
46
52
|
|
47
53
|
# spec.add_dependency 'tty-box', '~> 0.5.0'
|
48
|
-
spec.add_dependency 'activesupport'
|
49
|
-
spec.add_dependency 'handlebars'
|
54
|
+
spec.add_dependency 'activesupport' , '~> 6'
|
55
|
+
spec.add_dependency 'handlebars' , '~> 0.8.0'
|
50
56
|
end
|
data/lib/handlebars/helpers.rb
CHANGED
@@ -3,6 +3,8 @@
|
|
3
3
|
require 'handlebars/helpers/version'
|
4
4
|
require 'handlebars/helpers/template'
|
5
5
|
require 'handlebars/helpers/register_helpers'
|
6
|
+
# ruby docs is not showing all classes because
|
7
|
+
# this gem dynamically loads the classes for performance reasons
|
6
8
|
|
7
9
|
module Handlebars
|
8
10
|
module Helpers
|
@@ -0,0 +1,99 @@
|
|
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_safe_string_helper'
|
7
|
+
|
8
|
+
module Handlebars
|
9
|
+
module Helpers
|
10
|
+
# Miscellaneous handling routines
|
11
|
+
module Misc
|
12
|
+
# Json will take handlebars object and write it out as JSON
|
13
|
+
class Json < Handlebars::Helpers::BaseSafeStringHelper
|
14
|
+
# Parse will take a ruby or handlebars object and write it out as JSON
|
15
|
+
#
|
16
|
+
# @example
|
17
|
+
#
|
18
|
+
# puts Json.new.parse({david: "was here", why: ['reason1', 'reason2', 'reason3']})
|
19
|
+
#
|
20
|
+
# { "david": "was here" }
|
21
|
+
#
|
22
|
+
# @param [Object] value - object to be converted to JSON string
|
23
|
+
# @return [String] value as JSON string
|
24
|
+
def parse(value)
|
25
|
+
value = '' if value.nil?
|
26
|
+
|
27
|
+
value = parse_json(value).to_json if value.is_a?(Hash) || value.is_a?(OpenStruct) || value.is_a?(V8::Object) || value.is_a?(V8::Array)
|
28
|
+
|
29
|
+
value
|
30
|
+
end
|
31
|
+
|
32
|
+
def handlebars_helper
|
33
|
+
proc do |_context, value|
|
34
|
+
# Handle optional: value
|
35
|
+
# value = nil if value.is_a?(V8::Object)
|
36
|
+
wrapper(parse(value))
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
# This needs to be in a data_helper
|
43
|
+
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Style/HashEachMethods
|
44
|
+
def parse_json(value, hash = {})
|
45
|
+
return value.map { |item| parse_json(item) } if value.is_a?(V8::Array)
|
46
|
+
|
47
|
+
return struct_to_hash(value) if value.is_a?(OpenStruct)
|
48
|
+
|
49
|
+
return value unless value.is_a?(V8::Object)
|
50
|
+
|
51
|
+
value.keys.each do |key|
|
52
|
+
hash[key] = case value[key]
|
53
|
+
when V8::Object
|
54
|
+
parse_json(value[key])
|
55
|
+
when V8::Array
|
56
|
+
value[key].map do |item|
|
57
|
+
case item
|
58
|
+
when V8::Object, V8::Array
|
59
|
+
parse_json(item)
|
60
|
+
when String
|
61
|
+
item
|
62
|
+
else
|
63
|
+
item.values
|
64
|
+
end
|
65
|
+
end
|
66
|
+
else
|
67
|
+
value[key]
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
hash
|
72
|
+
end
|
73
|
+
# rubocop:enable Metrics/PerceivedComplexity, Style/HashEachMethods
|
74
|
+
|
75
|
+
# Needs to move into a GEM and make sure I have consistency
|
76
|
+
def struct_to_hash(data)
|
77
|
+
# No test yet
|
78
|
+
if data.is_a?(Array)
|
79
|
+
return data.map { |v| v.is_a?(OpenStruct) ? struct_to_hash(v) : v }
|
80
|
+
end
|
81
|
+
|
82
|
+
data.each_pair.with_object({}) do |(key, value), hash|
|
83
|
+
case value
|
84
|
+
when OpenStruct
|
85
|
+
hash[key] = struct_to_hash(value)
|
86
|
+
when Array
|
87
|
+
# No test yet
|
88
|
+
values = value.map { |v| v.is_a?(OpenStruct) ? struct_to_hash(v) : v }
|
89
|
+
hash[key] = values
|
90
|
+
else
|
91
|
+
hash[key] = value
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
metadata
CHANGED
@@ -1,45 +1,44 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: handlebars-helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.77
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Cruwys
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-02
|
11
|
+
date: 2021-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '6'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '6'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: handlebars
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 0.8.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
41
|
-
description:
|
42
|
-
categories\n"
|
40
|
+
version: 0.8.0
|
41
|
+
description: Handlebars Helpers provides (42) handlebars helpers across (5) categories
|
43
42
|
email:
|
44
43
|
- david@ideasmen.com.au
|
45
44
|
executables: []
|
@@ -96,9 +95,11 @@ files:
|
|
96
95
|
- lib/handlebars/helpers/inflection/pluralize.rb
|
97
96
|
- lib/handlebars/helpers/inflection/pluralize_by_number.rb
|
98
97
|
- lib/handlebars/helpers/inflection/singularize.rb
|
98
|
+
- lib/handlebars/helpers/misc/json.rb
|
99
99
|
- lib/handlebars/helpers/misc/noop.rb
|
100
100
|
- lib/handlebars/helpers/misc/safe.rb
|
101
101
|
- lib/handlebars/helpers/register_helpers.rb
|
102
|
+
- lib/handlebars/helpers/statistics.rb
|
102
103
|
- lib/handlebars/helpers/string_formatting/append_if.rb
|
103
104
|
- lib/handlebars/helpers/string_formatting/back_slash.rb
|
104
105
|
- lib/handlebars/helpers/string_formatting/camel.rb
|
@@ -132,14 +133,14 @@ metadata:
|
|
132
133
|
homepage_uri: http://appydave.com/gems/handlebars-helpers
|
133
134
|
source_code_uri: https://github.com/klueless-io/handlebars-helpers
|
134
135
|
changelog_uri: https://github.com/klueless-io/handlebars-helpers/commits/master
|
136
|
+
documentation_uri: https://rubydoc.info/github/klueless-io/handlebars-helpers/master
|
135
137
|
post_install_message:
|
136
138
|
rdoc_options:
|
137
139
|
- "--title"
|
138
140
|
- handlebars-helpers by appydave.com
|
139
141
|
- "--main"
|
140
142
|
- README.md
|
141
|
-
- "--files"
|
142
|
-
- STORIES.MD USAGE.MD
|
143
|
+
- "--files STORIES.MD USAGE.MD"
|
143
144
|
require_paths:
|
144
145
|
- lib
|
145
146
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -156,5 +157,5 @@ requirements: []
|
|
156
157
|
rubygems_version: 3.2.7
|
157
158
|
signing_key:
|
158
159
|
specification_version: 4
|
159
|
-
summary: Handlebars Helpers provides (
|
160
|
+
summary: Handlebars Helpers provides (42) handlebars helpers across (5) categories
|
160
161
|
test_files: []
|