quilt_rails 1.0.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 79df4e26acc8f810e8a721f77915f4a4d4ccd303b99fa7f0707664ce7fee54d3
4
+ data.tar.gz: 3864feba212ae32c9e22935e43ecf3f48a3d7565f25dca7a9c08993e9e01d295
5
+ SHA512:
6
+ metadata.gz: e47642a175372f74193cac2016edb7198069d18ad2f81714892507b114966627a75765f53af510a16d81ba7ef16b9bd1973a6471b10591688b84682ea89629f0
7
+ data.tar.gz: 7c772564b14727ccd3e92cdcaaf6e35f54e1f28061d7d0e1918bf4c2ea5d05fe976356882e92d19409e6c1d2296b6304a3b6941b2180701b3bc39c65a63b4c0a
data/README.md ADDED
@@ -0,0 +1,82 @@
1
+ # quilt_rails
2
+
3
+ A turn-key solution for integrating server-rendered react into your Rails app using Quilt libraries.
4
+
5
+ This document focuses on Rails integration. For details of `@shopify/react-server`'s configuration and usage, see the [react-server documentation](/packages/react-server/README.md).
6
+
7
+ ## Quick Start
8
+
9
+ Create a Rails project using `dev init` then:
10
+
11
+ ### Install Dependencies
12
+
13
+ ```sh
14
+ # Add Ruby/Node dependencies
15
+ bundle add sewing_kit quilt_rails
16
+ yarn add @shopify/sewing-kit @shopify/react-server
17
+
18
+ # Optional - add Polaris and quilt libraries
19
+ yarn add @shopify/polaris @shopify/react-self-serializers react react-dom
20
+
21
+ yarn
22
+ dev up
23
+ ```
24
+
25
+ ### Add JavaScript
26
+
27
+ sewing_kit looks for JavaScript in `app/ui/index.js`. The code in `index.js` (and any imported JS/CSS) will be built into a `main` bundle.
28
+
29
+ ### Setup your react controller and routes
30
+
31
+ Create a `ReactController` to handle react requests.
32
+
33
+ ```ruby
34
+ class ReactController < ApplicationController
35
+ include Quilt::ReactRenderable
36
+
37
+ def index
38
+ render_react
39
+ end
40
+ end
41
+ ```
42
+
43
+ Have your routes wired up to default to your react controller.
44
+
45
+ ```ruby
46
+ get '/*path', to: 'react#index'
47
+ root 'react#index'
48
+ ```
49
+
50
+ ## Minimal Project Layout
51
+
52
+ ```
53
+ ├── Gemfile (must contain "gem 'sewing_kit" and "gem 'quilt_rails'")
54
+ ├── package.json (must specify '@shopify/sewing-kit' and `@shopify/react-server` as 'dependencies')
55
+
56
+ └── app
57
+ └── ui
58
+ │ └─- index.js
59
+ └── controllers
60
+ └─- react_controller (see above)
61
+ ```
62
+
63
+ ## Example minimal React/Polaris/Quilt entrypoint
64
+
65
+ ```tsx
66
+ // app/ui/index.tsx
67
+
68
+ import * as React from 'react';
69
+ import {AppProvider, Page, Card} from '@shopify/polaris';
70
+
71
+ function App() {
72
+ return (
73
+ <AppProvider>
74
+ <Page title="Hello">
75
+ <Card sectioned>Hi there</Card>
76
+ </Page>
77
+ </AppProvider>
78
+ );
79
+ }
80
+
81
+ export default App;
82
+ ```
data/Rakefile ADDED
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+
5
+ begin
6
+ require 'bundler/setup'
7
+ rescue LoadError
8
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
9
+ end
10
+
11
+ Bundler::GemHelper.install_tasks
12
+
13
+ require 'rake/testtask'
14
+
15
+ Rake::TestTask.new do |t|
16
+ t.libs << 'test'
17
+ t.pattern = 'test/**/*_test.rb'
18
+ end
19
+
20
+ Rake::TestTask.new do |t|
21
+ t.libs << 'test'
22
+ t.name = 'test:unit'
23
+ t.pattern = 'test/quilt_rails/**/*_test.rb'
24
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+ module Quilt
3
+ end
4
+
5
+ require "quilt_rails/version"
6
+ require "quilt_rails/configuration"
7
+ require "quilt_rails/railtie"
8
+ require "quilt_rails/react_renderable"
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+ module Quilt
3
+ class Configuration
4
+ attr_accessor :react_server_host, :react_server_protocol
5
+
6
+ def initialize
7
+ @react_server_host = ENV['SERVICE_URL'] || 'localhost:8081'
8
+ @react_server_protocol = ENV['SERVICE_PROTOCOL'] || 'http'
9
+ end
10
+ end
11
+
12
+ def self.configuration
13
+ @configuration ||= Configuration.new
14
+ end
15
+
16
+ def self.configure
17
+ yield(configuration)
18
+ end
19
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Quilt
4
+ class Railtie < Rails::Railtie
5
+ end
6
+ end
@@ -0,0 +1,12 @@
1
+ require 'rails-reverse-proxy';
2
+
3
+ module Quilt
4
+ module ReactRenderable
5
+ include ReverseProxy::Controller
6
+
7
+ def render_react
8
+ host = "#{Quilt.configuration.react_server_protocol}://#{Quilt.configuration.react_server_host}"
9
+ reverse_proxy(host)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+ module Quilt
3
+ VERSION = "1.0.0"
4
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: quilt_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Mathew Allen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-08-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: railties
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 3.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 3.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rails-reverse-proxy
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.9.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.9.0
41
+ description: A turn-key solution for integrating server-rendered react into your Rails
42
+ app using Quilt libraries.
43
+ email:
44
+ - mathew.allen@shopify.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - README.md
50
+ - Rakefile
51
+ - lib/quilt_rails.rb
52
+ - lib/quilt_rails/configuration.rb
53
+ - lib/quilt_rails/railtie.rb
54
+ - lib/quilt_rails/react_renderable.rb
55
+ - lib/quilt_rails/version.rb
56
+ homepage: https://github.com/Shopify/quilt/tree/master/gems/quilt_rails
57
+ licenses:
58
+ - MIT
59
+ metadata: {}
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubygems_version: 3.0.3
76
+ signing_key:
77
+ specification_version: 4
78
+ summary: A turn-key solution for integrating server-rendered react into your Rails
79
+ app using Quilt libraries.
80
+ test_files: []