Sha256: bdb5a0af9d0e580c37e6244b06b8acfa73bae37dec0a7c12e0485da505b84753

Contents?: true

Size: 1.15 KB

Versions: 40

Compression:

Stored size: 1.15 KB

Contents

# Override to prepend stage name when on AWS.
module Jets::AssetTagHelper
  include Jets::CommonMethods

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

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

  # 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.
  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
end
ActionView::Helpers.send(:include, Jets::AssetTagHelper)

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
jets-0.9.1 lib/jets/rails_overrides/asset_tag_helper.rb
jets-0.9.0 lib/jets/rails_overrides/asset_tag_helper.rb
jets-0.8.18 lib/jets/rails_overrides/asset_tag_helper.rb
jets-0.8.17 lib/jets/rails_overrides/asset_tag_helper.rb
jets-0.8.15 lib/jets/rails_overrides/asset_tag_helper.rb
jets-0.8.14 lib/jets/rails_overrides/asset_tag_helper.rb
jets-0.8.13 lib/jets/rails_overrides/asset_tag_helper.rb
jets-0.8.12 lib/jets/rails_overrides/asset_tag_helper.rb
jets-0.8.11 lib/jets/rails_overrides/asset_tag_helper.rb
jets-0.8.10 lib/jets/rails_overrides/asset_tag_helper.rb
jets-0.8.9 lib/jets/rails_overrides/asset_tag_helper.rb
jets-0.8.8 lib/jets/rails_overrides/asset_tag_helper.rb
jets-0.8.6 lib/jets/rails_overrides/asset_tag_helper.rb
jets-0.8.5 lib/jets/rails_overrides/asset_tag_helper.rb
jets-0.8.4 lib/jets/rails_overrides/asset_tag_helper.rb
jets-0.8.3 lib/jets/rails_overrides/asset_tag_helper.rb
jets-0.8.2 lib/jets/rails_overrides/asset_tag_helper.rb
jets-0.8.1 lib/jets/rails_overrides/asset_tag_helper.rb
jets-0.8.0 lib/jets/rails_overrides/asset_tag_helper.rb
jets-0.7.1 lib/jets/rails_overrides/asset_tag_helper.rb