Skip to content

Commit

Permalink
Make simpler
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Anema authored and tylerball committed Nov 7, 2019
1 parent 8f01204 commit 87836e4
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 54 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,23 @@ Questions or problems?
- [Ask questions!](https://ecommerce.shopify.com/c/shopify-apis-and-technology)
- [Read the docs!](https://help.shopify.com/api/guides)
Rails 6 Compatibility
---------------------------
### Disable Webpacker
If you are using sprockets in rails 6 or want to generate a shopify_app without webpacker run the install task by running
```
SHOPIFY_APP_DISABLE_WEBPACKER=1 rails generate shopify_app
```
and then in your ShopifyApp configuration block, add
```
ShopifyApp.configure do |config|
config.disable_webpacker = true
end
```
Upgrading from 8.6 to 9.0.0
---------------------------
Expand Down
6 changes: 1 addition & 5 deletions app/views/shopify_app/sessions/enable_cookies.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@
window.returnTo = "<%= params[:return_to] %>"
</script>

<% if ShopifyApp.rails6? %>
<%= javascript_pack_tag('shopify_app_enable_cookies', crossorigin: 'anonymous', integrity: true) %>
<% else %>
<%= javascript_include_tag('shopify_app/enable_cookies', crossorigin: 'anonymous', integrity: true) %>
<% end %>
<%= javascript_include_tag('shopify_app/enable_cookies', crossorigin: 'anonymous', integrity: true) %>
</head>
<body>
<%=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@
</div>
</div>
</main>
<% if ShopifyApp.rails6? %>
<%= javascript_pack_tag('shopify_app_request_storage_access', crossorigin: 'anonymous', integrity: true) %>
<% else %>
<%= javascript_include_tag('shopify_app/request_storage_access', crossorigin: 'anonymous', integrity: true) %>
<% end %>
<%= javascript_include_tag('shopify_app/request_storage_access', crossorigin: 'anonymous', integrity: true) %>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@
window.redirectUrl = "<%= @url %>";
</script>

<% if ShopifyApp.rails6? %>
<%= javascript_pack_tag('shopify_app_top_level', crossorigin: 'anonymous', integrity: true) %>
<% else %>
<%= javascript_include_tag('shopify_app/top_level', crossorigin: 'anonymous', integrity: true) %>
<% end %>
<%= javascript_include_tag('shopify_app/top_level', crossorigin: 'anonymous', integrity: true) %>
</head>
<body>
<main id="TopLevelInteractionContent">
Expand Down
6 changes: 1 addition & 5 deletions app/views/shopify_app/shared/redirect.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />
<base target="_top">
<title>Redirecting…</title>
<% if ShopifyApp.rails6? %>
<%= javascript_pack_tag('shopify_app_redirect', crossorigin: 'anonymous', integrity: true) %>
<% else %>
<%= javascript_include_tag('shopify_app/redirect', crossorigin: 'anonymous', integrity: true) %>
<% end %>
<%= javascript_include_tag('shopify_app/redirect', crossorigin: 'anonymous', integrity: true) %>
</head>
<body>
<%=
Expand Down
28 changes: 4 additions & 24 deletions lib/generators/shopify_app/install/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,37 +41,17 @@ def create_and_inject_into_omniauth_initializer

def create_embedded_app_layout
return unless embedded_app?
if ShopifyApp.rails6?
copy_file 'embedded_app.html.erb', 'app/views/layouts/embedded_app.html.erb'
copy_file '_flash_messages.html.erb', 'app/views/layouts/_flash_messages.html.erb'

copy_file 'embedded_app.html.erb', 'app/views/layouts/embedded_app.html.erb'
copy_file '_flash_messages.html.erb', 'app/views/layouts/_flash_messages.html.erb'

if ShopifyApp.use_webpacker?
copy_file('shopify_app.js', 'app/javascript/shopify_app/shopify_app.js')
copy_file('flash_messages.js', 'app/javascript/shopify_app/flash_messages.js')
copy_file('shopify_app_index.js', 'app/javascript/shopify_app/index.js')

%w(
itp_helper
partition_cookies
redirect
storage_access
storage_access_redirect
top_level_interaction
).each do |filename|
copy_file(
"../../../../../app/assets/javascripts/shopify_app/#{filename}.js",
"app/javascript/shopify_app/#{filename}.js",
)
end

copy_file('redirect.js', 'app/javascript/packs/shopify_app_redirect.js')
copy_file('enable_cookies.js', 'app/javascript/packs/shopify_app_enable_cookies.js')
copy_file('request_storage_access.js', 'app/javascript/packs/shopify_app_request_storage_access.js')
copy_file('top_level.js', 'app/javascript/packs/shopify_app_top_level.js')
append_to_file('app/javascript/packs/application.js', 'require("shopify_app")')
else
copy_file 'embedded_app.html.erb', 'app/views/layouts/embedded_app.html.erb'
copy_file('shopify_app.js', 'app/assets/javascripts/shopify_app.js')
copy_file '_flash_messages.html.erb', 'app/views/layouts/_flash_messages.html.erb'
copy_file('flash_messages.js', 'app/assets/javascripts/flash_messages.js')
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<% application_name = ShopifyApp.configuration.application_name %>
<title><%= application_name %></title>
<%= stylesheet_link_tag 'application' %>
<% if ShopifyApp.rails6? %>
<% if ShopifyApp.use_webpacker? %>
<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
<% else %>
<%= javascript_include_tag 'application', "data-turbolinks-track" => true %>
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion lib/generators/shopify_app/install/templates/redirect.js

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions lib/generators/shopify_app/install/templates/top_level.js

This file was deleted.

6 changes: 6 additions & 0 deletions lib/shopify_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ def self.rails6?
Rails::VERSION::MAJOR >= 6
end

def self.use_webpacker?
rails6? &&
defined?(Webpacker) == 'constant' &&
!configuration.disable_webpacker
end

# config
require 'shopify_app/configuration'

Expand Down
4 changes: 4 additions & 0 deletions lib/shopify_app/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ class Configuration
# configure myshopify domain for local shopify development
attr_accessor :myshopify_domain

# ability to have webpacker installed but not used in this gem and the generators
attr_accessor :disable_webpacker

# allow namespacing webhook jobs
attr_accessor :webhook_jobs_namespace

Expand All @@ -36,6 +39,7 @@ def initialize
@myshopify_domain = 'myshopify.com'
@scripttags_manager_queue_name = Rails.application.config.active_job.queue_name
@webhooks_manager_queue_name = Rails.application.config.active_job.queue_name
@disable_webpacker = ENV['SHOPIFY_APP_DISABLE_WEBPACKER'].present?
end

def login_url
Expand Down

0 comments on commit 87836e4

Please sign in to comment.