react_rb 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 136f41b89ddeb2ce6c117b2fa94fe7e08bf2f357694aeac774d17b458e8f6f01
4
+ data.tar.gz: 76e62f1b2cdbe92ab6fd438e7caea9fae36fb334ae254d00446b8fa72c58603d
5
+ SHA512:
6
+ metadata.gz: 1ba2c4a170fb13ebfa63862e733f1842ea72345470752399771929b84ef6c282091547b8febe8416bd36ab7e66b15c47cb708d5ff2224df632d9a03f2ce9b2ad
7
+ data.tar.gz: 81f5e30c01ee04b75526aba173c1dee3145e0fe6d6951c52fe49bd1d61a27f14da1a5b3d3cc09d0dcb7d82f606fc0118b8f2a1fabfd2fd04aa53b6f34e1feb9c
@@ -0,0 +1,3 @@
1
+ module ReactRB; end
2
+
3
+ require "react_rb/railtie" if defined?(Rails)
@@ -0,0 +1,12 @@
1
+ module ReactRB
2
+ class Form
3
+ include ActiveModel::AttributeAssignment
4
+ include ActiveModel::Validations
5
+
6
+ def initialize(attributes = {})
7
+ assign_attributes(attributes) if attributes
8
+
9
+ super()
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,22 @@
1
+ require_relative "renderer"
2
+ require_relative "form"
3
+
4
+ module ReactRB
5
+ class Railtie < Rails::Railtie
6
+
7
+ config.to_prepare do
8
+ ActionController::Renderers.add :page do |page, options|
9
+ ReactRB::Renderer.new(
10
+ controller: self,
11
+ page: page,
12
+ render: method(:render),
13
+ request: request,
14
+ response: response,
15
+ props: options[:props],
16
+ html_attrs: options[:html_attrs],
17
+ title: options[:title]
18
+ ).render
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ class ReactRB::Renderer
2
+ def initialize(controller:, page:, render:, request:, response:, props:, html_attrs:, title: nil)
3
+ @page = page
4
+ @render = render
5
+ @request = request
6
+ @response = response
7
+ @props = props || {}
8
+ @html_attrs = html_attrs || {}
9
+
10
+ controller.instance_variable_set("@pagetitle", title) if title.present?
11
+ controller.instance_variable_set("@__react_page", true)
12
+ end
13
+
14
+ def render
15
+ @response.headers["Vary"] = "Accept"
16
+ if @request.headers["X-React-Pack"]
17
+ @render.call json: { props: @props, page: @page }
18
+ else
19
+ @render.call "react/page", locals: { page: @page, props: @props, html_attrs: { **@html_attrs, data: { page: @page } } }
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,5 @@
1
+ require_relative "./spec_helper"
2
+
3
+ RSpec.describe ReactRB::Renderer do
4
+
5
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "react_rb"
4
+
5
+ RSpec.configure do |config|
6
+ config.expect_with :rspec do |expectations|
7
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
8
+ end
9
+
10
+ config.mock_with :rspec do |mocks|
11
+ mocks.verify_partial_doubles = true
12
+ end
13
+
14
+ config.filter_run :focus
15
+ config.run_all_when_everything_filtered = true
16
+
17
+ config.disable_monkey_patching!
18
+
19
+ # This setting enables warnings. It's recommended, but in some cases may
20
+ # be too noisy due to issues in dependencies.
21
+ config.warnings = true
22
+
23
+ # Many RSpec users commonly either run the entire suite or an individual
24
+ # file, and it's useful to allow more verbose output when running an
25
+ # individual spec file.
26
+ if config.files_to_run.one?
27
+ # Use the documentation formatter for detailed output,
28
+ # unless a formatter has already been configured
29
+ # (e.g. via a command-line flag).
30
+ config.default_formatter = 'doc'
31
+ end
32
+
33
+ # Print the 10 slowest examples and example groups at the
34
+ # end of the spec run, to help surface which specs are running
35
+ # particularly slow.
36
+ config.profile_examples = 10
37
+
38
+ # Run specs in random order to surface order dependencies. If you find an
39
+ # order dependency and want to debug it, you can fix the order by providing
40
+ # the seed, which is printed after each run.
41
+ # --seed 1234
42
+ config.order = :random
43
+
44
+ # Seed global randomization in this process using the `--seed` CLI option.
45
+ # Setting this allows you to use `--seed` to deterministically reproduce
46
+ # test failures related to randomization by passing the same `--seed` value
47
+ # as the one that triggered the failure.
48
+ Kernel.srand config.seed
49
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: react_rb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - ConvertKit
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-06-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description:
42
+ email:
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - lib/react_rb.rb
48
+ - lib/react_rb/form.rb
49
+ - lib/react_rb/railtie.rb
50
+ - lib/react_rb/renderer.rb
51
+ - lib/spec/renderer_spec.rb
52
+ - lib/spec/spec_helper.rb
53
+ homepage:
54
+ licenses: []
55
+ metadata: {}
56
+ post_install_message:
57
+ rdoc_options: []
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ requirements: []
71
+ rubyforge_project:
72
+ rubygems_version: 2.7.6.2
73
+ signing_key:
74
+ specification_version: 4
75
+ summary: A library for working with React & Rails
76
+ test_files: []