js_render 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +16 -7
- data/examples/react/.gitignore +19 -0
- data/examples/react/Gemfile +50 -0
- data/examples/react/Gemfile.lock +171 -0
- data/examples/react/README.rdoc +28 -0
- data/examples/react/Rakefile +6 -0
- data/examples/react/app/assets/images/.keep +0 -0
- data/examples/react/app/assets/javascripts/application.js +16 -0
- data/examples/react/app/assets/javascripts/components/Counter/index.js +31 -0
- data/examples/react/app/assets/javascripts/components/Counter/renderClient.js +8 -0
- data/examples/react/app/assets/javascripts/components/Counter/renderServer.js +7 -0
- data/examples/react/app/assets/stylesheets/application.css +15 -0
- data/examples/react/app/assets/stylesheets/components/Counter.scss +6 -0
- data/examples/react/app/controllers/application_controller.rb +8 -0
- data/examples/react/app/controllers/concerns/.keep +0 -0
- data/examples/react/app/helpers/application_helper.rb +2 -0
- data/examples/react/app/mailers/.keep +0 -0
- data/examples/react/app/models/.keep +0 -0
- data/examples/react/app/models/concerns/.keep +0 -0
- data/examples/react/app/views/application/index.html.erb +7 -0
- data/examples/react/app/views/layouts/application.html.erb +14 -0
- data/examples/react/bin/bundle +3 -0
- data/examples/react/bin/rails +9 -0
- data/examples/react/bin/rake +9 -0
- data/examples/react/bin/setup +29 -0
- data/examples/react/bin/spring +15 -0
- data/examples/react/config/application.rb +31 -0
- data/examples/react/config/boot.rb +3 -0
- data/examples/react/config/database.yml +25 -0
- data/examples/react/config/environment.rb +5 -0
- data/examples/react/config/environments/development.rb +41 -0
- data/examples/react/config/environments/production.rb +79 -0
- data/examples/react/config/environments/test.rb +42 -0
- data/examples/react/config/initializers/assets.rb +11 -0
- data/examples/react/config/initializers/backtrace_silencers.rb +7 -0
- data/examples/react/config/initializers/cookies_serializer.rb +3 -0
- data/examples/react/config/initializers/filter_parameter_logging.rb +4 -0
- data/examples/react/config/initializers/inflections.rb +16 -0
- data/examples/react/config/initializers/js_render.rb +6 -0
- data/examples/react/config/initializers/mime_types.rb +4 -0
- data/examples/react/config/initializers/session_store.rb +3 -0
- data/examples/react/config/initializers/wrap_parameters.rb +14 -0
- data/examples/react/config/locales/en.yml +23 -0
- data/examples/react/config/routes.rb +3 -0
- data/examples/react/config/secrets.yml +22 -0
- data/examples/react/config.ru +4 -0
- data/examples/react/db/seeds.rb +7 -0
- data/examples/react/lib/assets/.keep +0 -0
- data/examples/react/lib/tasks/.keep +0 -0
- data/examples/react/log/.keep +0 -0
- data/examples/react/package.json +26 -0
- data/examples/react/public/404.html +67 -0
- data/examples/react/public/422.html +67 -0
- data/examples/react/public/500.html +66 -0
- data/examples/react/public/favicon.ico +0 -0
- data/examples/react/public/robots.txt +5 -0
- data/examples/react/test/controllers/.keep +0 -0
- data/examples/react/test/fixtures/.keep +0 -0
- data/examples/react/test/helpers/.keep +0 -0
- data/examples/react/test/integration/.keep +0 -0
- data/examples/react/test/mailers/.keep +0 -0
- data/examples/react/test/models/.keep +0 -0
- data/examples/react/test/test_helper.rb +10 -0
- data/examples/react/vendor/assets/javascripts/.keep +0 -0
- data/examples/react/vendor/assets/stylesheets/.keep +0 -0
- data/lib/js_render/asset_finder/base.rb +16 -0
- data/lib/js_render/asset_finder.rb +6 -0
- data/lib/js_render/errors.rb +18 -0
- data/lib/js_render/rails/asset_finder.rb +23 -0
- data/lib/js_render/rails/view_helpers.rb +0 -2
- data/lib/js_render/rails.rb +6 -0
- data/lib/js_render/renderer.rb +9 -19
- data/lib/js_render/version.rb +1 -1
- data/lib/js_render.rb +2 -0
- metadata +70 -2
data/lib/js_render/rails.rb
CHANGED
data/lib/js_render/renderer.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
require 'execjs'
|
2
|
+
require 'securerandom'
|
2
3
|
|
3
4
|
module JsRender
|
4
5
|
class Renderer
|
5
|
-
|
6
|
+
attr_reader :component_name, :json_data, :uuid
|
6
7
|
|
7
8
|
GLOBAL_CONTEXT = <<-JS
|
8
9
|
var global = global || this;
|
@@ -32,11 +33,11 @@ module JsRender
|
|
32
33
|
return '<span id="#{@uuid}">' + serverStr + '</span>';
|
33
34
|
})()
|
34
35
|
JS
|
35
|
-
renderer_code = js_context(
|
36
|
+
renderer_code = js_context(find_renderer_files)
|
36
37
|
context = ::ExecJS.compile(GLOBAL_CONTEXT + renderer_code)
|
37
38
|
context.eval(server_code)
|
38
39
|
rescue ExecJS::RuntimeError, ExecJS::ProgramError => error
|
39
|
-
raise
|
40
|
+
raise Errors::ServerRenderError::new(@component_name, @json_data, error)
|
40
41
|
end
|
41
42
|
|
42
43
|
def generate_client_script
|
@@ -51,7 +52,7 @@ module JsRender
|
|
51
52
|
|
52
53
|
private
|
53
54
|
|
54
|
-
def
|
55
|
+
def find_renderer_files
|
55
56
|
base_path = JsRender.config.base_path
|
56
57
|
paths = JsRender.config.component_paths
|
57
58
|
suffix = JsRender.config.component_suffix
|
@@ -64,24 +65,13 @@ module JsRender
|
|
64
65
|
end
|
65
66
|
|
66
67
|
def js_context(paths)
|
67
|
-
if defined?(::Rails) && JsRender.config.use_asset_pipeline
|
68
|
-
::
|
69
|
-
regex = ::Regexp.new(paths.join('|'))
|
70
|
-
abs_path.match(regex)
|
71
|
-
end.map do |abs_path|
|
72
|
-
::Rails.application.assets[abs_path].to_s
|
73
|
-
end.join('')
|
68
|
+
asset_finder = if defined?(::Rails) && JsRender.config.use_asset_pipeline
|
69
|
+
Rails::AssetFinder.new
|
74
70
|
else
|
75
|
-
|
71
|
+
AssetFinder::Base.new
|
76
72
|
end
|
73
|
+
paths.map { |path| asset_finder.find path }.join('')
|
77
74
|
end
|
78
75
|
end
|
79
76
|
|
80
|
-
class ServerRenderError < ::StandardError
|
81
|
-
def initialize(component_name, data, message)
|
82
|
-
message = ["Error \"#{message}\" when server rendering component, \"#{component_name}\", with data: \"#{data}\"",
|
83
|
-
message.backtrace.join("\n")].join("\n")
|
84
|
-
super(message)
|
85
|
-
end
|
86
|
-
end
|
87
77
|
end
|
data/lib/js_render/version.rb
CHANGED
data/lib/js_render.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: js_render
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonathan Lehman
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -83,6 +83,70 @@ files:
|
|
83
83
|
- Rakefile
|
84
84
|
- bin/console
|
85
85
|
- bin/setup
|
86
|
+
- examples/react/.gitignore
|
87
|
+
- examples/react/Gemfile
|
88
|
+
- examples/react/Gemfile.lock
|
89
|
+
- examples/react/README.rdoc
|
90
|
+
- examples/react/Rakefile
|
91
|
+
- examples/react/app/assets/images/.keep
|
92
|
+
- examples/react/app/assets/javascripts/application.js
|
93
|
+
- examples/react/app/assets/javascripts/components/Counter/index.js
|
94
|
+
- examples/react/app/assets/javascripts/components/Counter/renderClient.js
|
95
|
+
- examples/react/app/assets/javascripts/components/Counter/renderServer.js
|
96
|
+
- examples/react/app/assets/stylesheets/application.css
|
97
|
+
- examples/react/app/assets/stylesheets/components/Counter.scss
|
98
|
+
- examples/react/app/controllers/application_controller.rb
|
99
|
+
- examples/react/app/controllers/concerns/.keep
|
100
|
+
- examples/react/app/helpers/application_helper.rb
|
101
|
+
- examples/react/app/mailers/.keep
|
102
|
+
- examples/react/app/models/.keep
|
103
|
+
- examples/react/app/models/concerns/.keep
|
104
|
+
- examples/react/app/views/application/index.html.erb
|
105
|
+
- examples/react/app/views/layouts/application.html.erb
|
106
|
+
- examples/react/bin/bundle
|
107
|
+
- examples/react/bin/rails
|
108
|
+
- examples/react/bin/rake
|
109
|
+
- examples/react/bin/setup
|
110
|
+
- examples/react/bin/spring
|
111
|
+
- examples/react/config.ru
|
112
|
+
- examples/react/config/application.rb
|
113
|
+
- examples/react/config/boot.rb
|
114
|
+
- examples/react/config/database.yml
|
115
|
+
- examples/react/config/environment.rb
|
116
|
+
- examples/react/config/environments/development.rb
|
117
|
+
- examples/react/config/environments/production.rb
|
118
|
+
- examples/react/config/environments/test.rb
|
119
|
+
- examples/react/config/initializers/assets.rb
|
120
|
+
- examples/react/config/initializers/backtrace_silencers.rb
|
121
|
+
- examples/react/config/initializers/cookies_serializer.rb
|
122
|
+
- examples/react/config/initializers/filter_parameter_logging.rb
|
123
|
+
- examples/react/config/initializers/inflections.rb
|
124
|
+
- examples/react/config/initializers/js_render.rb
|
125
|
+
- examples/react/config/initializers/mime_types.rb
|
126
|
+
- examples/react/config/initializers/session_store.rb
|
127
|
+
- examples/react/config/initializers/wrap_parameters.rb
|
128
|
+
- examples/react/config/locales/en.yml
|
129
|
+
- examples/react/config/routes.rb
|
130
|
+
- examples/react/config/secrets.yml
|
131
|
+
- examples/react/db/seeds.rb
|
132
|
+
- examples/react/lib/assets/.keep
|
133
|
+
- examples/react/lib/tasks/.keep
|
134
|
+
- examples/react/log/.keep
|
135
|
+
- examples/react/package.json
|
136
|
+
- examples/react/public/404.html
|
137
|
+
- examples/react/public/422.html
|
138
|
+
- examples/react/public/500.html
|
139
|
+
- examples/react/public/favicon.ico
|
140
|
+
- examples/react/public/robots.txt
|
141
|
+
- examples/react/test/controllers/.keep
|
142
|
+
- examples/react/test/fixtures/.keep
|
143
|
+
- examples/react/test/helpers/.keep
|
144
|
+
- examples/react/test/integration/.keep
|
145
|
+
- examples/react/test/mailers/.keep
|
146
|
+
- examples/react/test/models/.keep
|
147
|
+
- examples/react/test/test_helper.rb
|
148
|
+
- examples/react/vendor/assets/javascripts/.keep
|
149
|
+
- examples/react/vendor/assets/stylesheets/.keep
|
86
150
|
- examples/vanilla_js/.gitignore
|
87
151
|
- examples/vanilla_js/Gemfile
|
88
152
|
- examples/vanilla_js/Gemfile.lock
|
@@ -148,8 +212,12 @@ files:
|
|
148
212
|
- examples/vanilla_js/vendor/assets/stylesheets/.keep
|
149
213
|
- js_render.gemspec
|
150
214
|
- lib/js_render.rb
|
215
|
+
- lib/js_render/asset_finder.rb
|
216
|
+
- lib/js_render/asset_finder/base.rb
|
151
217
|
- lib/js_render/configuration.rb
|
218
|
+
- lib/js_render/errors.rb
|
152
219
|
- lib/js_render/rails.rb
|
220
|
+
- lib/js_render/rails/asset_finder.rb
|
153
221
|
- lib/js_render/rails/railtie.rb
|
154
222
|
- lib/js_render/rails/view_helpers.rb
|
155
223
|
- lib/js_render/renderer.rb
|