render-react 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/render/react/compiler.rb +22 -13
- data/lib/render/react/config.rb +3 -1
- data/lib/render/react/version.rb +1 -1
- data/lib/render/react.rb +2 -2
- data/render-react.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ddd5c97adcd6ba8d8c1a2a594f5da398da5cc2d5
|
4
|
+
data.tar.gz: 53670580d70661bf44f81713ababbebe7093fb44
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f48287b850dc575b70231c3bcc2b922480d0f5496d805bb4a0933f8958dd542e9a0b9237bd37ac67825abf09f5cc226581e80c4415d79b85c4e04229de0df29e
|
7
|
+
data.tar.gz: 39420f25acaf5124b3b1e6abb5b0f917c92ab81456ee108877f0c397aa6792ad0ded243eec207d132fbd8949f07475ab3123ceb35864a039b69cd517a29f094f
|
@@ -5,9 +5,9 @@ module Render
|
|
5
5
|
@lookup ||= {}
|
6
6
|
end
|
7
7
|
|
8
|
-
def
|
9
|
-
return @cxt if @cxt
|
8
|
+
def create_context
|
10
9
|
@cxt = Config.new_context
|
10
|
+
@durability = Config::CONTEXT_DURABILITY
|
11
11
|
|
12
12
|
js_lib_files = Dir.glob(
|
13
13
|
File.join(
|
@@ -17,36 +17,45 @@ module Render
|
|
17
17
|
'*.js'
|
18
18
|
)
|
19
19
|
)
|
20
|
-
js_lib_files.each { |file| @cxt.load(file) }
|
21
20
|
|
22
|
-
@cxt
|
21
|
+
js_lib_files.each { |file| @cxt.load(file) }
|
23
22
|
end
|
24
23
|
|
25
|
-
def
|
26
|
-
|
24
|
+
def bootstrap
|
25
|
+
if @durability && @durability <= 0
|
26
|
+
@cxt.destroy
|
27
|
+
@cxt = nil
|
28
|
+
end
|
29
|
+
|
30
|
+
create_context unless @cxt
|
31
|
+
|
27
32
|
Config.paths.each do |path|
|
28
33
|
files = Dir.glob(File.join(path, '**', '*.js'))
|
29
34
|
files.each do |filename|
|
30
35
|
name, code = Transpiler.babelify(filename)
|
31
|
-
cxt.eval(code)
|
36
|
+
@cxt.eval(code)
|
32
37
|
lookup[name.to_sym] = true
|
33
38
|
end
|
34
39
|
end
|
35
|
-
|
40
|
+
|
41
|
+
@durability -= 1
|
36
42
|
end
|
37
43
|
|
38
44
|
def render(component_class, **props)
|
39
45
|
unless lookup[component_class.to_sym]
|
40
46
|
raise "#{component_class} component not found."
|
41
47
|
end
|
42
|
-
cxt.eval <<-EOS
|
43
|
-
|
44
|
-
|
45
|
-
);
|
48
|
+
@cxt.eval <<-EOS
|
49
|
+
var component = React.createElement(#{component_class}, #{JSON.dump(props)});
|
50
|
+
ReactDOMServer.renderToString(component);
|
46
51
|
EOS
|
47
52
|
end
|
48
53
|
|
49
|
-
|
54
|
+
def evaljs(code)
|
55
|
+
@cxt.eval(code)
|
56
|
+
end
|
57
|
+
|
58
|
+
module_function :bootstrap, :create_context, :render, :lookup, :evaljs
|
50
59
|
end
|
51
60
|
end
|
52
61
|
end
|
data/lib/render/react/config.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
module Render
|
2
2
|
module React
|
3
3
|
module Config
|
4
|
+
CONTEXT_DURABILITY = 100_000
|
5
|
+
|
4
6
|
def path(*paths)
|
5
7
|
@paths ||= []
|
6
8
|
@paths += paths
|
@@ -11,7 +13,7 @@ module Render
|
|
11
13
|
end
|
12
14
|
|
13
15
|
def new_context
|
14
|
-
|
16
|
+
V8::Context.new
|
15
17
|
end
|
16
18
|
|
17
19
|
def gem_js_path
|
data/lib/render/react/version.rb
CHANGED
data/lib/render/react.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'json'
|
2
|
-
require '
|
2
|
+
require 'v8'
|
3
3
|
require 'active_support/inflector'
|
4
4
|
|
5
5
|
require 'render/react/config'
|
@@ -10,7 +10,7 @@ require 'render/react/version'
|
|
10
10
|
module Render
|
11
11
|
module React
|
12
12
|
def render_react(component_class, **props)
|
13
|
-
Compiler.
|
13
|
+
Compiler.bootstrap
|
14
14
|
"<span data-react-isomorphic='true' " \
|
15
15
|
"data-react-component='#{component_class}' " \
|
16
16
|
"data-react-props='#{JSON.dump(props)}'>" \
|
data/render-react.gemspec
CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.bindir = "exe"
|
18
18
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
19
|
|
20
|
-
spec.add_dependency "
|
20
|
+
spec.add_dependency "therubyracer"
|
21
21
|
spec.add_dependency "activesupport"
|
22
22
|
spec.require_paths = ["lib"]
|
23
23
|
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: render-react
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Krasnoschekov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-08-
|
11
|
+
date: 2016-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: therubyracer
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|