Module: Simpacker::Helper

Defined in:
lib/simpacker/helper.rb

Instance Method Summary collapse

Instance Method Details

#asset_pack_path(name, **options) ⇒ Object



17
18
19
# File 'lib/simpacker/helper.rb', line 17

def asset_pack_path(name, **options)
  asset_path(simpacker_context.manifest.lookup!(name), **options)
end

#asset_pack_url(name, **options) ⇒ Object



21
22
23
# File 'lib/simpacker/helper.rb', line 21

def asset_pack_url(name, **options)
  asset_url(simpacker_context.manifest.lookup!(name), **options)
end

#favicon_pack_tag(name, **options) ⇒ Object



43
44
45
# File 'lib/simpacker/helper.rb', line 43

def favicon_pack_tag(name, **options)
  favicon_link_tag(asset_path(simpacker_context.manifest.lookup!(name)), **options)
end

#image_pack_tag(name, **options) ⇒ Object



25
26
27
# File 'lib/simpacker/helper.rb', line 25

def image_pack_tag(name, **options)
  image_tag(asset_path(simpacker_context.manifest.lookup!(name)), **options)
end

#image_pack_url(name, **options) ⇒ Object



29
30
31
# File 'lib/simpacker/helper.rb', line 29

def image_pack_url(name, **options)
  asset_url(simpacker_context.manifest.lookup!(name), **options)
end

#javascript_pack_tag(*names, **options) ⇒ Object



3
4
5
6
7
8
# File 'lib/simpacker/helper.rb', line 3

def javascript_pack_tag(*names, **options)
  sources = names.map do |name|
    simpacker_context.manifest.lookup!("#{name}#{compute_asset_extname(name.to_s, type: :javascript)}")
  end
  javascript_include_tag(*sources, **options)
end

#picture_pack_tag(*names, &block) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/simpacker/helper.rb', line 33

def picture_pack_tag(*names, &block)
  unless Rails.gem_version >= Gem::Version.new('7.1.0')
    raise NotImplementedError, '`picture_pack_tag` is only available for Rails 7.1 or above.'
  end
  names.flatten!
  options = names.extract_options!
  sources = names.map { |name| asset_path(simpacker_context.manifest.lookup!(name)) }
  picture_tag(*sources, options, &block)
end

#simpacker_contextObject



47
48
49
# File 'lib/simpacker/helper.rb', line 47

def simpacker_context
  Simpacker.default_context
end

#stylesheet_pack_tag(*names, **options) ⇒ Object



10
11
12
13
14
15
# File 'lib/simpacker/helper.rb', line 10

def stylesheet_pack_tag(*names, **options)
  sources = names.map do |name|
    simpacker_context.manifest.lookup!("#{name}#{compute_asset_extname(name.to_s, type: :stylesheet)}")
  end
  stylesheet_link_tag(*sources, **options)
end