Skip to content

Commit e6524f2

Browse files
authored
readme/specs: update description and test compile with options (#11)
* update description * test compile with options
1 parent 4f3516f commit e6524f2

5 files changed

Lines changed: 63 additions & 5 deletions

File tree

CONTRIBUTING.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
# Contributing
22

3+
Bug reports and pull requests are welcome on GitHub:
4+
https://github.com/gi/handlebars-ruby.
5+
6+
1. Fork the repository: https://github.com/gi/handlebars-ruby.
7+
1. Create an issue branch: `git checkout -b issue-N/summary origin/develop`)
8+
1. Run [setup](#Setup): `bin/setup`.
9+
1. Add tests for your updates.
10+
1. Run [tests](#Test): `bin/test`.
11+
1. Run linter: `bin/lint`.
12+
1. Commit changes: `git commit -am '[#N] Summary'`.
13+
1. Push changes: `git push origin head`.
14+
1. Create a pull request targeting `develop`.
15+
316
## Branches
417

518
This repository follows a modified version of the

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
# Handlebars::Engine
22

33
[![Gem Version](https://badge.fury.io/rb/handlebars-engine.svg)](https://rubygems.org/gems/handlebars-engine)
4-
[![Build Status](https://github.com/gi/handlebars-ruby/actions/workflows/ci.yml/badge.svg)](https://github.com/gi/handlebars-ruby/actions/workflows/ci.yml)
4+
[![CI Status](https://github.com/gi/handlebars-ruby/actions/workflows/ci.yml/badge.svg)](https://github.com/gi/handlebars-ruby/actions/workflows/ci.yml)
55
[![Test Coverage](https://api.codeclimate.com/v1/badges/45d98ad9e12ee3384161/test_coverage)](https://codeclimate.com/github/gi/handlebars-ruby/test_coverage)
66
[![Maintainability](https://api.codeclimate.com/v1/badges/45d98ad9e12ee3384161/maintainability)](https://codeclimate.com/github/gi/handlebars-ruby/maintainability)
77
[![MIT License](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE.txt)
88

9-
A simple interface to [Handlebars.js](https://handlebarsjs.com) for Ruby.
9+
A complete interface to [Handlebars.js](https://handlebarsjs.com) for Ruby.
10+
11+
`Handlebars::Engine` provides a complete Ruby API for the official JavaScript
12+
version of Handlebars, including the abilities to register Ruby blocks/procs as
13+
Handlebars helper functions and to dynamically register partials.
14+
15+
It uses [MiniRacer](https://github.com/rubyjs/mini_racer) for the bridge between
16+
Ruby and the V8 JavaScript engine.
17+
18+
`Handlebars::Engine` was created as a replacement for
19+
[handlebars.rb](https://github.com/cowboyd/handlebars.rb).
1020

1121
## Installation
1222

handlebars-engine.gemspec

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,17 @@ Gem::Specification.new do |spec|
88
spec.authors = ["Zach Gianos"]
99
spec.email = ["zach.gianos+git@gmail.com"]
1010

11-
spec.summary = "A simple interface to Handlebars.js for Ruby."
11+
spec.summary = "A complete interface to Handlebars.js for Ruby."
1212
spec.description = <<-DESCRIPTION
13-
A simple interface to Handlebars.js for Ruby.
13+
A complete interface to Handlebars.js for Ruby.
14+
15+
Handlebars::Engine provides a complete Ruby API for the official JavaScript
16+
version of Handlebars, including the abilities to register Ruby blocks/procs
17+
as Handlebars helper functions and to dynamically register partials.
18+
19+
It uses MiniRacer for the bridge between Ruby and the V8 JavaScript engine.
20+
21+
Handlebars::Engine was created as a replacement for handlebars.rb.
1422
DESCRIPTION
1523

1624
spec.homepage = "https://github.com/gi/handlebars-ruby"

lib/handlebars/engine.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ module Handlebars
1212
# This API follows the JavaScript API as closely as possible:
1313
# https://handlebarsjs.com/api-reference/.
1414
class Engine
15+
Error = MiniRacer::RuntimeError
16+
1517
# Creates a new instance.
1618
#
1719
# @param lazy [true, false] immediately loads and initializes the JavaScript

spec/handlebars/engine_spec.rb

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
shared_examples "rendering" do |error: false|
9393
if error
9494
it "raises an error" do
95-
expect { render }.to raise_error(MiniRacer::RuntimeError)
95+
expect { render }.to raise_error(Handlebars::Engine::Error)
9696
end
9797
else
9898
it "renders the template" do
@@ -101,6 +101,27 @@
101101
end
102102
end
103103

104+
shared_examples "compiling with options" do
105+
let(:template_options) { {} }
106+
107+
describe "knownHelpers" do
108+
let(:render_context) { { age: -30 } }
109+
let(:rendered) { "Hello, you are 30!" }
110+
let(:template) { "Hello, you are {{abs age}}!" }
111+
112+
before do
113+
engine.register_helper(:abs) { |_ctx, age, _opts| age.abs }
114+
template_options[:knownHelpers] = {
115+
abs: true,
116+
}
117+
end
118+
119+
describe "rendering" do
120+
include_examples "rendering"
121+
end
122+
end
123+
end
124+
104125
describe "#compile" do
105126
let(:renderer) { engine.compile(template, template_options) }
106127

@@ -111,6 +132,8 @@
111132
describe "return value" do
112133
it_behaves_like "renderer"
113134
end
135+
136+
it_behaves_like "compiling with options"
114137
end
115138

116139
describe "#precompile" do
@@ -138,6 +161,8 @@
138161
describe "return value" do
139162
it_behaves_like "renderer"
140163
end
164+
165+
it_behaves_like "compiling with options"
141166
end
142167

143168
###################################

0 commit comments

Comments
 (0)