hbs 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/.gitmodules +3 -0
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/README.mdown +20 -0
- data/Rakefile +5 -0
- data/hbs.gemspec +28 -0
- data/js/.gitignore +5 -0
- data/js/Gemfile +4 -0
- data/js/LICENSE +20 -0
- data/js/README.markdown +224 -0
- data/js/Rakefile +107 -0
- data/js/bench/benchwarmer.js +147 -0
- data/js/bench/handlebars.js +166 -0
- data/js/lib/handlebars.js +15 -0
- data/js/lib/handlebars/ast.js +103 -0
- data/js/lib/handlebars/base.js +114 -0
- data/js/lib/handlebars/compiler.js +739 -0
- data/js/lib/handlebars/debug.js +29 -0
- data/js/lib/handlebars/printer.js +138 -0
- data/js/lib/handlebars/utils.js +66 -0
- data/js/lib/handlebars/visitor.js +13 -0
- data/js/spec/acceptance_spec.rb +100 -0
- data/js/spec/parser_spec.rb +259 -0
- data/js/spec/qunit_spec.js +836 -0
- data/js/spec/spec_helper.rb +106 -0
- data/js/spec/tokenizer_spec.rb +227 -0
- data/js/src/handlebars.l +34 -0
- data/js/src/handlebars.yy +99 -0
- data/lib/handlebars.rb +23 -0
- data/lib/handlebars/loader.rb +29 -0
- data/lib/handlebars/version.rb +3 -0
- data/spec/handlebars_spec.rb +32 -0
- metadata +112 -0
data/lib/handlebars.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
|
2
|
+
require 'handlebars/loader'
|
3
|
+
|
4
|
+
module Handlebars
|
5
|
+
|
6
|
+
@loader = Loader.new
|
7
|
+
|
8
|
+
module_function
|
9
|
+
|
10
|
+
def compile(*args)
|
11
|
+
handlebars.compile(*args)
|
12
|
+
end
|
13
|
+
|
14
|
+
def register_helper(name, &fn)
|
15
|
+
handlebars.registerHelper(name, fn)
|
16
|
+
end
|
17
|
+
|
18
|
+
def handlebars
|
19
|
+
Handlebars.module_eval do
|
20
|
+
@loader.require('handlebars')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
require 'v8'
|
3
|
+
require 'pathname'
|
4
|
+
|
5
|
+
module Handlebars
|
6
|
+
class Loader
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@cxt = V8::Context.new
|
10
|
+
@path = Pathname(__FILE__).dirname.join('..','..','js','lib')
|
11
|
+
@modules = {}
|
12
|
+
end
|
13
|
+
|
14
|
+
def require(modname)
|
15
|
+
unless mod = @modules[modname]
|
16
|
+
filename = modname =~ /\.js$/ ? modname : "#{modname}.js"
|
17
|
+
filepath = @path.join(filename)
|
18
|
+
fail LoadError, "no such file: #{filename}" unless filepath.exist?
|
19
|
+
load = @cxt.eval("(function(require, module, exports) {#{File.read(filepath)}})", filepath.expand_path)
|
20
|
+
object = @cxt['Object']
|
21
|
+
mod = object.new
|
22
|
+
mod['exports'] = object.new
|
23
|
+
@modules[modname] = mod
|
24
|
+
load.call(method(:require), mod, mod.exports)
|
25
|
+
end
|
26
|
+
return mod.exports
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
|
2
|
+
require 'handlebars'
|
3
|
+
describe(Handlebars) do
|
4
|
+
|
5
|
+
before {extend Handlebars}
|
6
|
+
|
7
|
+
describe "a simple template" do
|
8
|
+
let(:t) {compile("Hello {{name}}")}
|
9
|
+
it "allows simple subsitution" do
|
10
|
+
t.call(:name => 'World').should eql "Hello World"
|
11
|
+
end
|
12
|
+
|
13
|
+
it "allows Ruby blocks as a property" do
|
14
|
+
t.call(:name => lambda {|context| ;"Mate"}).should eql "Hello Mate"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "can use any Ruby object as a context" do
|
18
|
+
t.call(mock(:Object, :name => "Flipper")).should eql "Hello Flipper"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "registering Helpers" do
|
23
|
+
Handlebars.register_helper('alsowith') do |context, block|
|
24
|
+
block.call(context)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "correctly passes context and implementation" do
|
28
|
+
t = compile("it's so {{#alsowith weather}}*{{summary}}*{{/alsowith}}!")
|
29
|
+
t.call(:weather => {:summary => "sunny"}).should eql "it's so *sunny*!"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hbs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.1.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Charles Lowell
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-07-18 00:00:00 -05:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: therubyracer
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ~>
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 0.9.3beta1
|
25
|
+
type: :runtime
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
prerelease: false
|
30
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ~>
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: 2.0.0
|
36
|
+
type: :development
|
37
|
+
version_requirements: *id002
|
38
|
+
description: Uses the rubyracer bind in rails
|
39
|
+
email:
|
40
|
+
- cowboyd@thefrontside.net
|
41
|
+
executables: []
|
42
|
+
|
43
|
+
extensions: []
|
44
|
+
|
45
|
+
extra_rdoc_files: []
|
46
|
+
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- .gitmodules
|
50
|
+
- .rspec
|
51
|
+
- Gemfile
|
52
|
+
- README.mdown
|
53
|
+
- Rakefile
|
54
|
+
- hbs.gemspec
|
55
|
+
- lib/handlebars.rb
|
56
|
+
- lib/handlebars/loader.rb
|
57
|
+
- lib/handlebars/version.rb
|
58
|
+
- spec/handlebars_spec.rb
|
59
|
+
- js/.gitignore
|
60
|
+
- js/Gemfile
|
61
|
+
- js/Gemfile.lock
|
62
|
+
- js/LICENSE
|
63
|
+
- js/README.markdown
|
64
|
+
- js/Rakefile
|
65
|
+
- js/bench/benchwarmer.js
|
66
|
+
- js/bench/handlebars.js
|
67
|
+
- js/lib/handlebars.js
|
68
|
+
- js/lib/handlebars/ast.js
|
69
|
+
- js/lib/handlebars/base.js
|
70
|
+
- js/lib/handlebars/compiler.js
|
71
|
+
- js/lib/handlebars/debug.js
|
72
|
+
- js/lib/handlebars/printer.js
|
73
|
+
- js/lib/handlebars/utils.js
|
74
|
+
- js/lib/handlebars/visitor.js
|
75
|
+
- js/spec/acceptance_spec.rb
|
76
|
+
- js/spec/parser_spec.rb
|
77
|
+
- js/spec/qunit_spec.js
|
78
|
+
- js/spec/spec_helper.rb
|
79
|
+
- js/spec/tokenizer_spec.rb
|
80
|
+
- js/src/handlebars.l
|
81
|
+
- js/src/handlebars.yy
|
82
|
+
- js/lib/handlebars/parser.js
|
83
|
+
has_rdoc: true
|
84
|
+
homepage: http://github.com/cowboyd/handlebars.rb
|
85
|
+
licenses: []
|
86
|
+
|
87
|
+
post_install_message:
|
88
|
+
rdoc_options: []
|
89
|
+
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: "0"
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
none: false
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: "0"
|
104
|
+
requirements: []
|
105
|
+
|
106
|
+
rubyforge_project: handlebars
|
107
|
+
rubygems_version: 1.6.2
|
108
|
+
signing_key:
|
109
|
+
specification_version: 3
|
110
|
+
summary: Ruby bindings for the handlebars.js templating library
|
111
|
+
test_files:
|
112
|
+
- spec/handlebars_spec.rb
|