Module: Jets::AssetTagHelper

Includes:
CommonMethods
Defined in:
lib/jets/rails_overrides/asset_tag_helper.rb

Overview

Override to prepend stage name when on AWS.

Instance Method Summary collapse

Methods included from CommonMethods

#add_stage_name

Instance Method Details

#javascript_include_tag(*sources, **options) ⇒ Object



5
6
7
8
# File 'lib/jets/rails_overrides/asset_tag_helper.rb', line 5

def javascript_include_tag(*sources, **options)
  sources = sources.map { |s| stage_name_asset_url(s, :javascripts) }
  super
end

#stage_name_asset_url(url, asset_type) ⇒ Object

User can use:

javascript_include_tag "assets/test"

Rails automatically adds “javscript” in front, to become:

/javascripts/assets/test

We want to add the API Gateway stage name in front for this:

/stag/javascript/asset/test

But adding it in front results in this:

/javascript/stag/asset/test

If there’s a / in front then rails will not add the “javascript”: So we can add the javascript ourselves and then add the stag with a / in front.



33
34
35
36
37
38
39
# File 'lib/jets/rails_overrides/asset_tag_helper.rb', line 33

def stage_name_asset_url(url, asset_type)
  unless url.starts_with?('/') or url.starts_with?('http')
    url = "/#{asset_type}/#{url}" # /javascript/asset/test
  end
  url = add_stage_name(url)
  url
end


10
11
12
13
# File 'lib/jets/rails_overrides/asset_tag_helper.rb', line 10

def stylesheet_link_tag(*sources, **options)
  sources = sources.map { |s| stage_name_asset_url(s, :stylesheets) }
  super
end