diff --git a/Gemfile b/Gemfile index 46bc25d..c6489f6 100644 --- a/Gemfile +++ b/Gemfile @@ -10,3 +10,4 @@ gem 'liquid' gem 'mustache' gem 'markaby' gem 'tenjin' +gem 'handlebars' diff --git a/Gemfile.lock b/Gemfile.lock index 946a2e4..8c0774c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,21 +2,32 @@ GEM remote: https://rubygems.org/ specs: builder (3.2.2) + commonjs (0.2.7) erubis (2.7.0) faker (1.2.0) i18n (~> 0.5) haml (4.0.4) tilt + handlebars (0.5.0) + commonjs (~> 0.2.3) + handlebars-source (~> 1.0.12) + therubyracer (~> 0.12.0) + handlebars-source (1.0.12) i18n (0.6.9) + libv8 (3.16.14.3) liquid (2.6.0) markaby (0.7.2) builder (>= 2.0.0) mustache (0.99.5) + ref (1.0.5) slim (2.0.2) temple (~> 0.6.6) tilt (>= 1.3.3, < 2.1) temple (0.6.7) tenjin (0.7.1) + therubyracer (0.12.0) + libv8 (~> 3.16.14.0) + ref tilt (2.0.0) PLATFORMS @@ -26,6 +37,7 @@ DEPENDENCIES erubis faker haml + handlebars liquid markaby mustache diff --git a/README.md b/README.md index 5cc07bb..273110c 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ - [ERB](http://ruby-doc.org/stdlib-2.0.0/libdoc/erb/rdoc/ERB.html) - [Erubis](http://www.kuwata-lab.com/erubis/) - [Haml](http://haml.info/) +- [Handlebars](https://github.com/cowboyd/handlebars.rb) (JS bingings) - [Liquid](http://liquidmarkup.org/) - [Markaby](http://markaby.github.io/) - [Mustache](https://github.com/defunkt/mustache) diff --git a/benchmark.rb b/benchmark.rb index 3a00a7c..70549f6 100755 --- a/benchmark.rb +++ b/benchmark.rb @@ -9,10 +9,6 @@ $ ./fakedata.rb 10000 > data/big.yml AGRR Workbench::Benchmark.describe_engines( - tenjin: { - class: Workbench::Wrappers::Tenjin, - extension: 'rbhtml' - }, string: { class: Tilt::StringTemplate, extension: 'str' @@ -21,6 +17,10 @@ Workbench::Benchmark.describe_engines( class: Tilt::ErubisTemplate, extension: 'erubis' }, + tenjin: { + class: Workbench::Wrappers::Tenjin, + extension: 'rbhtml' + }, erb: { class: Tilt::ERBTemplate, extension: 'erb' @@ -49,6 +49,10 @@ Workbench::Benchmark.describe_engines( class: Tilt::BuilderTemplate, extension: 'builder' }, + handlebars: { + class: Workbench::Wrappers::Handlebars, + extension: 'handlebars' + }, ) templates = {} diff --git a/lib/workbench.rb b/lib/workbench.rb index e08f942..8ae23fc 100644 --- a/lib/workbench.rb +++ b/lib/workbench.rb @@ -12,6 +12,7 @@ require 'slim' require 'liquid' require 'mustache' require 'tenjin' +require 'handlebars' require 'tilt/erb' require 'tilt/erubis' require 'tilt/haml' @@ -22,3 +23,4 @@ require 'workbench/wrappers/base' require 'workbench/wrappers/mustache' require 'workbench/wrappers/slim' require 'workbench/wrappers/tenjin' +require 'workbench/wrappers/handlebars' diff --git a/lib/workbench/wrappers/handlebars.rb b/lib/workbench/wrappers/handlebars.rb new file mode 100644 index 0000000..892a559 --- /dev/null +++ b/lib/workbench/wrappers/handlebars.rb @@ -0,0 +1,16 @@ +module Workbench + module Wrappers + class Handlebars < Base + @@context = ::Handlebars::Context.new + + def initialize path + @engine = @@context.compile(File.read(path)) + end + + def render context, args = {} + @engine.call(args) + end + end + end +end + diff --git a/templates/handlebars/big.handlebars b/templates/handlebars/big.handlebars new file mode 100644 index 0000000..1b32386 --- /dev/null +++ b/templates/handlebars/big.handlebars @@ -0,0 +1,25 @@ + + + + Customers List + + + {{#each customers}} +
+
Name:
+
{{name}}
+
Age:
+
{{age}}
+
Address:
+
+ {{zip}} + {{country}} + {{city}} + {{address}} +
+
Employer:
+
{{employer}}
+
+ {{/each}} + + diff --git a/templates/handlebars/small.handlebars b/templates/handlebars/small.handlebars new file mode 100644 index 0000000..a1c78e4 --- /dev/null +++ b/templates/handlebars/small.handlebars @@ -0,0 +1,18 @@ + + + + {{window_title}} + + +

Hello, {{username}}!

+

+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod + tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim + veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea + commodo consequat. Duis aute irure dolor in reprehenderit in voluptate + velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat + cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id + est laborum. +

+ +