dusty_rails_renderer 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dusty_rails_renderer/version.rb +1 -1
- data/lib/dusty_rails_renderer.rb +39 -38
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a5f0511e19fad284e05ed4aa5eb0df00cbd8bcc
|
4
|
+
data.tar.gz: 3aafe27812a9187c315fb6d48db545e500a64f9b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5884e283eea8928fae1629777d502d2333bf4f79ebd6d57326b62839a240e56e20422ff79d84bfc54e304880622070f5ae6f3295b95a58e81b7f80dc21c56350
|
7
|
+
data.tar.gz: fa6a42ebe494c248a561bb8cc29b889026ce0c6bcac2b327de8830584f6494b570651a43e7484155c7e69c74a462a47b0f9eee47456f331d28ea44fdca93bf98
|
data/lib/dusty_rails_renderer.rb
CHANGED
@@ -3,48 +3,49 @@ require "dusty_rails_renderer/version"
|
|
3
3
|
|
4
4
|
module DustyRailsRenderer
|
5
5
|
class << self
|
6
|
-
|
7
|
-
|
6
|
+
include Singleton
|
7
|
+
attr_writer :configuration
|
8
8
|
|
9
9
|
#Initialize, load Dust.js library, and precompile Dust.js templates
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
10
|
+
def initialize
|
11
|
+
@dust_config = YAML.load_file(self.configuration.dust_config_path)
|
12
|
+
@dust_library = File.read(self.configuration.dust_js_library_path)
|
13
|
+
@precompiled_templates = Hash.new
|
14
|
+
@context = V8::Context.new
|
15
|
+
@context.eval(@dust_library, 'dustjs')
|
16
16
|
|
17
|
-
|
18
|
-
|
17
|
+
read_dust_files
|
18
|
+
end
|
19
19
|
|
20
20
|
#Return precompiled templates in JSON format (Client-side)
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
def templates
|
22
|
+
@precompiled_templates.to_json
|
23
|
+
end
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
25
|
+
def render(template_name, json)
|
26
|
+
if self.configuration.production
|
27
|
+
@context.eval("(function() { var result; dust.render('#{template_name}', #{json}, function(err, out) { result = out; }); return result; })()")
|
28
|
+
else
|
29
|
+
#Reset Context
|
30
|
+
@context = V8::Context.new
|
31
|
+
@context.eval(@dust_library, 'dustjs')
|
32
|
+
|
33
|
+
read_dust_files
|
34
|
+
@context.eval("(function() { var result; dust.render('#{template_name}', #{json}, function(err, out) { result = out; }); return result; })()")
|
35
|
+
end
|
36
|
+
end
|
34
37
|
|
35
38
|
private
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
end
|
47
|
-
end
|
39
|
+
#Read in and register Dust.js templates
|
40
|
+
def read_dust_files
|
41
|
+
@dust_config.each do |template, info|
|
42
|
+
file_url = self.configuration.dust_template_base_path + info["file_path"]
|
43
|
+
template_name = info["name"]
|
44
|
+
contents = File.read(file_url).gsub("\n","").gsub("\"","'").gsub("\t","")
|
45
|
+
template = @context.eval("(function() {var template = dust.compile(\"#{contents}\",'#{template_name}'); dust.loadSource(template); return template; })()")
|
46
|
+
@precompiled_templates[template_name] = template
|
47
|
+
end
|
48
|
+
end
|
48
49
|
end
|
49
50
|
|
50
51
|
def self.configure
|
@@ -62,10 +63,10 @@ module DustyRailsRenderer
|
|
62
63
|
attr_accessor :dust_template_base_path
|
63
64
|
|
64
65
|
def initialize
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
66
|
+
@dust_config_path = "config/dust_initializer.yml"
|
67
|
+
@dust_js_library_path = "app/assets/javascripts/libraries/dust/dust-full.js"
|
68
|
+
@dust_template_base_path = "app/assets/javascripts/dust/"
|
69
|
+
@production = false
|
69
70
|
end
|
70
71
|
end
|
71
72
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dusty_rails_renderer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Louis Ellis
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|