handlebar_wax 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/README.rdoc +50 -0
- data/lib/handlebar_wax.rb +6 -3
- data/lib/handlebar_wax/templates/handlebars_templates.js.hbs +23 -0
- data/lib/handlebar_wax/version.rb +1 -1
- metadata +6 -5
- data/README +0 -25
data/.gitignore
CHANGED
data/README.rdoc
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
= handlebar_wax
|
2
|
+
|
3
|
+
== What is it?
|
4
|
+
|
5
|
+
HandlebarWax is a gem to let you easily share mustache templates between your server-side and client-side code.
|
6
|
+
|
7
|
+
On the server, HandlebarWax uses code borrowed from handlebars-rails to support +*.*.hbs+ as a template type (think +foo.html.erb+, +foo.html.haml+, +foo.html.hbs+). These work pretty much exactly like you would expect they should.
|
8
|
+
|
9
|
+
For the client side, HandlebarWax writes all your templates into +public/javascripts/handlebars_templates.js+, for you to use in your JavaScript code.
|
10
|
+
|
11
|
+
== How do I use it?
|
12
|
+
|
13
|
+
1. Add it to your gemfile.
|
14
|
+
|
15
|
+
gem "handlebar_wax"
|
16
|
+
|
17
|
+
2. Add it to your layout (it's important that +:handlebar_wax+ be a symbol, not a string)
|
18
|
+
|
19
|
+
= javascript_include_tag :handlebar_wax
|
20
|
+
|
21
|
+
3. Create view files.
|
22
|
+
|
23
|
+
(app/views/users/_user.html.hbs)
|
24
|
+
|
25
|
+
<h1>{{greeting}}, {{user/name}}!</h1>
|
26
|
+
|
27
|
+
4. Render views from rails. Note that in MustacheWax, hbs templates understand both assigns and locals.
|
28
|
+
|
29
|
+
- @user = User.first
|
30
|
+
= render :partial => 'users/user', :locals => {:greeting => "Hello"}
|
31
|
+
|
32
|
+
|
33
|
+
5. Render views from JavaScript
|
34
|
+
|
35
|
+
HandlebarWax('users/_user', {user: {name: "Why"}, greeting: "Frabjous Day"})
|
36
|
+
|
37
|
+
== Who made this possible?
|
38
|
+
|
39
|
+
* Steven Soroka (ssoroka) for pub-based discussion about this, and initial mustache_wax code
|
40
|
+
* Jamesarosen for handlebars-rails, which this project includes in its entirety, with very few modifications as of yet.
|
41
|
+
* Yehuda Katz (wycats) for the wonderful Handlebars.js.
|
42
|
+
|
43
|
+
== I want to help / I have an idea.
|
44
|
+
|
45
|
+
* I'm all ears. Shoot me an email or a PM.
|
46
|
+
|
47
|
+
== Copyright
|
48
|
+
|
49
|
+
Copyright (c) 2011 Burke Libbey. See LICENSE.txt for further details.
|
50
|
+
|
data/lib/handlebar_wax.rb
CHANGED
@@ -32,9 +32,12 @@ module HandlebarWax
|
|
32
32
|
name = template_file.scan(/app\/views\/(.*)\.[^\.]+\.hbs$/).flatten.first
|
33
33
|
templates[name] = File.read(template_file)
|
34
34
|
end
|
35
|
-
|
36
|
-
script =
|
37
|
-
|
35
|
+
|
36
|
+
script = File.read(File.join(File.dirname(__FILE__), 'handlebar_wax', 'templates', 'handlebars_templates.js.hbs'))
|
37
|
+
script.sub!("{{templates}}", Yajl::Encoder.encode(templates)) # How ironic is this?
|
38
|
+
|
38
39
|
File.open(output_path, 'w') { |f| f.puts script }
|
39
40
|
end
|
41
|
+
|
40
42
|
end
|
43
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
HandlebarWax = (function() {
|
2
|
+
|
3
|
+
var templates = {{templates}};
|
4
|
+
|
5
|
+
var compiledTemplates = {};
|
6
|
+
|
7
|
+
var fun = function(templateName, params) {
|
8
|
+
if (! compiledTemplates[name]) {
|
9
|
+
compiledTemplates[name] = Handlebars.compile(templates[templateName]);
|
10
|
+
}
|
11
|
+
if (typeof params == "undefined") {
|
12
|
+
return compiledTemplates[name];
|
13
|
+
} else {
|
14
|
+
return compiledTemplates[name](params);
|
15
|
+
}
|
16
|
+
};
|
17
|
+
|
18
|
+
fun.templates = templates;
|
19
|
+
fun.compiledTemplates = templates; // I can't think of a use for this, but why not?
|
20
|
+
|
21
|
+
return fun;
|
22
|
+
})();
|
23
|
+
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: handlebar_wax
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Burke Libbey
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-02-
|
18
|
+
date: 2011-02-26 00:00:00 -06:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -121,13 +121,14 @@ files:
|
|
121
121
|
- Gemfile
|
122
122
|
- Gemfile.lock
|
123
123
|
- LICENSE.txt
|
124
|
-
- README
|
124
|
+
- README.rdoc
|
125
125
|
- Rakefile
|
126
126
|
- handlebar_wax.gemspec
|
127
127
|
- lib/handlebar_wax.rb
|
128
128
|
- lib/handlebar_wax/middleware.rb
|
129
129
|
- lib/handlebar_wax/railtie.rb
|
130
130
|
- lib/handlebar_wax/template_handler.rb
|
131
|
+
- lib/handlebar_wax/templates/handlebars_templates.js.hbs
|
131
132
|
- lib/handlebar_wax/v8.rb
|
132
133
|
- lib/handlebar_wax/version.rb
|
133
134
|
- spec/handlebar_wax_spec.rb
|
data/README
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
= handlebar_wax
|
2
|
-
|
3
|
-
First off, credits:
|
4
|
-
|
5
|
-
* Steven Soroka (ssoroka) for pub-based discussion about this, and initial mustache_wax code
|
6
|
-
* Jamesarosen for handlebars-rails, which this project includes in its entirety, with very few modifications as of yet.
|
7
|
-
* Yehuda Katz (wycats) for the wonderful Handlebars.js.
|
8
|
-
|
9
|
-
Description goes here.
|
10
|
-
|
11
|
-
== Contributing to handlebar_wax
|
12
|
-
|
13
|
-
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
14
|
-
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
15
|
-
* Fork the project
|
16
|
-
* Start a feature/bugfix branch
|
17
|
-
* Commit and push until you are happy with your contribution
|
18
|
-
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
19
|
-
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
20
|
-
|
21
|
-
== Copyright
|
22
|
-
|
23
|
-
Copyright (c) 2011 Steven Soroka. See LICENSE.txt for
|
24
|
-
further details.
|
25
|
-
|