templebars 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +64 -0
- data/LICENSE +21 -0
- data/README.md +37 -0
- data/Rakefile +2 -0
- data/lib/templebars/rails/engine.rb +6 -0
- data/lib/templebars/rails/templates.rb +47 -0
- data/lib/templebars/rails/version.rb +6 -0
- data/lib/templebars/rails.rb +9 -0
- data/lib/templebars.rb +2 -0
- data/templebars.gemspec +22 -0
- data/vendor/assets/handlebars.js +1550 -0
- metadata +84 -0
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
templebars (0.0.1)
|
5
|
+
execjs
|
6
|
+
railties (>= 3.2.0.beta, < 5.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: http://rubygems.org/
|
10
|
+
specs:
|
11
|
+
actionpack (3.2.0.rc2)
|
12
|
+
activemodel (= 3.2.0.rc2)
|
13
|
+
activesupport (= 3.2.0.rc2)
|
14
|
+
builder (~> 3.0.0)
|
15
|
+
erubis (~> 2.7.0)
|
16
|
+
journey (~> 1.0.0.rc1)
|
17
|
+
rack (~> 1.4.0)
|
18
|
+
rack-cache (~> 1.1)
|
19
|
+
rack-test (~> 0.6.1)
|
20
|
+
sprockets (~> 2.1.2)
|
21
|
+
activemodel (3.2.0.rc2)
|
22
|
+
activesupport (= 3.2.0.rc2)
|
23
|
+
builder (~> 3.0.0)
|
24
|
+
activesupport (3.2.0.rc2)
|
25
|
+
i18n (~> 0.6)
|
26
|
+
multi_json (~> 1.0)
|
27
|
+
builder (3.0.0)
|
28
|
+
erubis (2.7.0)
|
29
|
+
execjs (1.2.13)
|
30
|
+
multi_json (~> 1.0)
|
31
|
+
hike (1.2.1)
|
32
|
+
i18n (0.6.0)
|
33
|
+
journey (1.0.0.rc4)
|
34
|
+
json (1.6.4)
|
35
|
+
multi_json (1.0.4)
|
36
|
+
rack (1.4.0)
|
37
|
+
rack-cache (1.1)
|
38
|
+
rack (>= 0.4)
|
39
|
+
rack-ssl (1.3.2)
|
40
|
+
rack
|
41
|
+
rack-test (0.6.1)
|
42
|
+
rack (>= 1.0)
|
43
|
+
railties (3.2.0.rc2)
|
44
|
+
actionpack (= 3.2.0.rc2)
|
45
|
+
activesupport (= 3.2.0.rc2)
|
46
|
+
rack-ssl (~> 1.3.2)
|
47
|
+
rake (>= 0.8.7)
|
48
|
+
rdoc (~> 3.4)
|
49
|
+
thor (~> 0.14.6)
|
50
|
+
rake (0.9.2.2)
|
51
|
+
rdoc (3.12)
|
52
|
+
json (~> 1.4)
|
53
|
+
sprockets (2.1.2)
|
54
|
+
hike (~> 1.2)
|
55
|
+
rack (~> 1.0)
|
56
|
+
tilt (~> 1.1, != 1.3.0)
|
57
|
+
thor (0.14.6)
|
58
|
+
tilt (1.3.3)
|
59
|
+
|
60
|
+
PLATFORMS
|
61
|
+
ruby
|
62
|
+
|
63
|
+
DEPENDENCIES
|
64
|
+
templebars!
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2012 Stovepipe Studios
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# templebars
|
2
|
+
|
3
|
+
This gem provides Handlebars 1.0.beta.6 to the Rails assert pipeline via `handlebars`. You can include it in other JS files:
|
4
|
+
|
5
|
+
```js
|
6
|
+
//= require handlebars
|
7
|
+
```
|
8
|
+
|
9
|
+
You can also include it via a regular ol' `javascript_include_tag` call:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
javascript_include_tag( "handlebars" )
|
13
|
+
```
|
14
|
+
|
15
|
+
## Precompiled templates
|
16
|
+
|
17
|
+
`templebars` also allows you to precomile Handlebars templates and make them available globally in a `Templates` object. (This can be set via `Templebars::Rails::GLOBAL`) Create files with a "handlebars", "hjs", or "hb" extension inside of a `templates/` directory in any `assets/javascripts/` directory:
|
18
|
+
|
19
|
+
```
|
20
|
+
app/assets/javascripts/templates/todo_item.js.handlebars
|
21
|
+
```
|
22
|
+
|
23
|
+
You can then access it like any other JavaScript asset:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
javascript_include_tag( "templates/todo_item" )
|
27
|
+
```
|
28
|
+
|
29
|
+
The above template would be stored as `Templates.todo_item`.
|
30
|
+
|
31
|
+
## Installation
|
32
|
+
|
33
|
+
Add this to your Gemfile, preferably in the `:assets` gem group:
|
34
|
+
|
35
|
+
gem "templebars"
|
36
|
+
|
37
|
+
Done. Go forth, grasshopper.
|
data/Rakefile
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require "tilt/template"
|
2
|
+
require "execjs"
|
3
|
+
require 'sprockets'
|
4
|
+
|
5
|
+
module Templebars
|
6
|
+
module Rails
|
7
|
+
# Tilt template renderer for precompiling Handlebars templates and storing
|
8
|
+
# them in a global Templates object.
|
9
|
+
class HandlebarsTemplate < ::Tilt::Template
|
10
|
+
SETUP_GLOBAL = "#{Templebars::Rails::GLOBAL} || (#{Templebars::Rails::GLOBAL} = {});"
|
11
|
+
|
12
|
+
def self.default_mime_type
|
13
|
+
"application/javascript"
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize_engine; end
|
17
|
+
|
18
|
+
def prepare; end
|
19
|
+
|
20
|
+
def evaluate( scope, locals, &block )
|
21
|
+
name = scope.logical_path.sub( /^templates\//, "" )
|
22
|
+
precompiled_js = precompile( data )
|
23
|
+
template_declaration = "#{Templebars::Rails::GLOBAL}[\"#{name}\"] = Handlebars.template(#{precompiled_js});"
|
24
|
+
"#{SETUP_GLOBAL}\n#{template_declaration}\n"
|
25
|
+
end
|
26
|
+
|
27
|
+
protected
|
28
|
+
|
29
|
+
def precompile( template )
|
30
|
+
runtime.call( "Handlebars.precompile", template )
|
31
|
+
end
|
32
|
+
|
33
|
+
def runtime
|
34
|
+
@runtime ||= ExecJS.compile( handlebars_js )
|
35
|
+
end
|
36
|
+
|
37
|
+
def handlebars_js
|
38
|
+
path = File.join( File.dirname(__FILE__), "..", "..", "..", "vendor", "assets", "handlebars.js" )
|
39
|
+
File.read( path )
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
Sprockets.register_engine '.handlebars', HandlebarsTemplate
|
44
|
+
Sprockets.register_engine '.hbs', HandlebarsTemplate
|
45
|
+
Sprockets.register_engine '.hb', HandlebarsTemplate
|
46
|
+
end
|
47
|
+
end
|
data/lib/templebars.rb
ADDED
data/templebars.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/templebars/rails/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "templebars"
|
6
|
+
s.version = Templebars::Rails::VERSION
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.authors = ["Tyson Tate"]
|
9
|
+
s.email = ["tyson@stovepipestudios.com"]
|
10
|
+
s.homepage = "http://rubygems.org/gems/templebars"
|
11
|
+
s.summary = "Use precompiled Handlebars templates with Rails 3"
|
12
|
+
s.description = "This gem provides Handlebars magic for your Rails 3 application."
|
13
|
+
|
14
|
+
s.required_rubygems_version = ">= 1.3.6"
|
15
|
+
s.rubyforge_project = "templebars"
|
16
|
+
|
17
|
+
s.add_dependency "railties", ">= 3.2.0.beta", "< 5.0"
|
18
|
+
s.add_dependency "execjs"
|
19
|
+
|
20
|
+
s.files = `git ls-files`.split("\n")
|
21
|
+
s.require_path = 'lib'
|
22
|
+
end
|