Skip to content

Commit f09e915

Browse files
committed
Update naming
1 parent bb215e5 commit f09e915

File tree

11 files changed

+152
-147
lines changed

11 files changed

+152
-147
lines changed

app/controllers/shopify_app/callback_controller.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,12 @@ def install_webhooks(session)
162162
end
163163

164164
def install_scripttags(session)
165-
return unless ShopifyApp.configuration.has_scripttags?
165+
return unless ShopifyApp.configuration.has_script_tags?
166166

167-
ScripttagsManager.queue(
167+
ScriptTagsManager.queue(
168168
session.shop,
169169
session.access_token,
170-
ShopifyApp.configuration.scripttags,
170+
ShopifyApp.configuration.script_tags,
171171
)
172172
end
173173

docs/shopify_app/script-tags.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
# ScriptTags
1+
# Script Tags
22

3-
ShopifyApp can manage your app's [ScriptTags](https://shopify.dev/docs/admin-api/graphql/reference/online-store/scripttag) for you by setting which scripttags you require in the initializer.
3+
ShopifyApp can manage your app's [Script Tags](https://shopify.dev/docs/admin-api/graphql/reference/online-store/scripttag) for you by setting which script tags you require in the initializer.
4+
> [!NOTE]
5+
> Script tags should only be used for vintage themes that do not support app blocks.
46
57
## Configuration
68

79
```ruby
810
ShopifyApp.configure do |config|
9-
config.scripttags = [
11+
config.script_tags = [
1012
# Basic script tag
1113
{cache: true, src: 'https://example.com/fancy.js'},
1214

@@ -41,7 +43,7 @@ config.scope = 'write_products,write_script_tags,read_themes'
4143

4244
### Script Tag Creation
4345

44-
Scripttags are created in the same way as [Webhooks](/docs/shopify_app/webhooks.md), with a background job which will create the required scripttags.
46+
Script tags are created in the same way as [Webhooks](/docs/shopify_app/webhooks.md), with a background job which will create the required scripttags.
4547

4648
### App Block Detection
4749

lib/shopify_app.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ def self.use_webpacker?
6464

6565
# jobs
6666
require "shopify_app/jobs/webhooks_manager_job"
67-
require "shopify_app/jobs/scripttags_manager_job"
67+
require "shopify_app/jobs/script_tags_manager_job"
6868

6969
# managers
7070
require "shopify_app/managers/webhooks_manager"
71-
require "shopify_app/managers/scripttags_manager"
71+
require "shopify_app/managers/script_tags_manager"
7272
# middleware
7373
require "shopify_app/middleware/jwt_middleware"
7474

lib/shopify_app/auth/post_authenticate_tasks.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def perform(session)
1111

1212
install_webhooks(session_for_shop)
1313
install_scripttags(session_for_shop)
14-
14+
1515
perform_after_authenticate_job(session)
1616
end
1717

@@ -30,9 +30,9 @@ def install_webhooks(session)
3030

3131
def install_scripttags(session)
3232
ShopifyApp::Logger.debug("PostAuthenticateTasks: Installing scripttags")
33-
return unless ShopifyApp.configuration.has_scripttags?
33+
return unless ShopifyApp.configuration.has_script_tags?
3434

35-
ScripttagsManager.queue(session.shop, session.access_token, ShopifyApp.configuration.scripttags)
35+
ScriptTagsManager.queue(session.shop, session.access_token, ShopifyApp.configuration.script_tags)
3636
end
3737

3838
def perform_after_authenticate_job(session)

lib/shopify_app/configuration.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Configuration
1515
attr_accessor :embedded_app
1616
alias_method :embedded_app?, :embedded_app
1717
attr_accessor :webhooks
18-
attr_accessor :scripttags
18+
attr_accessor :script_tags
1919
attr_accessor :after_authenticate_job
2020
attr_accessor :api_version
2121

@@ -33,7 +33,7 @@ class Configuration
3333
attr_accessor :custom_post_authenticate_tasks
3434

3535
# customise ActiveJob queue names
36-
attr_accessor :scripttags_manager_queue_name
36+
attr_accessor :script_tags_manager_queue_name
3737
attr_accessor :webhooks_manager_queue_name
3838

3939
# configure myshopify domain for local shopify development
@@ -58,7 +58,7 @@ def initialize
5858
@root_url = "/"
5959
@myshopify_domain = "myshopify.com"
6060
@unified_admin_domain = "shopify.com"
61-
@scripttags_manager_queue_name = Rails.application.config.active_job.queue_name
61+
@script_tags_manager_queue_name = Rails.application.config.active_job.queue_name
6262
@webhooks_manager_queue_name = Rails.application.config.active_job.queue_name
6363
@disable_webpacker = ENV["SHOPIFY_APP_DISABLE_WEBPACKER"].present?
6464
@scope = []
@@ -115,8 +115,8 @@ def has_webhooks?
115115
webhooks.present?
116116
end
117117

118-
def has_scripttags?
119-
scripttags.present?
118+
def has_script_tags?
119+
script_tags.present?
120120
end
121121

122122
def requires_billing?

lib/shopify_app/engine.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module RedactJobParams
55
private
66

77
def args_info(job)
8-
log_disabled_classes = ["ShopifyApp::WebhooksManagerJob", "ShopifyApp::ScripttagsManagerJob"]
8+
log_disabled_classes = ["ShopifyApp::WebhooksManagerJob", "ShopifyApp::ScriptTagsManagerJob"]
99
return "" if log_disabled_classes.include?(job.class.name)
1010

1111
super
@@ -30,7 +30,7 @@ class Engine < Rails::Engine
3030
ActiveSupport.on_load(:active_job) do
3131
if ActiveJob::Base.respond_to?(:log_arguments?)
3232
WebhooksManagerJob.log_arguments = false
33-
ScripttagsManagerJob.log_arguments = false
33+
ScriptTagsManagerJob.log_arguments = false
3434
elsif ActiveJob::Logging::LogSubscriber.private_method_defined?(:args_info)
3535
ActiveJob::Logging::LogSubscriber.prepend(RedactJobParams)
3636
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# frozen_string_literal: true
2+
3+
module ShopifyApp
4+
class ScriptTagsManagerJob < ActiveJob::Base
5+
queue_as do
6+
ShopifyApp.configuration.script_tags_manager_queue_name
7+
end
8+
9+
def perform(shop_domain:, shop_token:, script_tags:)
10+
ShopifyAPI::Auth::Session.temp(shop: shop_domain, access_token: shop_token) do |session|
11+
manager = ScriptTagsManager.new(script_tags, shop_domain)
12+
manager.create_script_tags(session: session)
13+
end
14+
end
15+
end
16+
end

lib/shopify_app/jobs/scripttags_manager_job.rb

-16
This file was deleted.

lib/shopify_app/managers/scripttags_manager.rb lib/shopify_app/managers/script_tags_manager.rb

+33-33
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
# frozen_string_literal: true
22

33
module ShopifyApp
4-
class ScripttagsManager
5-
def self.queue(shop_domain, shop_token, scripttags)
6-
ShopifyApp::ScripttagsManagerJob.perform_later(
4+
class ScriptTagsManager
5+
def self.queue(shop_domain, shop_token, script_tags)
6+
ShopifyApp::ScriptTagsManagerJob.perform_later(
77
shop_domain: shop_domain,
88
shop_token: shop_token,
99
# Procs cannot be serialized so we interpolate now, if necessary
10-
scripttags: build_src(scripttags, shop_domain),
10+
script_tags: build_src(script_tags, shop_domain),
1111
)
1212
end
1313

14-
def self.build_src(scripttags, domain)
15-
scripttags.map do |tag|
14+
def self.build_src(script_tags, domain)
15+
script_tags.map do |tag|
1616
next tag unless tag[:src].respond_to?(:call)
1717

1818
tag = tag.dup
@@ -21,25 +21,25 @@ def self.build_src(scripttags, domain)
2121
end
2222
end
2323

24-
attr_reader :required_scripttags, :shop_domain
24+
attr_reader :required_script_tags, :shop_domain
2525

26-
def initialize(scripttags, shop_domain)
27-
@required_scripttags = scripttags
26+
def initialize(script_tags, shop_domain)
27+
@required_script_tags = script_tags
2828
@shop_domain = shop_domain
2929
@session = nil
3030
end
3131

32-
def recreate_scripttags!(session:)
33-
destroy_scripttags(session: session)
34-
create_scripttags(session: session)
32+
def recreate_script_tags!(session:)
33+
destroy_script_tags(session: session)
34+
create_script_tags(session: session)
3535
end
3636

37-
def create_scripttags(session:)
37+
def create_script_tags(session:)
3838
@session = session
39-
return unless required_scripttags.present?
39+
return unless required_script_tags.present?
4040

4141
# Check if any scripttag has template_types defined
42-
template_types_to_check = required_scripttags.flat_map { |tag| tag[:template_types] }.compact.uniq
42+
template_types_to_check = required_script_tags.flat_map { |tag| tag[:template_types] }.compact.uniq
4343

4444
# If template types are specified, check if the theme supports app blocks for those templates
4545
if template_types_to_check.any?
@@ -59,19 +59,19 @@ def create_scripttags(session:)
5959
end
6060
end
6161

62-
expanded_scripttags.each do |scripttag|
63-
create_scripttag(scripttag) unless scripttag_exists?(scripttag[:src])
62+
expanded_script_tags.each do |script_tag|
63+
create_script_tag(script_tag) unless script_tag_exists?(script_tag[:src])
6464
end
6565
end
6666

67-
def destroy_scripttags(session:)
67+
def destroy_script_tags(session:)
6868
@session = session
69-
scripttags = expanded_scripttags
70-
fetch_all_scripttags.each do |tag|
71-
delete_scripttag(tag) if required_scripttag?(scripttags, tag)
69+
script_tags = expanded_script_tags
70+
fetch_all_script_tags.each do |tag|
71+
delete_script_tag(tag) if required_script_tag?(script_tags, tag)
7272
end
7373

74-
@current_scripttags = nil
74+
@current_script_tags = nil
7575
end
7676

7777
private
@@ -236,15 +236,15 @@ def template_supports_app_blocks?(theme_id, template_type)
236236
end
237237
end
238238

239-
def expanded_scripttags
240-
self.class.build_src(required_scripttags, shop_domain)
239+
def expanded_script_tags
240+
self.class.build_src(required_script_tags, shop_domain)
241241
end
242242

243-
def required_scripttag?(scripttags, tag)
244-
scripttags.map { |w| w[:src] }.include?(tag["src"])
243+
def required_script_tag?(script_tags, tag)
244+
script_tags.map { |w| w[:src] }.include?(tag["src"])
245245
end
246246

247-
def create_scripttag(attributes)
247+
def create_script_tag(attributes)
248248
client = graphql_client
249249

250250
variables = {
@@ -287,7 +287,7 @@ def create_scripttag(attributes)
287287
end
288288
end
289289

290-
def delete_scripttag(tag)
290+
def delete_script_tag(tag)
291291
client = graphql_client
292292

293293
query = <<~QUERY
@@ -311,15 +311,15 @@ def delete_scripttag(tag)
311311
end
312312
end
313313

314-
def scripttag_exists?(src)
315-
current_scripttags[src]
314+
def script_tag_exists?(src)
315+
current_script_tags[src]
316316
end
317317

318-
def current_scripttags
319-
@current_scripttags ||= fetch_all_scripttags.index_by { |tag| tag["src"] }
318+
def current_script_tags
319+
@current_script_tags ||= fetch_all_script_tags.index_by { |tag| tag["src"] }
320320
end
321321

322-
def fetch_all_scripttags
322+
def fetch_all_script_tags
323323
client = graphql_client
324324

325325
query = <<~QUERY

test/dummy/config/initializers/shopify_app.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def self.call
1313
config.myshopify_domain = "myshopify.com"
1414
config.api_version = ShopifyAPI::LATEST_SUPPORTED_ADMIN_VERSION
1515
config.billing = nil
16-
config.scripttags = nil
16+
config.script_tags = nil
1717
config.embedded_redirect_url = nil
1818

1919
config.shop_session_repository = ShopifyApp::InMemorySessionStore

0 commit comments

Comments
 (0)