Module: Rails::Assets::Manifest::Helper

Defined in:
lib/rails/assets/manifest/helper.rb

Constant Summary collapse

URI_REGEXP =
%r{^[-a-z]+://|^(?:cid|data):|^//}i.freeze

Instance Method Summary collapse

Instance Method Details

#asset_integrity(name, options) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/rails/assets/manifest/helper.rb', line 33

def asset_integrity(name, options)
  ::Rails::Assets::Manifest.lookup!(path_with_extname(name, options)).integrity
rescue EntryMissing
  return super if Rails::Assets::Manifest.passthrough?

  raise
end

#compute_asset_path(name, _options) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/rails/assets/manifest/helper.rb', line 25

def compute_asset_path(name, _options)
  ::Rails::Assets::Manifest.lookup!(name).src
rescue EntryMissing
  return super if Rails::Assets::Manifest.passthrough?

  raise
end

#javascript_include_tag(*sources, integrity: nil, **kwargs) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/rails/assets/manifest/helper.rb', line 41

def javascript_include_tag(*sources, integrity: nil, **kwargs)
  return super(*sources, **kwargs) unless manifest_use_integrity?(integrity)

  with_integrity(sources, integrity, :javascript, **kwargs) do |source, options|
    super(source, options)
  end
end

#path_to_asset(source, options) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/rails/assets/manifest/helper.rb', line 7

def path_to_asset(source, options)
  if (entry = ::Rails::Assets::Manifest.lookup(path_with_extname(source, options)))
    # Directly return the entry src if it is a fully qualified URL. Otherwise,
    # Rails will join the URL with `relative_url_root` and/or asset host.
    return entry.src if URI_REGEXP.match?(entry.src)

    if entry.src[0] == '/'
      # When the asset name starts with a slash, Rails will skip an
      # additional lookup via `#compute_asset_path` and directly use the
      # provided path. As we already have looked up the manifest entry here,
      # we can pass the entry source, but only *if* it starts with a slash.
      return super entry.src, options
    end
  end

  super
end


49
50
51
52
53
54
55
# File 'lib/rails/assets/manifest/helper.rb', line 49

def stylesheet_link_tag(*sources, integrity: nil, **kwargs)
  return super(*sources, **kwargs) unless manifest_use_integrity?(integrity)

  with_integrity(sources, integrity, :stylesheet, **kwargs) do |source, options|
    super(source, options)
  end
end