quilt_rails 1.2.0 → 1.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 37e297fafc5b69be129c5a4770dacf4f59f4268d7e6c20ec0ad5f04bcf04f553
4
- data.tar.gz: 479e1d89872d29171328ed4fde97a734acbb6d87482dc3d585a4f5564cbe99dc
3
+ metadata.gz: 5214ca27d069782ed72ddcd0f8efe1570ac2d8ebbf71df664f01d88977b09d80
4
+ data.tar.gz: c80609914deb36fb2fe95b683b5bdca6bab97f2100609daf95e9938a31a35e4d
5
5
  SHA512:
6
- metadata.gz: e4241d2c553d44a385970ada0101e88461685b1dfc58bf057d02e97476df0662b7be908d453d8f920b9d268b5a8d3d42b2a2b568d9252ef9e6ae086cff112d43
7
- data.tar.gz: bb2df14689c7255c6df563df49f3985b312109fc3f89521cf85252130540c29f945e9a860f99d432adc4ffa819a95c3d019d306d690761323cbf35fe8daa5244
6
+ metadata.gz: 98813d5e73ad5a700318b8185f08db41863665adb071bef21e9abfea66cbda8810f42ee4c3d7065dbc6fbd32111de9b875964a215258d3fdb6fd71ddd0bfaaab
7
+ data.tar.gz: 0601b77ac976964817c259c5b4fc9d92356493ebe7f9bf617a5be03b8da9493e8cc04375bba08d6bedff54aec5db5b0fc7c5df0ca22ee9ff6eab6bb09f047e4b
data/README.md CHANGED
@@ -6,13 +6,20 @@ This document focuses on Rails integration. For details of `@shopify/react-serve
6
6
 
7
7
  ## Quick Start
8
8
 
9
- Create a Rails project using `dev init` then:
9
+ ### Add Ruby dependencies
10
+
11
+ `bundle add sewing_kit quilt_rails`
12
+
13
+ First, create a Rails project using `dev init`. Next, run `rails generate quilt:install`. This will install the Node dependencies, provide a basic React app (in TypeScript) and mounts the Quilt engine inside of your `config/routes.rb` file.
14
+
15
+ ## Manual Installation
16
+
17
+ You can also perform the steps within the rake task manually by following the guide below.
10
18
 
11
19
  ### Install Dependencies
12
20
 
13
21
  ```sh
14
- # Add Ruby/Node dependencies
15
- bundle add sewing_kit quilt_rails
22
+ # Add Node dependencies
16
23
  yarn add @shopify/sewing-kit @shopify/react-server
17
24
 
18
25
  # Optional - add Polaris and quilt libraries
@@ -26,7 +33,33 @@ dev up
26
33
 
27
34
  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
35
 
29
- ### Setup your react controller and routes
36
+ ### Rails Setup
37
+
38
+ There are 2 ways to consume this package.
39
+
40
+ ### Option 1: Mount the Engine
41
+
42
+ Add the engine to `routes.rb`.
43
+
44
+ ```ruby
45
+ # config/routes.rb
46
+ Rails.application.routes.draw do
47
+ # ...
48
+ mount Quilt::Engine, at: '/'
49
+ end
50
+ ```
51
+
52
+ Where `at` is the path where your App will respond with the React App. If you only want a sub-section of routes to respond with the React App, you can pass in the path to that sub-section here. For example:
53
+
54
+ ```ruby
55
+ # config/routes.rb
56
+ Rails.application.routes.draw do
57
+ # ...
58
+ mount Quilt::Engine, at: '/path/to/react'
59
+ end
60
+ ```
61
+
62
+ ### Option 2: Add your react controller and routes
30
63
 
31
64
  Create a `ReactController` to handle react requests.
32
65
 
@@ -80,3 +113,13 @@ function App() {
80
113
 
81
114
  export default App;
82
115
  ```
116
+
117
+ ## Rails Generators'
118
+
119
+ ### `quilt:install`
120
+
121
+ Installs the Node dependencies, provide a basic React app (in TypeScript) and mounts the Quilt engine inside of your `config/routes.rb` file.
122
+
123
+ ### `sewing-kit:install`
124
+
125
+ Adds a basic `sewing-kit.config.ts` file.
data/Rakefile CHANGED
@@ -10,6 +10,8 @@ end
10
10
 
11
11
  Bundler::GemHelper.install_tasks
12
12
 
13
+ require File.expand_path('../test/dummy/config/application', __FILE__)
14
+
13
15
  require 'rake/testtask'
14
16
 
15
17
  Rake::TestTask.new do |t|
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Quilt
4
+ class UiController < ApplicationController
5
+ include Quilt::ReactRenderable
6
+
7
+ def index
8
+ render_react
9
+ end
10
+ end
11
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ Quilt::Engine.routes.draw do
4
+ get '/*path', to: 'react#index'
5
+ root 'react#index'
6
+ end
@@ -0,0 +1,5 @@
1
+ Description:
2
+ This generator mounts the Quilt engine and adds a React app.
3
+
4
+ Example:
5
+ rails generate quilt:install
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Quilt
4
+ class InstallGenerator < Rails::Generators::Base
5
+ source_root File.expand_path('templates', __dir__)
6
+
7
+ desc "This generator mounts the Quilt engine and adds a React app."
8
+
9
+ def install_js_dependencies
10
+ say "Installing @shopify/react-server and @shopify/sewing-kit dependencies"
11
+ system("yarn add @shopify/sewing-kit @shopify/react-server") unless Rails.env.test?
12
+ end
13
+
14
+ def create_app_file
15
+ app_path = "app/ui/index.tsx"
16
+
17
+ unless File.exist?(app_path)
18
+ copy_file "App.tsx", app_path
19
+
20
+ log("React App at #{app_path}", 'wrote')
21
+ end
22
+ end
23
+
24
+ def create_route_file
25
+ routes_path = "config/routes.rb"
26
+
27
+ if File.exist?(routes_path)
28
+ route "mount Quilt::Engine, at: '/'"
29
+ else
30
+ copy_file "routes.rb", routes_path
31
+ end
32
+
33
+ say "Added Quilt engine mount"
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+
3
+ function App() {
4
+ return <div>Hello Quilt</div>;
5
+ }
6
+
7
+ export default App;
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ Rails.application.routes.draw do
4
+ mount Quilt::Engine, at: '/'
5
+ end
@@ -0,0 +1,5 @@
1
+ Description:
2
+ This generator creates a sewing-kit config file.
3
+
4
+ Example:
5
+ rails generate sewing-kit:install
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SewingKit
4
+ class InstallGenerator < Rails::Generators::Base
5
+ source_root File.expand_path('templates', __dir__)
6
+
7
+ desc "This generator creates a sewing-kit config file."
8
+
9
+ def create_config
10
+ config_path = "config/sewing-kit.config.ts"
11
+
12
+ if File.exist?(config_path)
13
+ say "Sewing kit config already exists"
14
+ else
15
+ copy_file "sewing-kit.config.ts", config_path
16
+
17
+ say "Sewing kit config"
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,7 @@
1
+ /* eslint-env node */
2
+
3
+ module.exports = function sewingKitConfig() {
4
+ return {
5
+ name: 'your-app-name',
6
+ };
7
+ };
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Quilt
4
+ class Engine < ::Rails::Engine
5
+ isolate_namespace Quilt
6
+ end
7
+ end
@@ -1,4 +1,6 @@
1
- require 'rails-reverse-proxy';
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails-reverse-proxy'
2
4
 
3
5
  module Quilt
4
6
  module ReactRenderable
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Quilt
3
- VERSION = "1.2.0"
3
+ VERSION = "1.3.1"
4
4
  end
data/lib/quilt_rails.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  module Quilt
3
3
  end
4
4
 
5
+ require "quilt_rails/engine"
5
6
  require "quilt_rails/version"
6
7
  require "quilt_rails/configuration"
7
- require "quilt_rails/railtie"
8
8
  require "quilt_rails/react_renderable"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quilt_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mathew Allen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-16 00:00:00.000000000 Z
11
+ date: 2019-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -38,6 +38,34 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.9.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.74'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.74'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop-git
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.1.3
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.1.3
41
69
  description: A turn-key solution for integrating server-rendered react into your Rails
42
70
  app using Quilt libraries.
43
71
  email:
@@ -48,9 +76,18 @@ extra_rdoc_files: []
48
76
  files:
49
77
  - README.md
50
78
  - Rakefile
79
+ - app/controllers/quilt/ui_controller.rb
80
+ - config/routes.rb
81
+ - lib/generators/quilt/USAGE
82
+ - lib/generators/quilt/install_generator.rb
83
+ - lib/generators/quilt/templates/App.tsx
84
+ - lib/generators/quilt/templates/routes.rb
85
+ - lib/generators/sewing_kit/USAGE
86
+ - lib/generators/sewing_kit/install_generator.rb
87
+ - lib/generators/sewing_kit/templates/sewing-kit.config.ts
51
88
  - lib/quilt_rails.rb
52
89
  - lib/quilt_rails/configuration.rb
53
- - lib/quilt_rails/railtie.rb
90
+ - lib/quilt_rails/engine.rb
54
91
  - lib/quilt_rails/react_renderable.rb
55
92
  - lib/quilt_rails/version.rb
56
93
  homepage: https://github.com/Shopify/quilt/tree/master/gems/quilt_rails
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Quilt
4
- class Railtie < Rails::Railtie
5
- end
6
- end