shopify_app 5.0.2 → 6.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/.gitignore +4 -1
- data/.travis.yml +9 -0
- data/CHANGELOG +12 -1
- data/README.md +73 -108
- data/Rakefile +0 -1
- data/app/controllers/sessions_controller.rb +3 -0
- data/app/views/sessions/new.html.erb +17 -0
- data/config/routes.rb +10 -0
- data/lib/generators/shopify_app/controllers/controllers_generator.rb +29 -0
- data/lib/generators/shopify_app/install/install_generator.rb +83 -0
- data/lib/generators/shopify_app/install/templates/embedded_app.html.erb +22 -0
- data/lib/generators/shopify_app/install/templates/home_controller.rb +11 -0
- data/lib/generators/shopify_app/install/templates/index.html.erb +12 -0
- data/lib/generators/shopify_app/install/templates/omniauth.rb +2 -0
- data/lib/generators/shopify_app/install/templates/shopify_app.rb +6 -0
- data/lib/generators/shopify_app/install/templates/shopify_app_ready_script.html +8 -0
- data/lib/generators/shopify_app/install/templates/shopify_provider.rb +11 -0
- data/lib/generators/shopify_app/{templates/config/initializers → install/templates}/shopify_session_repository.rb +3 -3
- data/lib/generators/shopify_app/routes/routes_generator.rb +31 -0
- data/lib/generators/shopify_app/routes/templates/routes.rb +7 -0
- data/lib/generators/shopify_app/shop_model/shop_model_generator.rb +42 -0
- data/lib/generators/shopify_app/shop_model/templates/db/migrate/create_shops.rb +15 -0
- data/lib/generators/shopify_app/shop_model/templates/session_storage.rb +16 -0
- data/lib/generators/shopify_app/shop_model/templates/shop.rb +3 -0
- data/lib/generators/shopify_app/shop_model/templates/shopify_session_repository.rb +7 -0
- data/lib/generators/shopify_app/shopify_app_generator.rb +10 -63
- data/lib/generators/shopify_app/views/views_generator.rb +29 -0
- data/lib/shopify_app.rb +14 -13
- data/lib/shopify_app/configuration.rb +26 -36
- data/lib/shopify_app/controller.rb +18 -0
- data/lib/shopify_app/engine.rb +5 -0
- data/lib/shopify_app/login_protection.rb +34 -32
- data/lib/shopify_app/sessions_controller.rb +64 -0
- data/lib/shopify_app/shop.rb +15 -0
- data/lib/shopify_app/shopify_session_repository.rb +23 -21
- data/lib/shopify_app/version.rb +1 -1
- data/shopify_app.gemspec +5 -10
- data/test/app_templates/app/controllers/application_controller.rb +2 -0
- data/test/app_templates/config/application.rb +24 -0
- data/test/app_templates/config/initializers/shopify_app.rb +6 -0
- data/test/app_templates/config/routes.rb +3 -0
- data/test/controllers/sessions_controller_test.rb +82 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/controllers/home_controller.rb +7 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +26 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/test.rb +42 -0
- data/test/dummy/config/initializers/shopify_app.rb +6 -0
- data/test/dummy/config/routes.rb +10 -0
- data/test/dummy/config/secrets.yml +17 -0
- data/test/generators/install_generator_test.rb +103 -0
- data/test/generators/routes_generator_test.rb +33 -0
- data/test/generators/shop_model_generator_test.rb +40 -0
- data/test/generators/shopify_app_generator.rb +15 -0
- data/test/generators/views_generator_test.rb +15 -0
- data/test/shopify_app/configuration_test.rb +17 -0
- data/test/{lib/shopify_app → shopify_app}/in_memory_session_store_test.rb +6 -6
- data/test/{lib/shopify_app → shopify_app}/login_protection_test.rb +10 -7
- data/test/shopify_app/shopify_session_repository_test.rb +73 -0
- data/test/support/generator_test_helpers.rb +29 -0
- data/test/test_helper.rb +11 -3
- metadata +79 -61
- metadata.gz.sig +0 -0
- data/install.rb +0 -25
- data/lib/generators/shopify_app/README +0 -23
- data/lib/generators/shopify_app/USAGE +0 -22
- data/lib/generators/shopify_app/templates/app/assets/images/favicon.png +0 -0
- data/lib/generators/shopify_app/templates/app/assets/images/grid-18px.png +0 -0
- data/lib/generators/shopify_app/templates/app/assets/images/shopify-114.png +0 -0
- data/lib/generators/shopify_app/templates/app/assets/images/shopify-57.png +0 -0
- data/lib/generators/shopify_app/templates/app/assets/images/shopify-72.png +0 -0
- data/lib/generators/shopify_app/templates/app/assets/images/shopify.png +0 -0
- data/lib/generators/shopify_app/templates/app/assets/javascripts/application.js +0 -15
- data/lib/generators/shopify_app/templates/app/assets/stylesheets/application.css +0 -10
- data/lib/generators/shopify_app/templates/app/assets/stylesheets/imports.css.less +0 -5
- data/lib/generators/shopify_app/templates/app/assets/stylesheets/shopify_app.css.scss +0 -150
- data/lib/generators/shopify_app/templates/app/assets/stylesheets/shopify_app_buttons.css.less +0 -77
- data/lib/generators/shopify_app/templates/app/controllers/application_controller.rb +0 -13
- data/lib/generators/shopify_app/templates/app/controllers/home_controller.rb +0 -18
- data/lib/generators/shopify_app/templates/app/controllers/sessions_controller.rb +0 -52
- data/lib/generators/shopify_app/templates/app/helpers/home_helper.rb +0 -9
- data/lib/generators/shopify_app/templates/app/helpers/login_helper.rb +0 -3
- data/lib/generators/shopify_app/templates/app/helpers/tabs_helper.rb +0 -11
- data/lib/generators/shopify_app/templates/app/views/home/design.html.erb +0 -3542
- data/lib/generators/shopify_app/templates/app/views/home/index.html.erb +0 -168
- data/lib/generators/shopify_app/templates/app/views/home/welcome.html.erb +0 -110
- data/lib/generators/shopify_app/templates/app/views/layouts/application.html.erb +0 -79
- data/lib/generators/shopify_app/templates/app/views/sessions/new.html.erb +0 -21
- data/lib/generators/shopify_app/templates/config/initializers/omniauth.rb +0 -14
- data/lib/generators/shopify_app/templates/config/initializers/rails_4_shim.rb +0 -1
- data/lib/generators/shopify_app/templates/public/404.html +0 -40
- data/lib/generators/shopify_app/templates/public/422.html +0 -40
- data/lib/generators/shopify_app/templates/public/500.html +0 -40
- data/lib/generators/shopify_app/templates/public/favicon.png +0 -0
- data/lib/generators/shopify_app/templates/public/shopify-114.png +0 -0
- data/lib/generators/shopify_app/templates/public/shopify-57.png +0 -0
- data/lib/generators/shopify_app/templates/public/shopify-72.png +0 -0
- data/lib/shopify_app/railtie.rb +0 -17
- data/test/config/development_config_file.yml +0 -8
- data/test/config/empty_config_file.yml +0 -1
- data/test/config/other_config_file.yml +0 -4
- data/test/config/shopify_app.yml +0 -4
- data/test/lib/shopify_app/configuration_test.rb +0 -91
- data/test/lib/shopify_app/shopify_session_repository_test.rb +0 -70
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2180fbad771bc170d57ca9e9d84264db64adc578
|
4
|
+
data.tar.gz: 028708ad9fc92ce756fbf815468d586e2e0302ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d07a8720342f16795447fd929d4fb9d5933ba7cbbe27b085f8c00663548ef3ff5bd5ef826ec5062e30e00d476ac2bea7818e1eefa61b4e06f0831027f4ce309a
|
7
|
+
data.tar.gz: 5c17a5290b05876ecd0bc321dc9477612d7f1d8c87689ff506d6e5ac21f0df4b2c936b1e9d28945d7d2fea0c25eacbf93fc129555fe7f47cc63400e4f80db87c
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/CHANGELOG
CHANGED
@@ -1,5 +1,16 @@
|
|
1
|
+
6.0.0
|
2
|
+
-----
|
3
|
+
* Re-written as a proper rails engine
|
4
|
+
* New modular generators
|
5
|
+
* generates embedded apps by default
|
6
|
+
* can bootstrap your app with a standard shop table and model
|
7
|
+
* code now lives as concerns in the engine which are included in your controllers
|
8
|
+
feel free to override anything you need in your app
|
9
|
+
|
10
|
+
Historical
|
11
|
+
----------
|
1
12
|
* re-styled with Twitter Bootstrap css framework and updated docs [warren]
|
2
13
|
* Require shopify_api gem via proper railtie setup [willem]
|
3
14
|
* Don't require shopify.yml when using environment variables [cody]
|
4
15
|
* Renamed instances of current_shop to shop_session to maintain logic
|
5
|
-
* Replace old LoginController with a RESTful SessionsController
|
16
|
+
* Replace old LoginController with a RESTful SessionsController
|
data/README.md
CHANGED
@@ -1,18 +1,30 @@
|
|
1
|
-
|
1
|
+
Shopify App [![Build Status](https://travis-ci.org/Shopify/shopify_app.png)](https://travis-ci.org/Shopify/shopify_app)
|
2
|
+
===========
|
2
3
|
|
3
|
-
|
4
|
+
Shopify Application Rails engine and generator
|
4
5
|
|
5
|
-
Shopify application generator for Rails 3.1 and Rails 4.0
|
6
6
|
|
7
|
-
|
7
|
+
Description
|
8
|
+
-----------
|
9
|
+
This gem includes some common code and generators for writing Rails applications using the Shopify API.
|
8
10
|
|
9
|
-
|
11
|
+
*Note: It's recommended to use this on a new Rails project, so that the generator won't overwrite/delete some of your files.*
|
10
12
|
|
11
|
-
The generator creates a basic SessionsController for authenticating with your shop and a HomeController which displays basic information about your products, orders and articles.
|
12
13
|
|
13
|
-
|
14
|
+
Becoming a Shopify App Developer
|
15
|
+
--------------------------------
|
16
|
+
If you don't have a Shopify Partner account yet head over to http://shopify.com/partners to create one, you'll need it before you can start developing apps.
|
17
|
+
|
18
|
+
Once you have a Partner account create a new application to get an Api key and other Api credentials. To create a development application set the Application Callback URL to
|
19
|
+
|
20
|
+
http://localhost:3000/login
|
21
|
+
|
22
|
+
This way you'll be able to run the app on your local machine.
|
23
|
+
|
14
24
|
|
15
|
-
|
25
|
+
Installation
|
26
|
+
------------
|
27
|
+
To get started add shopify_app to your Gemfile and bundle install
|
16
28
|
|
17
29
|
``` sh
|
18
30
|
# Create a new rails app
|
@@ -24,59 +36,72 @@ $ echo "gem 'shopify_app'" >> Gemfile
|
|
24
36
|
$ bundle install
|
25
37
|
```
|
26
38
|
|
27
|
-
|
39
|
+
Now we are ready to run any of the shopify_app generators. The following section explains the generators and what they can do.
|
28
40
|
|
29
|
-
|
30
|
-
|
41
|
+
|
42
|
+
Generators
|
43
|
+
----------
|
44
|
+
|
45
|
+
### Install Generator
|
46
|
+
|
47
|
+
```sh
|
48
|
+
$ rails generate shopify_app:install
|
49
|
+
|
50
|
+
# or optionally with arguments:
|
51
|
+
|
52
|
+
$ rails generate shopify_app:install -api_key=<your_api_key> -secret=<your_app_secret>
|
31
53
|
```
|
32
54
|
|
33
|
-
|
55
|
+
Other options include:
|
56
|
+
* `scope` - the Oauth access scope required for your app, eg 'read_products, write_orders'. For more information read the [docs](http://docs.shopify.com/api/tutorials/oauth)
|
57
|
+
* `embedded` - the default is to generate an [embedded app](http://docs.shopify.com/embedded-app-sdk), if you want a legacy non-embedded app then set this to false, `-embedded false`
|
34
58
|
|
35
|
-
|
59
|
+
You can update any of these settings later on easily, the arguments are simply for convenience.
|
36
60
|
|
37
|
-
|
61
|
+
The generator creates a basic SessionsController for authenticating with your shop and a HomeController which displays basic information about your products using the ShopifyAPI. The generated controllers include concerns provided by this gem - in this way code sharing is possible and if some of these core methods are updated everyone can benefit. It is completely safe to override any of the methods provided by this gem in your application.
|
38
62
|
|
39
|
-
|
63
|
+
After running the `install` generator you can start your app with `bundle exec rails server` and install your app by visiting localhost.
|
40
64
|
|
41
|
-
### Example
|
42
65
|
|
43
|
-
|
44
|
-
|
66
|
+
### Shop Model Generator
|
67
|
+
|
68
|
+
```sh
|
69
|
+
$ rails generate shopify_app:shop_model
|
45
70
|
```
|
46
71
|
|
47
|
-
|
72
|
+
The install generator doesn't create any database models for you and if you are starting a new app its quite likely that you will want one (most our internally developed apps do!). This generator creates a simple shop model and a migration. It also create a model called `SessionStorage` which interacts with `ShopifyApp::SessionRepository`. Check out the later section to learn more about `ShopifyApp::SessionRepository`
|
48
73
|
|
49
|
-
|
74
|
+
*Note that you will need to run rake db:migrate after this generator*
|
50
75
|
|
51
|
-
|
76
|
+
### Controllers, Routes and Views
|
52
77
|
|
53
|
-
|
54
|
-
* Configuration in a Rails `<environment>.rb` config file
|
78
|
+
The last group of generators are for your convenience when you want to start overriding code included as part of the Rails engine. For example by default the engine provides a simple SessionController, if you run the `rails generate shopify_app:controllers` generator then this code gets copied out into your app so you can start adding to it. Routes and views follow the exact same pattern.
|
55
79
|
|
56
|
-
``` ruby
|
57
|
-
config.shopify.api_key = 'your api key'
|
58
|
-
config.shopify.secret = 'your secret'
|
59
|
-
```
|
60
80
|
|
61
|
-
|
81
|
+
### Default Generator
|
82
|
+
|
83
|
+
If you just run `rails generate shopify_app` then all the generators will be run for you. This is how we do it internally!
|
84
|
+
|
62
85
|
|
63
|
-
``` yaml
|
64
|
-
development:
|
65
|
-
api_key: your api key
|
66
|
-
secret: your secret
|
67
|
-
```
|
68
86
|
|
69
|
-
|
87
|
+
Managing Api Keys
|
88
|
+
-----------------
|
70
89
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
90
|
+
The `install` generator places your Api credentials directly into the shopify_app initializer which is convient and fine for development but once your app goes into production **your api credentials should not be in source control**. When we develop apps we keep our keys in environment variables so a production shopify_app initializer would look like this:
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
ShopifyApp.configure do |config|
|
94
|
+
config.api_key = ENV['SHOPIFY_CLIENT_API_KEY']
|
95
|
+
config.secret = ENV['SHOPIFY_CLIENT_API_SECRET']
|
96
|
+
config.scope = 'read_customers, read_orders, write_products'
|
97
|
+
config.embedded_app = true
|
98
|
+
end
|
75
99
|
```
|
76
100
|
|
77
|
-
|
101
|
+
ShopifyApp::SessionRepository
|
102
|
+
-----------------------------
|
78
103
|
|
79
|
-
`
|
104
|
+
`ShopifyApp::SessionRepository` allows you as a developer to define how your sessions are retrieved and
|
80
105
|
stored for a shop. This can simply be your `Shop` model that stores the API Token and shop name. If
|
81
106
|
you are using ActiveRecord, then all you need to implement is `self.store(shopify_session)` and
|
82
107
|
`self.retrieve(id)` in order to store the record on disk or retrieve it for use at a later point.
|
@@ -88,98 +113,38 @@ Your ActiveRecord model would look something like this:
|
|
88
113
|
```ruby
|
89
114
|
class Shop < ActiveRecord::Base
|
90
115
|
def self.store(session)
|
91
|
-
shop =
|
116
|
+
shop = self.new(domain: session.url, token: session.token)
|
92
117
|
shop.save!
|
93
118
|
shop.id
|
94
119
|
end
|
95
120
|
|
96
121
|
def self.retrieve(id)
|
97
|
-
if shop =
|
122
|
+
if shop = self.where(id: id).first
|
98
123
|
ShopifyAPI::Session.new(shop.domain, shop.token)
|
99
124
|
end
|
100
125
|
end
|
101
126
|
end
|
102
127
|
```
|
103
128
|
|
104
|
-
By default you will have an in memory store but it
|
129
|
+
By default you will have an in memory store but it **won't work** on multi-server environments since
|
105
130
|
they won't be sharing the static data that would be required in case your user gets directed to a
|
106
131
|
different server by your load balancer.
|
107
132
|
|
108
133
|
The in memory store also does not behave well on Heroku because the session data would be destroyed
|
109
134
|
when a dyno is killed due to inactivity.
|
110
135
|
|
111
|
-
Changing the `
|
136
|
+
Changing the `ShopifyApp::SessionRepository.storage` can simply be done by editing
|
112
137
|
`config/initializers/shopify_session_repository.rb` to use the correct model.
|
113
138
|
|
114
139
|
```ruby
|
115
|
-
|
116
|
-
```
|
117
|
-
|
118
|
-
## Set your required API permissions
|
119
|
-
|
120
|
-
Before making API requests, your application must state which API permissions it requires from the shop it's installed in. These requested permissions will be listed on the screen the merchant sees when approving your app to be installed in their shop.
|
121
|
-
|
122
|
-
Start by reviewing the documentation on API permission scopes: http://docs.shopify.com/api/tutorials/oauth
|
123
|
-
|
124
|
-
When you know which ones your app will need, add a scope line to the `config/initializers/omniauth.rb` file.
|
125
|
-
|
126
|
-
### Example
|
127
|
-
|
128
|
-
Make this change to request write access to products and read access to orders:
|
129
|
-
|
130
|
-
``` ruby
|
131
|
-
Rails.application.config.middleware.use OmniAuth::Builder do
|
132
|
-
provider :shopify,
|
133
|
-
ShopifyApp.configuration.api_key,
|
134
|
-
ShopifyApp.configuration.secret,
|
135
|
-
:scope => "write_products,read_orders",
|
136
|
-
:setup => lambda {|env|
|
137
|
-
params = Rack::Utils.parse_query(env['QUERY_STRING'])
|
138
|
-
site_url = "https://#{params['shop']}"
|
139
|
-
env['omniauth.strategy'].options[:client_options][:site] = site_url
|
140
|
-
}
|
141
|
-
end
|
142
|
-
```
|
143
|
-
|
144
|
-
*Note that you can change your API permission scopes on the fly, but the merchant will have to approve each change and your computed API password will change.*
|
145
|
-
|
146
|
-
## After running the generator
|
147
|
-
|
148
|
-
First, start your application:
|
149
|
-
|
150
|
-
``` sh
|
151
|
-
$ rails server
|
152
|
-
```
|
153
|
-
|
154
|
-
Now visit http://localhost:3000 and install your application in a Shopify store. Even if Rails tells you to visit your app at http://0.0.0.0:3000, go to http://localhost:3000.
|
155
|
-
|
156
|
-
After your application has been given whatever API permissions you requested by the shop, you're ready to start experimenting with the Shopify API.
|
157
|
-
|
158
|
-
## Rails 3.0 (as in before 3.1) Support
|
159
|
-
|
160
|
-
Rails 3.0 (as in before the big changes in 3.1) is supported on a branch of our github repo: https://github.com/Shopify/shopify_app/tree/rails_3.0_support
|
161
|
-
|
162
|
-
## Common problems
|
163
|
-
|
164
|
-
If you are getting the following error:
|
165
|
-
|
166
|
-
```
|
167
|
-
Faraday::Error::ConnectionFailed error when accessing app.
|
168
|
-
```
|
169
|
-
|
170
|
-
It probably means that the CA certificate on your computer is out of date. A simple solution on the Mac is to install XCode.
|
171
|
-
|
172
|
-
If you are getting the following error:
|
173
|
-
|
174
|
-
```
|
175
|
-
ActiveResource::ForbiddenAccess in HomeController#index
|
176
|
-
Failed. Response code = 403. Response message = Forbidden.
|
140
|
+
ShopifyApp::SessionRepository.storage = 'Shop'
|
177
141
|
```
|
178
142
|
|
179
|
-
|
143
|
+
If you run the `shop_model` generator it will create the required code to use the generated Shop model as the SessionRepository and update the initializer.
|
180
144
|
|
181
|
-
## Questions or problems?
|
182
145
|
|
146
|
+
Questions or problems?
|
147
|
+
----------------------
|
183
148
|
http://api.shopify.com <= Read up on the possible API calls!
|
184
149
|
|
185
150
|
http://ecommerce.shopify.com/c/shopify-apis-and-technology <= Ask questions!
|
data/Rakefile
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Install Page</title>
|
5
|
+
</head>
|
6
|
+
<body>
|
7
|
+
|
8
|
+
<h2>Install the application</h2>
|
9
|
+
|
10
|
+
<form method="GET" action="login">
|
11
|
+
<label>Type shop name:</label>
|
12
|
+
<input type="text" name="shop" placeholder="blabla.myshopify.com"/>
|
13
|
+
<button type='submit'>Install</buttom>
|
14
|
+
</form>
|
15
|
+
|
16
|
+
</body>
|
17
|
+
</html>
|
data/config/routes.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
if ShopifyApp.configuration.routes_enabled?
|
2
|
+
ShopifyApp::Engine.routes.draw do
|
3
|
+
controller :sessions do
|
4
|
+
get 'login' => :new, :as => :login
|
5
|
+
post 'login' => :create, :as => :authenticate
|
6
|
+
get 'auth/shopify/callback' => :callback
|
7
|
+
get 'logout' => :destroy, :as => :logout
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'rails/generators/base'
|
2
|
+
|
3
|
+
module ShopifyApp
|
4
|
+
module Generators
|
5
|
+
class ControllersGenerator < Rails::Generators::Base
|
6
|
+
source_root File.expand_path("../../../../..", __FILE__)
|
7
|
+
|
8
|
+
def create_controllers
|
9
|
+
controllers.each do |controller|
|
10
|
+
copy_file controller
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def controllers
|
17
|
+
files_within_root('.', 'app/controllers/*.*')
|
18
|
+
end
|
19
|
+
|
20
|
+
def files_within_root(prefix, glob)
|
21
|
+
root = "#{self.class.source_root}/#{prefix}"
|
22
|
+
|
23
|
+
Dir["#{root}/#{glob}"].sort.map do |full_path|
|
24
|
+
full_path.sub(root, '.').gsub('/./', '/')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'rails/generators/base'
|
2
|
+
require 'rails/generators/active_record'
|
3
|
+
|
4
|
+
module ShopifyApp
|
5
|
+
module Generators
|
6
|
+
class InstallGenerator < Rails::Generators::Base
|
7
|
+
include Rails::Generators::Migration
|
8
|
+
source_root File.expand_path('../templates', __FILE__)
|
9
|
+
attr_reader :opts
|
10
|
+
|
11
|
+
def initialize(args, *options)
|
12
|
+
@opts = Hash[options.first.join(' ').scan(/--?([^=\s]+)(?:=(\S+))?/)]
|
13
|
+
super(args, *options)
|
14
|
+
end
|
15
|
+
|
16
|
+
def create_shopify_app_initializer
|
17
|
+
template 'shopify_app.rb', 'config/initializers/shopify_app.rb'
|
18
|
+
end
|
19
|
+
|
20
|
+
def create_and_inject_into_omniauth_initializer
|
21
|
+
unless File.exist? "config/initializers/omniauth.rb"
|
22
|
+
copy_file 'omniauth.rb', 'config/initializers/omniauth.rb'
|
23
|
+
end
|
24
|
+
|
25
|
+
inject_into_file(
|
26
|
+
'config/initializers/omniauth.rb',
|
27
|
+
File.read(File.expand_path(find_in_source_paths('shopify_provider.rb'))),
|
28
|
+
after: "Rails.application.config.middleware.use OmniAuth::Builder do\n"
|
29
|
+
)
|
30
|
+
end
|
31
|
+
|
32
|
+
def create_shopify_session_repository_initializer
|
33
|
+
copy_file 'shopify_session_repository.rb', 'config/initializers/shopify_session_repository.rb'
|
34
|
+
end
|
35
|
+
|
36
|
+
def inject_embedded_app_options_to_application
|
37
|
+
if embedded_app?
|
38
|
+
application "config.action_dispatch.default_headers.delete('X-Frame-Options')"
|
39
|
+
application "config.action_dispatch.default_headers['P3P'] = 'CP=\"Not used\"'"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def inject_into_application_controller
|
44
|
+
inject_into_class(
|
45
|
+
"app/controllers/application_controller.rb",
|
46
|
+
'ApplicationController',
|
47
|
+
" include ShopifyApp::Controller\n"
|
48
|
+
)
|
49
|
+
end
|
50
|
+
|
51
|
+
def create_embedded_app_layout
|
52
|
+
if embedded_app?
|
53
|
+
copy_file 'embedded_app.html.erb', 'app/views/layouts/embedded_app.html.erb'
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def create_home_controller
|
58
|
+
template 'home_controller.rb', 'app/controllers/home_controller.rb'
|
59
|
+
end
|
60
|
+
|
61
|
+
def create_home_index_view
|
62
|
+
copy_file 'index.html.erb', 'app/views/home/index.html.erb'
|
63
|
+
if embedded_app?
|
64
|
+
prepend_to_file(
|
65
|
+
'app/views/home/index.html.erb',
|
66
|
+
File.read(File.expand_path(find_in_source_paths('shopify_app_ready_script.html')))
|
67
|
+
)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def add_home_index_route
|
72
|
+
route "root :to => 'home#index'"
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
def embedded_app?
|
78
|
+
opts[:embedded] != 'false'
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|