handlebars-helpers 0.0.5 → 0.0.73

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.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +2 -3
  3. data/.gitignore +1 -0
  4. data/.handlebars_helpers.json +956 -0
  5. data/.handlebars_string_formatters.json +137 -0
  6. data/.rubocop.yml +4 -2
  7. data/.vscode/settings.json +6 -0
  8. data/Gemfile +3 -0
  9. data/README.md +31 -3
  10. data/Rakefile +1 -0
  11. data/STORIES.md +55 -7
  12. data/USAGE.md +1 -1
  13. data/bin/console +1 -1
  14. data/handlebars-helpers.gemspec +10 -1
  15. data/lib/handlebars/helpers.rb +2 -0
  16. data/lib/handlebars/helpers/base_helper.rb +36 -0
  17. data/lib/handlebars/helpers/base_safe_string_helper.rb +17 -0
  18. data/lib/handlebars/helpers/code_ruby/classify.rb +40 -0
  19. data/lib/handlebars/helpers/code_ruby/deconstantize.rb +48 -0
  20. data/lib/handlebars/helpers/code_ruby/demodulize.rb +58 -0
  21. data/lib/handlebars/helpers/code_ruby/foreign_key.rb +49 -0
  22. data/lib/handlebars/helpers/code_ruby/tableize.rb +35 -0
  23. data/lib/handlebars/helpers/comparison/and.rb +44 -0
  24. data/lib/handlebars/helpers/comparison/default.rb +66 -0
  25. data/lib/handlebars/helpers/comparison/eq.rb +35 -0
  26. data/lib/handlebars/helpers/comparison/gt.rb +35 -0
  27. data/lib/handlebars/helpers/comparison/gte.rb +43 -0
  28. data/lib/handlebars/helpers/comparison/lt.rb +35 -0
  29. data/lib/handlebars/helpers/comparison/lte.rb +43 -0
  30. data/lib/handlebars/helpers/comparison/ne.rb +35 -0
  31. data/lib/handlebars/helpers/comparison/or.rb +56 -0
  32. data/lib/handlebars/helpers/configuration.rb +72 -0
  33. data/lib/handlebars/helpers/inflection/ordinal.rb +58 -0
  34. data/lib/handlebars/helpers/inflection/ordinalize.rb +59 -0
  35. data/lib/handlebars/helpers/inflection/pluralize.rb +36 -0
  36. data/lib/handlebars/helpers/inflection/pluralize_by_number.rb +60 -0
  37. data/lib/handlebars/helpers/inflection/singularize.rb +35 -0
  38. data/lib/handlebars/helpers/misc/noop.rb +36 -0
  39. data/lib/handlebars/helpers/misc/safe.rb +37 -0
  40. data/lib/handlebars/helpers/register_helpers.rb +73 -0
  41. data/lib/handlebars/helpers/string_formatting/append_if.rb +42 -0
  42. data/lib/handlebars/helpers/string_formatting/back_slash.rb +33 -0
  43. data/lib/handlebars/helpers/string_formatting/camel.rb +29 -0
  44. data/lib/handlebars/helpers/string_formatting/constantize.rb +29 -0
  45. data/lib/handlebars/helpers/string_formatting/dasherize.rb +33 -0
  46. data/lib/handlebars/helpers/string_formatting/dotirize.rb +33 -0
  47. data/lib/handlebars/helpers/string_formatting/double_colon.rb +33 -0
  48. data/lib/handlebars/helpers/string_formatting/downcase.rb +31 -0
  49. data/lib/handlebars/helpers/string_formatting/format_as.rb +57 -0
  50. data/lib/handlebars/helpers/string_formatting/humanize.rb +39 -0
  51. data/lib/handlebars/helpers/string_formatting/lamel.rb +29 -0
  52. data/lib/handlebars/helpers/string_formatting/padl.rb +58 -0
  53. data/lib/handlebars/helpers/string_formatting/padr.rb +59 -0
  54. data/lib/handlebars/helpers/string_formatting/pluserize.rb +29 -0
  55. data/lib/handlebars/helpers/string_formatting/prepend_if.rb +42 -0
  56. data/lib/handlebars/helpers/string_formatting/singularize.rb +35 -0
  57. data/lib/handlebars/helpers/string_formatting/slash.rb +33 -0
  58. data/lib/handlebars/helpers/string_formatting/snake.rb +33 -0
  59. data/lib/handlebars/helpers/string_formatting/string.js +511 -0
  60. data/lib/handlebars/helpers/string_formatting/surround.rb +49 -0
  61. data/lib/handlebars/helpers/string_formatting/surround_if.rb +43 -0
  62. data/lib/handlebars/helpers/string_formatting/titleize.rb +39 -0
  63. data/lib/handlebars/helpers/string_formatting/upcase.rb +31 -0
  64. data/lib/handlebars/helpers/string_tokenizer.rb +43 -0
  65. data/lib/handlebars/helpers/template.rb +68 -0
  66. data/lib/handlebars/helpers/version.rb +1 -1
  67. metadata +97 -6
@@ -0,0 +1,137 @@
1
+ {
2
+ "formatters": [
3
+ {
4
+ "name": "ordinalize",
5
+ "description": "number value turned to 1st, 2nd, 3rd, 4th etc.",
6
+ "aliases": ["ordinalize"],
7
+ "class_namespace": "Handlebars::Helpers::Inflection::Ordinalize",
8
+ "require_path": "handlebars/helpers/inflection/ordinalize"
9
+ },
10
+ {
11
+ "name": "ordinal",
12
+ "description": "ordinal suffix that would be required for a number, eg. st, nd, rd, th",
13
+ "aliases": ["ordinal"],
14
+ "class_namespace": "Handlebars::Helpers::Inflection::Ordinal",
15
+ "require_path": "handlebars/helpers/inflection/ordinal"
16
+ },
17
+ {
18
+ "name": "pluralize",
19
+ "description": "singular value is converted to plural form",
20
+ "aliases": ["pluralize", "plural"],
21
+ "class_namespace": "Handlebars::Helpers::Inflection::Pluralize",
22
+ "require_path": "handlebars/helpers/inflection/pluralize"
23
+ },
24
+ {
25
+ "name": "singularize",
26
+ "description": "plural value is converted to singular from",
27
+ "aliases": ["singularize", "singular"],
28
+ "class_namespace": "Handlebars::Helpers::Inflection::Singularize",
29
+ "require_path": "handlebars/helpers/inflection/singularize"
30
+ },
31
+ {
32
+ "name": "tableize",
33
+ "description": "creates the name of a table like Rails does when converting models to table names",
34
+ "aliases": ["tableize"],
35
+ "class_namespace": "Handlebars::Helpers::CodeRuby::Tableize",
36
+ "require_path": "handlebars/helpers/code_ruby/tableize"
37
+ },
38
+ {
39
+ "name": "back_slash",
40
+ "description": "convert to back slash notation",
41
+ "aliases": ["back_slash", "backward_slash", "slash_backward"],
42
+ "class_namespace": "Handlebars::Helpers::StringFormatting::BackSlash",
43
+ "require_path": "handlebars/helpers/string_formatting/back_slash"
44
+ },
45
+ {
46
+ "name": "camel",
47
+ "description": "convert to camel case with first word uppercase and following words uppercase",
48
+ "aliases": ["camel", "camel_upper", "camelUpper", "camelU", "pascalcase"],
49
+ "class_namespace": "Handlebars::Helpers::StringFormatting::Camel",
50
+ "require_path": "handlebars/helpers/string_formatting/camel"
51
+ },
52
+ {
53
+ "name": "constantize",
54
+ "description": "convert to constant case",
55
+ "aliases": ["constantize", "constant"],
56
+ "class_namespace": "Handlebars::Helpers::StringFormatting::Constantize",
57
+ "require_path": "handlebars/helpers/string_formatting/constantize"
58
+ },
59
+ {
60
+ "name": "dasherize",
61
+ "description": "convert to dash notation",
62
+ "aliases": ["dasherize", "dashify", "dashcase", "hyphenate"],
63
+ "class_namespace": "Handlebars::Helpers::StringFormatting::Dasherize",
64
+ "require_path": "handlebars/helpers/string_formatting/dasherize"
65
+ },
66
+ {
67
+ "name": "dotirize",
68
+ "description": "convert to dash notation",
69
+ "aliases": ["dotirize", "dotify", "dotcase"],
70
+ "class_namespace": "Handlebars::Helpers::StringFormatting::Dotirize",
71
+ "require_path": "handlebars/helpers/string_formatting/dotirize"
72
+ },
73
+ {
74
+ "name": "double_colon",
75
+ "description": "double_colon notation, similar to ruby namespace",
76
+ "aliases": ["double_colon"],
77
+ "class_namespace": "Handlebars::Helpers::StringFormatting::DoubleColon",
78
+ "require_path": "handlebars/helpers/string_formatting/double_colon"
79
+ },
80
+ {
81
+ "name": "downcase",
82
+ "description": "convert all characters to lower case",
83
+ "aliases": ["downcase", "lowercase"],
84
+ "class_namespace": "Handlebars::Helpers::StringFormatting::Downcase",
85
+ "require_path": "handlebars/helpers/string_formatting/downcase"
86
+ },
87
+ {
88
+ "name": "humanize",
89
+ "description": "convert text to human case, aka capitalize",
90
+ "aliases": ["humanize", "capitalize"],
91
+ "class_namespace": "Handlebars::Helpers::StringFormatting::Humanize",
92
+ "require_path": "handlebars/helpers/string_formatting/humanize"
93
+ },
94
+ {
95
+ "name": "lamel",
96
+ "description": "convert to lamel case with first word lowercase and following words uppercase",
97
+ "aliases": ["lamel", "camel_lower", "camelLower", "camelL"],
98
+ "class_namespace": "Handlebars::Helpers::StringFormatting::Lamel",
99
+ "require_path": "handlebars/helpers/string_formatting/lamel"
100
+ },
101
+ {
102
+ "name": "pluserize",
103
+ "description": "convert to plus notation",
104
+ "aliases": ["pluserize", "plusify", "pluscase"],
105
+ "class_namespace": "Handlebars::Helpers::StringFormatting::Pluserize",
106
+ "require_path": "handlebars/helpers/string_formatting/pluserize"
107
+ },
108
+ {
109
+ "name": "slash",
110
+ "description": "convert to slash notation, aka forward slash",
111
+ "aliases": ["slash", "forward_slash", "slash_forward"],
112
+ "class_namespace": "Handlebars::Helpers::StringFormatting::Slash",
113
+ "require_path": "handlebars/helpers/string_formatting/slash"
114
+ },
115
+ {
116
+ "name": "snake",
117
+ "description": "convert to snake notation",
118
+ "aliases": ["snake"],
119
+ "class_namespace": "Handlebars::Helpers::StringFormatting::Snake",
120
+ "require_path": "handlebars/helpers/string_formatting/snake"
121
+ },
122
+ {
123
+ "name": "titleize",
124
+ "description": "value converted to titleize case, aka heading case",
125
+ "aliases": ["titleize", "heading", "capitalize_all"],
126
+ "class_namespace": "Handlebars::Helpers::StringFormatting::Titleize",
127
+ "require_path": "handlebars/helpers/string_formatting/titleize"
128
+ },
129
+ {
130
+ "name": "upcase",
131
+ "description": "convert all characters to lower case",
132
+ "aliases": ["upcase", "uppercase"],
133
+ "class_namespace": "Handlebars::Helpers::StringFormatting::Upcase",
134
+ "require_path": "handlebars/helpers/string_formatting/upcase"
135
+ }
136
+ ]
137
+ }
data/.rubocop.yml CHANGED
@@ -1,3 +1,4 @@
1
+ require: rubocop-rake
1
2
  inherit_from: .rubocop_todo.yml
2
3
 
3
4
  AllCops:
@@ -10,9 +11,9 @@ AllCops:
10
11
 
11
12
  Metrics/BlockLength:
12
13
  Exclude:
13
- - "**/spec/*"
14
+ - "**/spec/**/*"
14
15
  - "*.gemspec"
15
- ExcludedMethods:
16
+ IgnoredMethods:
16
17
  - configure
17
18
  - context
18
19
  - define
@@ -77,3 +78,4 @@ Style/AccessorGrouping:
77
78
  Layout/SpaceBeforeComma:
78
79
  Enabled: false
79
80
  # My Preferences - End
81
+
@@ -0,0 +1,6 @@
1
+ {
2
+ "cSpell.words": [
3
+ "dashcase",
4
+ "dotcase"
5
+ ]
6
+ }
data/Gemfile CHANGED
@@ -17,8 +17,11 @@ group :development, :test do
17
17
  gem 'guard-rspec'
18
18
  gem 'guard-rubocop'
19
19
  gem 'rake', '~> 12.0'
20
+ gem 'rake-compiler', require: false
20
21
  gem 'rspec', '~> 3.0'
21
22
  gem 'rubocop'
23
+ gem 'rubocop-rake', require: false
24
+ gem 'rubocop-rspec', require: false
22
25
  end
23
26
 
24
27
  # # Temporary path:
data/README.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # Handlebars Helpers
2
2
 
3
- > Handlebars Helpers is a library that provides (x) handlebars helpers across (y) categories, it was built to complement [cowboyd/handlebars.rb](https://github.com/cowboyd/handlebars.rb) with Ruby helpers commonly found in the Javascript community
3
+ > Handlebars Helpers is a library that provides <b>$HELPER_COUNT$</b> handlebars helpers across <b>$HELPER_CATEGORY_COUNT$</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
+
5
+ This GEM is inspired by the Javascript Library [handlebars-helpers](https://github.com/helpers/handlebars-helpers).
6
+
7
+ I am following a lot of the categories found there, but this GEM is not a one for one match to the existing JS library as I feel it is a bit dated and could use some new helpers and categories may be relevant today.
4
8
 
5
9
  ## Installation
6
10
 
@@ -46,11 +50,35 @@ class SomeRuby; end
46
50
 
47
51
  ## Development
48
52
 
49
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
53
+ Checkout the repo
54
+
55
+ ```bash
56
+ git clone klueless-io/handlebars-helpers
57
+ ```
58
+
59
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests.
60
+
61
+ You can also run `bin/console` for an interactive prompt that will allow you to experiment.
62
+
63
+ ```bash
64
+ bin/console
65
+
66
+ Handlebars::Helpers::Template.render('{{camel .}}', 'david was here')
67
+ # => "DavidWasHere"
68
+ Handlebars::Helpers::Template.render('{{dasherize .}}', 'david was here')
69
+ # => "david-was-here"
70
+ ```
50
71
 
51
72
  `handlebars-helpers` is setup with Guard, run `guard`, this will watch development file changes and run tests automatically, if successful, it will then run rubocop for style quality.
52
73
 
53
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
74
+ To release a new version, update the version number in `version.rb`, build the gem and push the `.gem` file to [rubygems.org](https://rubygems.org).
75
+
76
+ ```bash
77
+ gem build
78
+ gem push rspec-usecases-?.?.??.gem
79
+ # or push the latest gem
80
+ ls *.gem | sort -r | head -1 | xargs gem push
81
+ ```
54
82
 
55
83
  ## Contributing
56
84
 
data/Rakefile CHANGED
@@ -7,6 +7,7 @@ RSpec::Core::RakeTask.new(:spec)
7
7
 
8
8
  require 'rake/extensiontask'
9
9
 
10
+ desc 'Compile all the extensions'
10
11
  task build: :compile
11
12
 
12
13
  Rake::ExtensionTask.new('handlebars_helpers') do |ext|
data/STORIES.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Handlebars Helpers
2
2
 
3
- > Handlebars Helpers is a library that provides (x) handlebars helpers across (y) categories, it was built to complement [cowboyd/handlebars.rb](https://github.com/cowboyd/handlebars.rb) with Ruby helpers commonly found in the Javascript community
3
+ > Handlebars Helpers is a library that provides <b>5</b> handlebars helpers across <b>42</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
 
@@ -8,10 +8,41 @@ As a Ruby Developer, I want to use HandlebarsJS with useful helpers, so that I h
8
8
 
9
9
  ### Stories next on list
10
10
 
11
+ As a Documentor, I can create usage examples for this GEM, so that I can document the project
12
+
13
+ - setup rspec-usage for the project
14
+ - create templates for generating slide decks
15
+ - record videos on how to use
16
+
17
+ As a Developer, I can release a new version of the GEM, so that the updated Gem appears on rubygems and rubydoc
18
+
19
+ - gem release
20
+ - research automated solution, eg. rake
21
+ - implement the solution
22
+
23
+ As a Developer, I have flexible and modular formatters, so that I can format data into a new format
24
+
25
+ - Define formatter categories, https://github.com/helpers/handlebars-helpers has 20 categories
26
+ - Create modular formatters with tests
27
+
28
+ ### Tasks next on list
29
+
30
+ add support for string_formatter usage via STRING_FORMATTER.md
31
+
32
+ add gem release rake task
33
+
34
+ add support for category and helper count to readme.md
35
+
36
+ ## Stories and tasks
37
+
38
+ ### Stories - completed
39
+
11
40
  As a Developer, I can easily render Handlebar Templates, so that I am more efficient
12
41
 
13
42
  - Build simplified API for rendering templates
14
43
 
44
+ As a Developer, I can have string case formatting helpers, so that I can generate code and documentation using handlebars
45
+
15
46
  As a Developer, I can alias existing helpers, so that I have helper names that make sense to me
16
47
 
17
48
  - Provide a flexible mechanism for template aliases
@@ -20,16 +51,33 @@ As a Developer, I can load specific groups of helpers, so that memory consumptio
20
51
 
21
52
  - Lazy load ruby helpers on an as needed basis
22
53
 
23
- ### Tasks next on list
54
+ ### Tasks - completed
24
55
 
25
- Setup RubyGems and RubyDoc
56
+ check camel P02E04 has correct formatting
26
57
 
27
- - Build and deploy gem to rubygems.org
28
- - Attach documentation to [rubydoc.info](https://rubydoc.info/github/klueless-io/handlebars-helpers/master)
58
+ - tested alpha-numeric coded value with word separation (p02_ef4 &gt; P02Ef4)
59
+ - tested alpha-numeric coded value without word separation (p02ef4 &gt; P02ef4)
29
60
 
30
- ## Stories and tasks
61
+ add support for misc helper category
31
62
 
32
- ### Tasks - completed
63
+ - add noop/raw helper
64
+ - add safe helper
65
+
66
+ refactor inflections namespace
67
+
68
+ - Move pluralize and singularize to inflections
69
+ - Add support for ordinalize case, eg. 1st, 2nd, 3rd, 4th
70
+ - Add support for ordinal case, eg. st, nd, rd, th
71
+
72
+ String tokenizer that formats input strings in a consistent fashion
73
+
74
+ - Setup a single opinionated string tokenizer
75
+ - Make the string tokenizer configurable so it can be replaced with a different opinionated tokenizer
76
+
77
+ Setup RubyGems and RubyDoc
78
+
79
+ - Build and deploy gem to [rubygems.org](https://rubygems.org/gems/handlebars-helpers)
80
+ - Attach documentation to [rubydoc.info](https://rubydoc.info/github/klueless-io/handlebars-helpers/master)
33
81
 
34
82
  Setup GitHub Action (test and lint)
35
83
 
data/USAGE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Handlebars Helpers
2
2
 
3
- > Handlebars Helpers is a library that provides (x) handlebars helpers across (y) categories, it was built to complement [cowboyd/handlebars.rb](https://github.com/cowboyd/handlebars.rb) with Ruby helpers commonly found in the Javascript community
3
+ > Handlebars Helpers is a library that provides <b>5</b> handlebars helpers across <b>42</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/bin/console CHANGED
@@ -3,7 +3,7 @@
3
3
  # frozen_string_literal: true
4
4
 
5
5
  require 'bundler/setup'
6
- require 'handlebars_helpers'
6
+ require 'handlebars/helpers'
7
7
 
8
8
  # You can add fixtures and/or initialization code here to make experimenting
9
9
  # with your gem easier. You can also use a different console, if you like.
@@ -25,6 +25,7 @@ Gem::Specification.new do |spec|
25
25
  spec.metadata['homepage_uri'] = spec.homepage
26
26
  spec.metadata['source_code_uri'] = 'https://github.com/klueless-io/handlebars-helpers'
27
27
  spec.metadata['changelog_uri'] = 'https://github.com/klueless-io/handlebars-helpers/commits/master'
28
+ spec.metadata['documentation_uri'] = 'https://rubydoc.info/github/klueless-io/handlebars-helpers/master'
28
29
 
29
30
  # Specify which files should be added to the gem when it is released.
30
31
  # The `git ls-files -z` loads the RubyGem files that have been added into git.
@@ -36,7 +37,15 @@ Gem::Specification.new do |spec|
36
37
  spec.bindir = 'exe'
37
38
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
38
39
  spec.require_paths = ['lib']
39
- # spec.extensions = ['ext/handlebars_helpers/extconf.rb']
40
+
41
+ spec.extra_rdoc_files = ['README.md', 'STORIES.md', 'USAGE.md']
42
+ spec.rdoc_options += [
43
+ '--title', 'handlebars-helpers by appydave.com',
44
+ '--main', 'README.md',
45
+ '--files', 'STORIES.MD USAGE.MD'
46
+ ]
40
47
 
41
48
  # spec.add_dependency 'tty-box', '~> 0.5.0'
49
+ spec.add_dependency 'activesupport'
50
+ spec.add_dependency 'handlebars'
42
51
  end
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'handlebars/helpers/version'
4
+ require 'handlebars/helpers/template'
5
+ require 'handlebars/helpers/register_helpers'
4
6
 
5
7
  module Handlebars
6
8
  module Helpers
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'handlebars/helpers/configuration'
4
+
5
+ module Handlebars
6
+ module Helpers
7
+ # base helper provides an interface to wrap your parsing logic
8
+ # in a Handlebars aware context
9
+ class BaseHelper
10
+ # Wrap the parse method in a handlebars context
11
+ # aware block that is used during registration
12
+ def handlebars_helper
13
+ proc { |_context, value| wrapper(parse(value)) }
14
+ end
15
+
16
+ # All child classes will generally implement this method
17
+ def parse(value)
18
+ value
19
+ end
20
+
21
+ # If you need to wrap the return value in a specific
22
+ # Handlebars Type, eg. SafeString, then you can override
23
+ # this method
24
+ def wrapper(value)
25
+ value
26
+ end
27
+
28
+ # String tokenizer will clean up a string so that
29
+ # all sorts of case formatted strings can be
30
+ # represented in a consistent fashion
31
+ def tokenizer
32
+ @_tokenizer ||= Handlebars::Helpers.configuration.tokenizer
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'handlebars/safe_string'
4
+ require 'handlebars/helpers/configuration'
5
+ require 'handlebars/helpers/base_helper'
6
+
7
+ module Handlebars
8
+ module Helpers
9
+ # base safe string helper provides will return a Handlebars::SafeString
10
+ # which allows characters like < > " to be rendered as is
11
+ class BaseSafeStringHelper < BaseHelper
12
+ def wrapper(value)
13
+ Handlebars::SafeString.new(value)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,40 @@
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 Handlebars
9
+ module Helpers
10
+ # Ruby code handling routines
11
+ module CodeRuby
12
+ # Classify: Creates a class name from a plural table name like Rails does for table names to models.
13
+ class Classify < Handlebars::Helpers::BaseHelper
14
+ # Parse will create a class name from a plural table name like Rails does for table names to models.
15
+ #
16
+ # @example
17
+ #
18
+ # puts Classify.new.parse('product_categories')
19
+ #
20
+ # ProductCategory
21
+ #
22
+ # @example
23
+ #
24
+ # puts Classify.new.parse('product_category')
25
+ #
26
+ # ProductCategory
27
+ #
28
+ # @param [String] value - name of the ruby class in plural or singular notation
29
+ # @return [String] value converted to ruby class notation
30
+ def parse(value)
31
+ tokenizer.parse(value, separator: '_', forced_separator: true).classify
32
+ end
33
+
34
+ def handlebars_helper
35
+ proc { |_context, value| wrapper(parse(value)) }
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end