dusty_rails_renderer 0.1.5 → 0.2.0
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.
- checksums.yaml +4 -4
- data/README.md +2 -1
- data/dusty_rails_renderer.gemspec +1 -1
- data/lib/dusty_rails_renderer.rb +21 -25
- data/lib/dusty_rails_renderer/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 77021db12f8dccc2db6ef8ec7bc81897b1f214e8
|
4
|
+
data.tar.gz: 2927c5d786e0cf711d1139b50dfbdc02f48edc45
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b08985d018a6ec096b423436f09b0203676bd26d63428b7d166d8e85d3a63174d49e8f63170ae74b69f448eafe073dbd6b9b232ddd15f9b993378c9d1b88c28
|
7
|
+
data.tar.gz: 700cbc07f10ea9b3e7d651da2fcd13ed7a3b4d4324da5867731792f6fa8666b00bae87338ce609b4f9e980864b800b48d06f8c02b1458ba360238e78dae76629
|
data/README.md
CHANGED
@@ -35,6 +35,7 @@ dust_initializer.rb
|
|
35
35
|
$ config.dust_js_library_path = 'app/assets/javascripts/libraries/dust/dust-full.js'
|
36
36
|
$ config.dust_template_base_path = 'app/assets/javascripts/dust/'
|
37
37
|
$ config.production = false
|
38
|
+
$ config.node_dust_compiler = false
|
38
39
|
$ end
|
39
40
|
|
40
41
|
$ DustyRailsRenderer.initialize
|
@@ -42,7 +43,7 @@ dust_initializer.rb
|
|
42
43
|
|
43
44
|
By configuring the initializer you can update the location of your Dust templates and Dust.js library. For this gem to work property you must use the full Dust library that includes the compiler. Lastly, setting config.production = false will enable loading from disk and precompiling during request time. This
|
44
45
|
feature is great for debugging and creating new templates but not for production. Setting config.production = true will precompile the templates once
|
45
|
-
during the server initialization process and load the templates into memory.
|
46
|
+
during the server initialization process and load the templates into memory. Setting config.node_dust_compiler = true will activate precompiling templates with dustc (dustjs-linkedin npm package).
|
46
47
|
|
47
48
|
## Usage
|
48
49
|
|
@@ -29,5 +29,5 @@ Gem::Specification.new do |spec|
|
|
29
29
|
|
30
30
|
spec.add_development_dependency "bundler", "~> 1.10"
|
31
31
|
spec.add_development_dependency "rake", "~> 10.0"
|
32
|
-
spec.add_development_dependency "
|
32
|
+
spec.add_development_dependency "therubyracer", "~> 0.12.2"
|
33
33
|
end
|
data/lib/dusty_rails_renderer.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
require "singleton"
|
2
2
|
require "dusty_rails_renderer/version"
|
3
|
-
require "
|
3
|
+
require "open3"
|
4
4
|
|
5
5
|
module DustyRailsRenderer
|
6
6
|
class << self
|
7
7
|
include Singleton
|
8
|
+
include ActionView::Helpers::JavaScriptHelper
|
8
9
|
attr_writer :configuration
|
9
10
|
|
10
11
|
#Initialize, load Dust.js library, and precompile Dust.js templates
|
@@ -12,7 +13,9 @@ module DustyRailsRenderer
|
|
12
13
|
@dust_config = YAML.load_file(self.configuration.dust_config_path)
|
13
14
|
@dust_library = File.read(self.configuration.dust_js_library_path)
|
14
15
|
@precompiled_templates = Hash.new
|
15
|
-
|
16
|
+
@context = V8::Context.new
|
17
|
+
@context.eval(@dust_library, 'dustjs')
|
18
|
+
|
16
19
|
read_dust_files
|
17
20
|
end
|
18
21
|
|
@@ -25,7 +28,6 @@ module DustyRailsRenderer
|
|
25
28
|
if self.configuration.production
|
26
29
|
@context.eval("(function() { var result; dust.render('#{template_name}', #{json}, function(err, out) { result = out; }); return result; })()")
|
27
30
|
else
|
28
|
-
|
29
31
|
read_dust_files
|
30
32
|
@context.eval("(function() { var result; dust.render('#{template_name}', #{json}, function(err, out) { result = out; }); return result; })()")
|
31
33
|
end
|
@@ -34,28 +36,20 @@ module DustyRailsRenderer
|
|
34
36
|
private
|
35
37
|
#Read in and register Dust.js templates
|
36
38
|
def read_dust_files
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
@context = ExecJS.compile(@dust_library + js_content)
|
53
|
-
|
54
|
-
file_content_store.each do |content_map|
|
55
|
-
content = content_map['content']
|
56
|
-
template_name = content_map['template_name']
|
57
|
-
template = @context.call("dust.compile","#{content}","#template_name}")
|
58
|
-
@precompiled_templates[template_name] = template
|
39
|
+
@dust_config.each do |template, info|
|
40
|
+
file_url = self.configuration.dust_template_base_path + info["file_path"]
|
41
|
+
template_name = info["name"]
|
42
|
+
if self.configuration.node_dust_compiler
|
43
|
+
command = "dustc --name=#{template_name} #{file_url}"
|
44
|
+
template = Open3.capture3("bash","-c",command)
|
45
|
+
escaped_template = escape_javascript(template[0])
|
46
|
+
@context.eval("dust.loadSource(\"#{escaped_template}\")")
|
47
|
+
@precompiled_templates[template_name] = template[0]
|
48
|
+
else
|
49
|
+
contents = File.read(file_url).gsub("\n","").gsub("\"","'").gsub("\t","")
|
50
|
+
template = @context.eval("(function() {var template = dust.compile(\"#{contents}\",'#{template_name}'); dust.loadSource(template); return template; })()")
|
51
|
+
@precompiled_templates[template_name] = template
|
52
|
+
end
|
59
53
|
end
|
60
54
|
end
|
61
55
|
end
|
@@ -73,12 +67,14 @@ module DustyRailsRenderer
|
|
73
67
|
attr_accessor :dust_js_library_path
|
74
68
|
attr_accessor :production
|
75
69
|
attr_accessor :dust_template_base_path
|
70
|
+
attr_accessor :node_dust_compiler
|
76
71
|
|
77
72
|
def initialize
|
78
73
|
@dust_config_path = "config/dust_initializer.yml"
|
79
74
|
@dust_js_library_path = "app/assets/javascripts/libraries/dust/dust-full.js"
|
80
75
|
@dust_template_base_path = "app/assets/javascripts/dust/"
|
81
76
|
@production = false
|
77
|
+
@node_dust_compiler = false
|
82
78
|
end
|
83
79
|
end
|
84
80
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dusty_rails_renderer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Louis Ellis
|
@@ -39,19 +39,19 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: therubyracer
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 0.12.2
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 0.12.2
|
55
55
|
description: Render Dust server side
|
56
56
|
email: Louis.f.ellis@gmail.com
|
57
57
|
executables: []
|