Skip to content

Commit d0eb632

Browse files
authored
Merge pull request #3 from gi:release-0.2.0
v0.2.0: bump version and update changelog
2 parents 54515c7 + 3de44e4 commit d0eb632

11 files changed

Lines changed: 990 additions & 13 deletions

File tree

.github/workflows/ci.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
- name: Install
2020
uses: ruby/setup-ruby@v1
2121
with:
22-
ruby-version: ruby-3.0
22+
ruby-version: ruby-3
2323
bundler-cache: true
2424
- name: Test
2525
run: bundle exec rake
@@ -38,7 +38,7 @@ jobs:
3838
- name: Install
3939
uses: ruby/setup-ruby@v1
4040
with:
41-
ruby-version: ruby-3.0
41+
ruby-version: ruby-3
4242
bundler-cache: true
4343
- name: Lint
4444
run: bundle exec rubocop
@@ -47,12 +47,13 @@ jobs:
4747
strategy:
4848
matrix:
4949
os:
50-
# - macos-latest
50+
- macos-latest
5151
- ubuntu-latest
5252
ruby:
5353
- ruby-2.6
5454
- ruby-2.7
5555
- ruby-3.0
56+
- ruby-3.1
5657
# - jruby
5758
# - truffleruby
5859
runs-on: ${{ matrix.os }}

.github/workflows/publish.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Publish
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
permissions:
9+
contents: write
10+
packages: write
11+
12+
jobs:
13+
github:
14+
name: GitHub
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v2
19+
- name: Install
20+
uses: ruby/setup-ruby@v1
21+
with:
22+
ruby-version: ruby-3
23+
bundler-cache: true
24+
- name: Publish to GitHub
25+
env:
26+
GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}"
27+
RUBYGEMS_HOST: https://rubygems.pkg.github.com/${{github.repository_owner}}
28+
run: bin/release
29+
rubygems:
30+
name: RubyGems
31+
runs-on: ubuntu-latest
32+
steps:
33+
- name: Checkout
34+
uses: actions/checkout@v2
35+
- name: Install
36+
uses: ruby/setup-ruby@v1
37+
with:
38+
ruby-version: ruby-3
39+
bundler-cache: true
40+
- name: Publish to RubyGems
41+
env:
42+
GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_TOKEN}}"
43+
run: bin/release

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/[._]*/
2+
!/.github/
23
/doc/
34
/pkg/
45
/spec/reports/

.rubocop.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,6 @@ Metrics/ClassLength:
119119
- heredoc
120120
Max: 120
121121

122-
Metrics/CyclomaticComplexity:
123-
Max: 10
124-
125122
Metrics/MethodLength:
126123
CountAsOne:
127124
- array
@@ -138,8 +135,14 @@ Metrics/ModuleLength:
138135
Metrics/ParameterLists:
139136
Max: 10
140137

138+
RSpec/ExampleLength:
139+
CountAsOne:
140+
- array
141+
- hash
142+
- heredoc
143+
141144
RSpec/MultipleMemoizedHelpers:
142-
Max: 10
145+
Max: 20
143146

144147
RSpec/NestedGroups:
145148
Max: 8

CHANGELOG.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,28 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

88
## [Unreleased]
9+
10+
## [0.2.0] - 2022-01-27
11+
12+
This is the initial implementation, wrapping the JavaScript Handlebars.
13+
14+
### Added
15+
- `Handlebars::Engine#compile`
16+
- `Handlebars::Engine#precompile`
17+
- `Handlebars::Engine#template`
18+
- `Handlebars::Engine#register_helper`
19+
- `Handlebars::Engine#unregister_helper`
20+
- `Handlebars::Engine#register_partial`
21+
- `Handlebars::Engine#unregister_partial`
22+
- `Handlebars::Engine#register_helper_missing`
23+
- `Handlebars::Engine#unregister_helper_missing`
24+
- `Handlebars::Engine#register_partial_missing`
25+
- `Handlebars::Engine#unregister_partial_missing`
26+
- `Handlebars::Engine#version`
27+
28+
## [0.1.0] - 2022-01-13
29+
30+
This is the initial package.
31+
32+
### Added
33+
- gem init

README.md

Lines changed: 138 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,144 @@ Or install it yourself as:
2626

2727
## Usage
2828

29-
TODO: Write usage instructions here
29+
### Quick Start
30+
31+
```ruby
32+
handlebars = Handlebars::Engine.new
33+
template = handlebars.compile("{{firstname}} {{lastname}}")
34+
template.call({ firstname: "Yehuda", lastname: "Katz" })
35+
# => "Yehuda Katz"
36+
```
37+
38+
### Custom Helpers
39+
40+
Handlebars helpers can be accessed from any context in a template. You can
41+
register a helper with the `register_helper` method:
42+
43+
```ruby
44+
handlebars = Handlebars::Engine.new
45+
handlebars.register_helper(:loud) do |ctx, arg, opts|
46+
arg.upcase
47+
end
48+
template = handlebars.compile("{{firstname}} {{loud lastname}}")
49+
template.call({ firstname: "Yehuda", lastname: "Katz" })
50+
# => "Yehuda KATZ"
51+
```
52+
53+
#### Helper Arguments
54+
55+
Helpers receive the current context as the first argument of the block.
56+
57+
```ruby
58+
handlebars = Handlebars::Engine.new
59+
handlebars.register_helper(:full_name) do |ctx, opts|
60+
"#{ctx["firstname"]} #{ctx["lastname"]}"
61+
end
62+
template = handlebars.compile("{{full_name}}")
63+
template.call({ firstname: "Yehuda", lastname: "Katz" })
64+
# => "Yehuda Katz"
65+
```
66+
67+
Any arguments to the helper are included as individual positional arguments.
68+
69+
```ruby
70+
handlebars = Handlebars::Engine.new
71+
handlebars.register_helper(:join) do |ctx, *args, opts|
72+
args.join(" ")
73+
end
74+
template = handlebars.compile("{{join firstname lastname}}")
75+
template.call({ firstname: "Yehuda", lastname: "Katz" })
76+
# => "Yehuda Katz"
77+
```
78+
79+
The last argument is a hash of options.
80+
81+
See https://handlebarsjs.com/guide/#custom-helpers.
82+
83+
### Block Helpers
84+
85+
See https://handlebarsjs.com/guide/#block-helpers.
86+
87+
### Partials
88+
89+
Handlebars partials allow for code reuse by creating shared templates.
90+
91+
You can register a partial using the `register_partial` method:
92+
93+
```ruby
94+
handlebars = Handlebars::Engine.new
95+
handlebars.register_partial(:person, "{{person.name}} is {{person.age}}.")
96+
template = handlebars.compile("{{> person person=.}}")
97+
template.call({ name: "Yehuda Katz", age: 20 })
98+
# => "Yehuda Katz is 20."
99+
```
100+
101+
See https://handlebarsjs.com/guide/#partials.
102+
See https://handlebarsjs.com/guide/partials.html.
103+
104+
### Hooks
105+
106+
#### Helper Missing
107+
108+
This hook is called for a mustache or a block-statement when
109+
* a simple mustache-expression is not a registered helper, *and*
110+
* it is not a property of the current evaluation context.
111+
112+
You can add custom handling for those situations by registering a helper with
113+
the `register_helper_missing` method:
114+
115+
```ruby
116+
handlebars = Handlebars::Engine.new
117+
handlebars.register_helper_missing do |ctx, *args, opts|
118+
"Missing: #{opts["name"]}(#{args.join(", ")})"
119+
end
120+
121+
template = handlebars.compile("{{foo 2 true}}")
122+
template.call
123+
# => "Missing: foo(2, true)"
124+
125+
template = handlebars.compile("{{#foo true}}{{/foo}}")
126+
template.call
127+
# => "Missing: foo(true)"
128+
```
129+
130+
See https://handlebarsjs.com/guide/hooks.html#helpermissing.
131+
132+
##### Blocks
133+
134+
This hook is called for a block-statement when
135+
* a block-expression calls a helper that is not registered, *and*
136+
* the name is a property of the current evaluation context.
137+
138+
You can add custom handling for those situations by registering a helper with
139+
the `register_helper_missing` method (with a `:block` argument):
140+
141+
```ruby
142+
handlebars = Handlebars::Engine.new
143+
handlebars.register_helper_missing(:block) do |ctx, *args, opts|
144+
"Missing: #{opts["name"]}(#{args.join(", ")})"
145+
end
146+
147+
template = handlebars.compile("{{#person}}{{name}}{{/person}}")
148+
template.call({ person: { name: "Yehuda Katz" } })
149+
# => "Missing: person"
150+
```
151+
152+
See https://handlebarsjs.com/guide/hooks.html#blockhelpermissing.
153+
154+
#### Partial Missing
155+
156+
This hook is called for a partial that is not registered.
157+
158+
```ruby
159+
handlebars = Handlebars::Engine.new
160+
handlebars.register_partial_missing do |name|
161+
"partial: #{name}"
162+
end
163+
```
164+
165+
Note: This is not a part of the offical Handlebars API. It is provided for
166+
convenience.
30167

31168
## Changelog
32169

handlebars-engine.gemspec

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Gem::Specification.new do |spec|
66
spec.name = "handlebars-engine"
77
spec.version = Handlebars::Engine::VERSION
88
spec.authors = ["Zach Gianos"]
9-
spec.email = ["zach.gianos@gmail.com"]
9+
spec.email = ["zach.gianos+git@gmail.com"]
1010

1111
spec.summary = "A simple interface to Handlebars.js for Ruby."
1212
spec.description = <<-DESCRIPTION
@@ -18,6 +18,7 @@ Gem::Specification.new do |spec|
1818
spec.required_ruby_version = ">= 2.6.0"
1919

2020
spec.metadata["changelog_uri"] = "#{spec.homepage}/CHANGELOG.md"
21+
spec.metadata["github_repo"] = spec.homepage
2122
spec.metadata["homepage_uri"] = spec.homepage
2223
spec.metadata["rubygems_mfa_required"] = "true"
2324
spec.metadata["source_code_uri"] = spec.homepage
@@ -35,4 +36,7 @@ Gem::Specification.new do |spec|
3536
spec.bindir = "exe"
3637
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
3738
spec.require_paths = ["lib"]
39+
40+
spec.add_dependency "handlebars-source"
41+
spec.add_dependency "mini_racer"
3842
end

0 commit comments

Comments
 (0)