hbs 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,6 +4,26 @@
4
4
  This uses [therubyracer](http://github.com/cowboyd/therubyracer) to bind to the _actual_ JavaScript implementation of
5
5
  [Handlebars.js](http://github.com/wycats/handlebars.js) so that you can use it from ruby.
6
6
 
7
+ ## Usage
8
+
9
+ Simple stuff
10
+
11
+ require 'handlebars'
12
+ template = Handlebars.compile("{{say}}{{what}}")
13
+ template.call(:say => "Hey", :what => "Yuh!") #=> "Hey Yuh!"
14
+
15
+ With functions as properties
16
+
17
+ template.call(:say => "Hey", :what => lambda {|this| ("yo" * 2) + "!"}) #=> "Hey yoyo!"
18
+
19
+ Register block helpers:
20
+
21
+ Handlebars.register_helper(:twice) do |block|
22
+ "#{block.call}#{block.call}"
23
+ end
24
+ template = Handlebars.compile({{#twice}}Hurray!{{/twice}})
25
+ template.call #=> Hurray!Hurray!
26
+
7
27
  ## Hack
8
28
 
9
29
  git clone git@github.com:cowboyd/handlebars.rb.git #git it
@@ -11,10 +31,11 @@ This uses [therubyracer](http://github.com/cowboyd/therubyracer) to bind to the
11
31
  git submodule update --init #pull down handlebars.js
12
32
  rspec spec/ #test it
13
33
 
14
- ## Use
15
34
 
16
- require 'handlebars'
17
- template = Handlebars.compile("{{say}}{{what}}")
18
- template.call(:say => "Hey", :what => "Yuh!") #=> "Hey Yuh!"
35
+ ## Rubygems
19
36
 
37
+ Handlebars is available via the [hbs](http://rubygems.org/gems/hbs) gem on rubygems.org. There
38
+ is an [abandoned](https://github.com/MSch/handlebars-ruby) pure-ruby implementation of handlebars
39
+ on github. Eventually, I'd like to merge these two projects, but I have not been able to contact the
40
+ owner of that gem.
20
41
 
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
10
10
  s.email = ["cowboyd@thefrontside.net"]
11
11
  s.homepage = "http://github.com/cowboyd/handlebars.rb"
12
12
  s.summary = %q{Ruby bindings for the handlebars.js templating library}
13
- s.description = %q{Uses the rubyracer bind in rails}
13
+ s.description = %q{Uses the actual JavaScript implementation of Handlebars, but supports using Ruby objects as template contexts and Ruby procs as view functions and named helpers}
14
14
 
15
15
  s.rubyforge_project = "handlebars"
16
16
 
@@ -24,5 +24,5 @@ Gem::Specification.new do |s|
24
24
  end
25
25
 
26
26
  s.add_dependency "therubyracer", "~> 0.9.3beta1"
27
- s.add_development_dependency "rspec", "~> 2.0.0"
27
+ s.add_development_dependency "rspec", "~> 2.0"
28
28
  end
@@ -1,3 +1,3 @@
1
1
  module Handlebars
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -23,10 +23,18 @@ describe(Handlebars) do
23
23
  Handlebars.register_helper('alsowith') do |context, block|
24
24
  block.call(context)
25
25
  end
26
+ Handlebars.register_helper(:twice) do |block|
27
+ "#{block.call}#{block.call}"
28
+ end
26
29
 
27
30
  it "correctly passes context and implementation" do
28
31
  t = compile("it's so {{#alsowith weather}}*{{summary}}*{{/alsowith}}!")
29
32
  t.call(:weather => {:summary => "sunny"}).should eql "it's so *sunny*!"
30
33
  end
34
+
35
+ it "doesn't nee a context or arguments to the call" do
36
+ t = compile("{{#twice}}Hurray!{{/twice}}")
37
+ t.call.should eql "Hurray!Hurray!"
38
+ end
31
39
  end
32
40
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: hbs
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.0
5
+ version: 0.1.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Charles Lowell
@@ -32,10 +32,10 @@ dependencies:
32
32
  requirements:
33
33
  - - ~>
34
34
  - !ruby/object:Gem::Version
35
- version: 2.0.0
35
+ version: "2.0"
36
36
  type: :development
37
37
  version_requirements: *id002
38
- description: Uses the rubyracer bind in rails
38
+ description: Uses the actual JavaScript implementation of Handlebars, but supports using Ruby objects as template contexts and Ruby procs as view functions and named helpers
39
39
  email:
40
40
  - cowboyd@thefrontside.net
41
41
  executables: []