dust-rails 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ *.DS_Store
2
+ pkg
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in dust-rails.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,97 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ dust-rails (0.1.0)
5
+ execjs
6
+ rails (~> 3.1.0)
7
+ tilt
8
+
9
+ GEM
10
+ remote: http://rubygems.org/
11
+ specs:
12
+ actionmailer (3.1.3)
13
+ actionpack (= 3.1.3)
14
+ mail (~> 2.3.0)
15
+ actionpack (3.1.3)
16
+ activemodel (= 3.1.3)
17
+ activesupport (= 3.1.3)
18
+ builder (~> 3.0.0)
19
+ erubis (~> 2.7.0)
20
+ i18n (~> 0.6)
21
+ rack (~> 1.3.5)
22
+ rack-cache (~> 1.1)
23
+ rack-mount (~> 0.8.2)
24
+ rack-test (~> 0.6.1)
25
+ sprockets (~> 2.0.3)
26
+ activemodel (3.1.3)
27
+ activesupport (= 3.1.3)
28
+ builder (~> 3.0.0)
29
+ i18n (~> 0.6)
30
+ activerecord (3.1.3)
31
+ activemodel (= 3.1.3)
32
+ activesupport (= 3.1.3)
33
+ arel (~> 2.2.1)
34
+ tzinfo (~> 0.3.29)
35
+ activeresource (3.1.3)
36
+ activemodel (= 3.1.3)
37
+ activesupport (= 3.1.3)
38
+ activesupport (3.1.3)
39
+ multi_json (~> 1.0)
40
+ arel (2.2.1)
41
+ builder (3.0.0)
42
+ erubis (2.7.0)
43
+ execjs (1.2.12)
44
+ multi_json (~> 1.0)
45
+ hike (1.2.1)
46
+ i18n (0.6.0)
47
+ json (1.6.3)
48
+ mail (2.3.0)
49
+ i18n (>= 0.4.0)
50
+ mime-types (~> 1.16)
51
+ treetop (~> 1.4.8)
52
+ mime-types (1.17.2)
53
+ multi_json (1.0.4)
54
+ polyglot (0.3.3)
55
+ rack (1.3.5)
56
+ rack-cache (1.1)
57
+ rack (>= 0.4)
58
+ rack-mount (0.8.3)
59
+ rack (>= 1.0.0)
60
+ rack-ssl (1.3.2)
61
+ rack
62
+ rack-test (0.6.1)
63
+ rack (>= 1.0)
64
+ rails (3.1.3)
65
+ actionmailer (= 3.1.3)
66
+ actionpack (= 3.1.3)
67
+ activerecord (= 3.1.3)
68
+ activeresource (= 3.1.3)
69
+ activesupport (= 3.1.3)
70
+ bundler (~> 1.0)
71
+ railties (= 3.1.3)
72
+ railties (3.1.3)
73
+ actionpack (= 3.1.3)
74
+ activesupport (= 3.1.3)
75
+ rack-ssl (~> 1.3.2)
76
+ rake (>= 0.8.7)
77
+ rdoc (~> 3.4)
78
+ thor (~> 0.14.6)
79
+ rake (0.9.2.2)
80
+ rdoc (3.12)
81
+ json (~> 1.4)
82
+ sprockets (2.0.3)
83
+ hike (~> 1.2)
84
+ rack (~> 1.0)
85
+ tilt (!= 1.3.0, ~> 1.1)
86
+ thor (0.14.6)
87
+ tilt (1.3.3)
88
+ treetop (1.4.10)
89
+ polyglot
90
+ polyglot (>= 0.3.1)
91
+ tzinfo (0.3.31)
92
+
93
+ PLATFORMS
94
+ ruby
95
+
96
+ DEPENDENCIES
97
+ dust-rails!
data/README.markdown ADDED
@@ -0,0 +1,48 @@
1
+ # Dust-Rails
2
+
3
+ This gem adds the Dust template and a corresponding assets engine to the asset pipeline in Rails => 3.1 applications.
4
+
5
+ For detailed information about Dust, visit <http://akdubya.github.com/dustjs/>
6
+
7
+ ## Installing
8
+
9
+ Add the following line to your Gemfile:
10
+
11
+ gem 'dust-rails'
12
+
13
+ Update your bundle:
14
+
15
+ bundle install
16
+
17
+ ## Usage
18
+
19
+ Place individual Dust template file in their own file with `template_name.js.dust` extension:
20
+
21
+ ```javascript
22
+ /* app/assets/javascripts/dusts/demo.js.dust */
23
+
24
+ Hello {name}! You have {count} new messages.
25
+ ```
26
+
27
+ Which will be compiled and rendered as:
28
+
29
+ ```javascript
30
+ (function(){dust.register("demo",body_0);function body_0(chk,ctx){return chk.write("Hello ").reference(ctx.get("name"),ctx,"h").write("! You have ").reference(ctx.get("count"),ctx,"h").write(" new messages.");}return body_0;})();
31
+ ```
32
+
33
+
34
+ In your javascript files, require `dust-core` and your own template files.
35
+ I recommend you put all the template files under `assets/javascripts/dusts` and require using `require_tree` for easy use.
36
+
37
+ ```javascript
38
+ /* app/assets/javascripts/application.js */
39
+
40
+ //= require dust-core
41
+ //= require_tree ./dusts
42
+ ...
43
+ dust.render("demo", {name: "Fred", count: 10}, function(err, out) {
44
+ console.log(out);
45
+ });
46
+ ```
47
+
48
+ All done. Your template files will be compiled and registered.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "dust-rails/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "dust-rails"
7
+ s.version = Dust::Rails::VERSION
8
+ s.authors = ["Hoseong Hwang"]
9
+ s.email = ["thefron@wafflestudio.com"]
10
+ s.homepage = "https://github.com/thefron/dust-rails"
11
+ s.summary = %q{Use dust.js with rails}
12
+ s.description = %q{This gem makes you dust.js easy to use with rails.}
13
+
14
+ s.rubyforge_project = "dust-rails"
15
+
16
+ s.add_dependency('rails', '~> 3.1.0')
17
+ s.add_dependency('tilt')
18
+ s.add_dependency('execjs')
19
+
20
+ s.files = `git ls-files`.split("\n")
21
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
22
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
23
+ s.require_paths = ["lib"]
24
+ end
@@ -0,0 +1,40 @@
1
+ require 'tilt'
2
+ require 'execjs'
3
+
4
+ module Dust
5
+ module Rails
6
+
7
+ module Source
8
+ def self.path
9
+ @path ||= File.expand_path('../../../../vendor/assets/javascripts/dust-full-for-compile.js', __FILE__)
10
+ end
11
+
12
+ def self.contents
13
+ @contents ||= File.read(path)
14
+ end
15
+
16
+ def self.context
17
+ @context ||= ExecJS.compile(contents)
18
+ end
19
+
20
+ end
21
+
22
+ class DustTemplate < ::Tilt::Template
23
+
24
+ def self.default_mime_type
25
+ 'application/javascript'
26
+ end
27
+
28
+ def prepare
29
+ end
30
+
31
+ def evaluate(scope, locals, &block)
32
+ <<-TMPL
33
+ #{Source.context.call("dust.compile", data, basename('.js.dust'))}
34
+ TMPL
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+
@@ -0,0 +1,11 @@
1
+ require 'rails/engine'
2
+
3
+ module Dust
4
+ module Rails
5
+ class Engine < ::Rails::Engine
6
+ initializer :register_dustjs do |app|
7
+ app.assets.register_engine '.dust', DustTemplate
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ module Dust
2
+ module Rails
3
+ VERSION = "0.1.2"
4
+ end
5
+ end
data/lib/dust-rails.rb ADDED
@@ -0,0 +1,9 @@
1
+ require "dust-rails/version"
2
+ require "dust-rails/rails/engine.rb"
3
+ require "dust-rails/rails/dust_template.rb"
4
+
5
+ module Dust
6
+ module Rails
7
+ # Your code goes here...
8
+ end
9
+ end