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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 91475d4fce902235406761a1bf0a89f8ae285cd3
4
- data.tar.gz: 0c78bf23143e4741d14cb12e8686e226ee84ca34
3
+ metadata.gz: 706e807e7d95ba948b525406f0e993f9c670b382
4
+ data.tar.gz: 3a1ba52a293b182d3719894268b921fd64b1b4bb
5
5
  SHA512:
6
- metadata.gz: 2df709e5fad3b86d1920657c6f111cc0b4029a20079e1956dd5a272f1e54c372843e6c0465343284fa641279d9979916fdba7992071a272e336b2a977358b52c
7
- data.tar.gz: 8501b01779ae8e3a50d54ba5ac30950f3c9be7ce602ab22a9b76824c26606464b32e2767264d3aa58d85890e3e89d5e66a5b1b9e1e0d2a3b56219d05c709f8c3
6
+ metadata.gz: acb6732aae97a81c4abe1366d8d3a78e60009728c255b1d5c92af8dc9be158214f52eb566cf7fe4d54353c310fd30e1571f7125c06429087d304562b5849a230
7
+ data.tar.gz: b6476f5740cf2dce36433584e220b7e576052cd51d39f2f699d82a23a17841e06eba11ca59f6b6c4a005a885d469279bbc0f583bcba60db4e7a89e9880330881
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ test/js/node_modules
data/README.md CHANGED
@@ -8,14 +8,18 @@ First, add complate to your Gemfile:
8
8
  gem "complate"
9
9
  ```
10
10
 
11
- Add this to your `ApplicationController`:
11
+ To render the NameOfView macro in your actions with two parameters:
12
12
 
13
13
  ```ruby
14
- include Complate::Rails::ActionControllerExtensions
14
+ complate("NameOfView", param_1: "x", param_2: "y")
15
15
  ```
16
16
 
17
- To render something in your actions:
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(signature, to, be, determined)
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
@@ -7,4 +7,10 @@ Rake::TestTask.new(:test) do |t|
7
7
  t.test_files = FileList['test/**/*_test.rb']
8
8
  end
9
9
 
10
+ task :build_js_testdata do
11
+ Dir.chdir 'test/js' do
12
+ exec 'npm run compile'
13
+ end
14
+ end
15
+
10
16
  task :default => :test
@@ -1,4 +1,3 @@
1
1
  require 'complate/version'
2
2
  require 'complate/renderer'
3
-
4
- require 'complate/rails/engine' if Kernel.const_defined?(:Rails)
3
+ require 'complate/railtie' if Kernel.const_defined?(:Rails)
@@ -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
@@ -1,55 +1,28 @@
1
1
  require 'therubyracer'
2
-
3
- require 'complate/version'
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
- @cxt = V8::Context.new
9
- @cxt['console'] = Console.new
10
+ @context = V8::Context.new
10
11
  context_files.each do |file|
11
- @cxt.load(file)
12
+ @context.load(file)
12
13
  end
13
14
  end
14
15
 
15
- def render(*args)
16
+ def render(view, params = {})
16
17
  Stream.new do |stream|
17
- @cxt.scope.render(stream, *args)
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
- def writeln(str)
35
- write("#{str}\n")
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
@@ -1,3 +1,3 @@
1
1
  module Complate
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
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.1
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: 2017-10-20 00:00:00.000000000 Z
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/rails/engine.rb
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.11
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