Module: Jets::AssetTagHelper

Extended by:
Memoist
Includes:
AwsServices, 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 AwsServices

#cfn, #lambda, #logs, #s3, #s3_resource, #sns, #sts

Methods included from Jets::AwsServices::StackStatus

#stack_exists?, #stack_in_progress?

Methods included from CommonMethods

#add_stage?, #add_stage_name, #on_aws?

Instance Method Details

#asset_path(source, options = {}) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/jets/rails_overrides/asset_tag_helper.rb', line 35

def asset_path(source, options = {})
  if on_aws? && asset_folder?(source)
    # mimic original behavior to get /images in source
    source = "/images/#{source}" unless source.starts_with?('/')
    source = "#{s3_public}#{source}"
  end

  super
end

#favicon_path(path = 'favicon.ico') ⇒ Object

Serves favicon out of s3 when on API gateway.

Useful helper for API Gateway since serving binary data like images without an Accept header doesnt work well. You can changed Media Types to ‘/’ but then that messes up form data.



50
51
52
# File 'lib/jets/rails_overrides/asset_tag_helper.rb', line 50

def favicon_path(path='favicon.ico')
  on_aws? ? "#{s3_public}/#{path}" : "/#{path}"
end

#image_tag(source, options = {}) ⇒ Object

Locally:

image_tag("jets.png") => /images/jets.png
image_tag("/images/jets.png") => /images/jets.png

Remotely:

image_tag("jets.png") => https://s3-us-west-2.amazonaws.com/demo-dev-s3bucket-1kih4n2te0n66/jets/public/images/jets.png


25
26
27
28
29
30
31
32
33
# File 'lib/jets/rails_overrides/asset_tag_helper.rb', line 25

def image_tag(source, options = {})
  # mimic original behavior to get /images in source
  source = "/images/#{source}" unless source.starts_with?('/')
  if on_aws?
    source = "#{s3_public}#{source}"
  end

  super
end

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



7
8
9
10
# File 'lib/jets/rails_overrides/asset_tag_helper.rb', line 7

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


12
13
14
15
# File 'lib/jets/rails_overrides/asset_tag_helper.rb', line 12

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