Module: DiscoApp::Concerns::RendersAssets
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/disco_app/concerns/renders_assets.rb
Instance Method Summary collapse
-
#queue_render_asset_group_job ⇒ Object
Callback, triggered after a model save.
-
#render_asset_group(asset_group) ⇒ Object
Render the specified asset group and upload the result to Shopify.
-
#renderable_asset_groups ⇒ Object
Copies the class-level hash of assets with symbol asset name as keys and their corresponding options as values to the instance.
Instance Method Details
#queue_render_asset_group_job ⇒ Object
Callback, triggered after a model save. Iterates through each asset group defined on the model and queues a render job if any of the changed attributes are found in the asset group's triggered_by list.
76 77 78 79 80 |
# File 'app/models/disco_app/concerns/renders_assets.rb', line 76 def queue_render_asset_group_job renderable_asset_groups.each do |asset_group, | DiscoApp::RenderAssetGroupJob.perform_later(shop, self, asset_group.to_s) unless (previous_changes.keys & [:triggered_by]).empty? end end |
#render_asset_group(asset_group) ⇒ Object
Render the specified asset group and upload the result to Shopify.
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'app/models/disco_app/concerns/renders_assets.rb', line 89 def render_asset_group(asset_group) = renderable_asset_groups[asset_group] public_urls = {}.with_indifferent_access [:assets].each do |asset| # Create/replace the asset via the Shopify API. shopify_asset = shop.with_api_context do ShopifyAPI::Asset.create( key: asset, value: render_asset_group_asset(asset, public_urls, ) ) end # Store the public URL to this asset, so that we're able to use it in # subsequent template renders. Adds a .css suffix to .scss assets, so that # we use the Shopify-compiled version of any SCSS stylesheets. public_urls[asset] = shopify_asset.public_url.gsub(/\.scss\?/, '.scss.css?') if shopify_asset.public_url.present? end # If we specified the creation of any script tags based on newly rendered # assets, do that now. (, public_urls) unless [:script_tags].empty? end |
#renderable_asset_groups ⇒ Object
Copies the class-level hash of assets with symbol asset name as keys and their corresponding options as values to the instance.
84 85 86 |
# File 'app/models/disco_app/concerns/renders_assets.rb', line 84 def renderable_asset_groups @renderable_asset_groups ||= self.class.renderable_asset_groups.dup end |