complate 0.0.1 → 0.0.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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +8 -4
- data/Rakefile +6 -0
- data/lib/complate.rb +1 -2
- data/lib/complate/logger_wrapper.rb +30 -0
- data/lib/complate/railtie.rb +20 -0
- data/lib/complate/renderer.rb +12 -39
- data/lib/complate/stream.rb +29 -0
- data/lib/complate/version.rb +1 -1
- metadata +6 -4
- data/lib/complate/rails/engine.rb +0 -21
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 706e807e7d95ba948b525406f0e993f9c670b382
|
|
4
|
+
data.tar.gz: 3a1ba52a293b182d3719894268b921fd64b1b4bb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: acb6732aae97a81c4abe1366d8d3a78e60009728c255b1d5c92af8dc9be158214f52eb566cf7fe4d54353c310fd30e1571f7125c06429087d304562b5849a230
|
|
7
|
+
data.tar.gz: b6476f5740cf2dce36433584e220b7e576052cd51d39f2f699d82a23a17841e06eba11ca59f6b6c4a005a885d469279bbc0f583bcba60db4e7a89e9880330881
|
data/.gitignore
CHANGED
data/README.md
CHANGED
|
@@ -8,14 +8,18 @@ First, add complate to your Gemfile:
|
|
|
8
8
|
gem "complate"
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
To render the NameOfView macro in your actions with two parameters:
|
|
12
12
|
|
|
13
13
|
```ruby
|
|
14
|
-
|
|
14
|
+
complate("NameOfView", param_1: "x", param_2: "y")
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
This gem expect your bundle to be located in `dist/bundle.js`, but you can
|
|
18
|
+
reconfigure that with:
|
|
18
19
|
|
|
19
20
|
```ruby
|
|
20
|
-
complate
|
|
21
|
+
config.complate.bundle_path = Rails.root.join("bundle.js")
|
|
21
22
|
```
|
|
23
|
+
|
|
24
|
+
See https://github.com/complate/complate-ruby/tree/master/test/js how a very
|
|
25
|
+
simple complate/faucet setup for your project might look like.
|
data/Rakefile
CHANGED
data/lib/complate.rb
CHANGED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
module Complate
|
|
2
|
+
class LoggerWrapper
|
|
3
|
+
def initialize(logger)
|
|
4
|
+
@logger = logger
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def info(*msg)
|
|
8
|
+
@logger.info(format_message(msg))
|
|
9
|
+
end
|
|
10
|
+
alias log info
|
|
11
|
+
|
|
12
|
+
def warn(*msg)
|
|
13
|
+
@logger.warn(format_message(msg))
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def error(*msg)
|
|
17
|
+
@logger.error(format_message(msg))
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def debug(*msg)
|
|
21
|
+
@logger.debug(format_message(msg))
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
def format_message(msg)
|
|
27
|
+
msg.join(" ")
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require 'complate/renderer'
|
|
2
|
+
|
|
3
|
+
module Complate
|
|
4
|
+
class Railtie < Rails::Railtie
|
|
5
|
+
config.complate = ActiveSupport::OrderedOptions.new
|
|
6
|
+
|
|
7
|
+
ActiveSupport.on_load(:action_controller) do
|
|
8
|
+
define_method(:complate) do |*args|
|
|
9
|
+
renderer = Complate::Renderer.new(Rails.configuration.complate.bundle_path)
|
|
10
|
+
renderer.context['rails'] = self.helpers
|
|
11
|
+
renderer.logger = ::Rails.logger
|
|
12
|
+
self.response_body = renderer.render(*args)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
initializer "complate.configure_bundle_path" do |app|
|
|
17
|
+
app.config.complate.bundle_path ||= app.root.join("dist", "bundle.js")
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
data/lib/complate/renderer.rb
CHANGED
|
@@ -1,55 +1,28 @@
|
|
|
1
1
|
require 'therubyracer'
|
|
2
|
-
|
|
3
|
-
require 'complate/
|
|
2
|
+
require 'complate/stream'
|
|
3
|
+
require 'complate/logger_wrapper'
|
|
4
4
|
|
|
5
5
|
module Complate
|
|
6
6
|
class Renderer
|
|
7
|
+
attr_reader :context
|
|
8
|
+
|
|
7
9
|
def initialize(*context_files)
|
|
8
|
-
@
|
|
9
|
-
@cxt['console'] = Console.new
|
|
10
|
+
@context = V8::Context.new
|
|
10
11
|
context_files.each do |file|
|
|
11
|
-
@
|
|
12
|
+
@context.load(file)
|
|
12
13
|
end
|
|
13
14
|
end
|
|
14
15
|
|
|
15
|
-
def render(
|
|
16
|
+
def render(view, params = {})
|
|
16
17
|
Stream.new do |stream|
|
|
17
|
-
|
|
18
|
+
# The signature is:
|
|
19
|
+
# (view, params, stream, { fragment }, callback)
|
|
20
|
+
@context.scope.render(view, params, stream, {})
|
|
18
21
|
end
|
|
19
22
|
end
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
class Console
|
|
23
|
-
def log(*msg)
|
|
24
|
-
puts msg
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
class Stream < Enumerator
|
|
29
|
-
def initialize(&block)
|
|
30
|
-
@after_start = block
|
|
31
|
-
@buf = ''
|
|
32
|
-
end
|
|
33
23
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def write(str)
|
|
39
|
-
@buf << str
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
def each(&block)
|
|
43
|
-
@block = block
|
|
44
|
-
@after_start.call(self)
|
|
45
|
-
flush
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
def flush(*_)
|
|
49
|
-
if @block && @buf != ''
|
|
50
|
-
@block.call(@buf)
|
|
51
|
-
@buf = ''
|
|
52
|
-
end
|
|
24
|
+
def logger=(logger)
|
|
25
|
+
@context['console'] = LoggerWrapper.new(logger)
|
|
53
26
|
end
|
|
54
27
|
end
|
|
55
28
|
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module Complate
|
|
2
|
+
class Stream < Enumerator
|
|
3
|
+
def initialize(&block)
|
|
4
|
+
@after_start = block
|
|
5
|
+
@buf = ''
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def writeln(str)
|
|
9
|
+
write("#{str}\n")
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def write(str)
|
|
13
|
+
@buf << str
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def each(&block)
|
|
17
|
+
@block = block
|
|
18
|
+
@after_start.call(self)
|
|
19
|
+
flush
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def flush(*_)
|
|
23
|
+
if @block && @buf != ''
|
|
24
|
+
@block.call(@buf)
|
|
25
|
+
@buf = ''
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
data/lib/complate/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: complate
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Till Schulte-Coerne
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date:
|
|
12
|
+
date: 2018-08-22 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: therubyracer
|
|
@@ -83,8 +83,10 @@ files:
|
|
|
83
83
|
- Rakefile
|
|
84
84
|
- complate.gemspec
|
|
85
85
|
- lib/complate.rb
|
|
86
|
-
- lib/complate/
|
|
86
|
+
- lib/complate/logger_wrapper.rb
|
|
87
|
+
- lib/complate/railtie.rb
|
|
87
88
|
- lib/complate/renderer.rb
|
|
89
|
+
- lib/complate/stream.rb
|
|
88
90
|
- lib/complate/version.rb
|
|
89
91
|
homepage: ''
|
|
90
92
|
licenses: []
|
|
@@ -105,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
105
107
|
version: '0'
|
|
106
108
|
requirements: []
|
|
107
109
|
rubyforge_project:
|
|
108
|
-
rubygems_version: 2.6.
|
|
110
|
+
rubygems_version: 2.6.14.1
|
|
109
111
|
signing_key:
|
|
110
112
|
specification_version: 4
|
|
111
113
|
summary: Complate JSX on the server magic for ruby
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
module Complate
|
|
2
|
-
module Rails
|
|
3
|
-
|
|
4
|
-
class Engine < ::Rails::Engine
|
|
5
|
-
end
|
|
6
|
-
|
|
7
|
-
module ActionControllerExtensions
|
|
8
|
-
|
|
9
|
-
extend ActiveSupport::Concern
|
|
10
|
-
|
|
11
|
-
def complate(*args)
|
|
12
|
-
headers['X-Accel-Buffering'] = 'no' # Stop NGINX from buffering
|
|
13
|
-
headers['Cache-Control'] = 'no-cache' # Stop downstream caching
|
|
14
|
-
headers.delete('Content-Length') # See one line above
|
|
15
|
-
|
|
16
|
-
renderer = Complate::Renderer.new('dist/bundle.js')
|
|
17
|
-
self.response_body = renderer.render(*args)
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|