Module: Frails::Helper

Defined in:
lib/frails/helper.rb

Instance Method Summary collapse

Instance Method Details

#image_pack_tag(name, **options) ⇒ Object



56
57
58
59
60
# File 'lib/frails/helper.rb', line 56

def image_pack_tag(name, **options)
  return if Rails.env.test?

  image_tag(pack_path("images/#{name}", manifest: options.delete(:manifest)), **options)
end

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



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/frails/helper.rb', line 26

def javascript_pack_tag(*names, **options)
  return if Rails.env.test?

  @included_javascripts ||= []

  soft_lookup = options.delete(:soft_lookup) { false }
  sources = sources_from_manifest_entries(names, :javascript, manifest: options.delete(:manifest),
                                                              soft_lookup: soft_lookup)

  # Make sure that we don't include an asset that has already been included.
  sources -= @included_javascripts
  sources.compact!

  # Concatenate the sources to be included to those already included.
  @included_javascripts.concat sources

  sources.empty? ? nil : javascript_include_tag(*sources, **options)
end

#pack_path(name, type: nil, manifest: nil) ⇒ Object



62
63
64
# File 'lib/frails/helper.rb', line 62

def pack_path(name, type: nil, manifest: nil)
  manifest_manager[manifest].lookup! name, type: type
end

#render(options = {}, locals = {}, &block) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/frails/helper.rb', line 4

def render(options = {}, locals = {}, &block)
  sload_assets = respond_to?(:side_load_assets?) ? side_load_assets? : false

  case options
  when Hash
    in_rendering_context(options) do
      options[:side_load_assets] = sload_assets

      return view_renderer.render_component(self, options, &block) if options.key?(:component)

      if block_given?
        view_renderer.render_partial(self, options.merge(partial: options[:layout]), &block)
      else
        view_renderer.render(self, options)
      end
    end
  else
    view_renderer.render_partial(self, side_load_assets: sload_assets, partial: options,
                                       locals: locals, &block)
  end
end

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



45
46
47
48
49
50
51
52
53
54
# File 'lib/frails/helper.rb', line 45

def stylesheet_pack_tag(*names, **options)
  return if Rails.env.test?

  soft_lookup = options.delete(:soft_lookup) { false }
  sources = sources_from_manifest_entries(names, :stylesheet, manifest: options.delete(:manifest),
                                                              soft_lookup: soft_lookup)

  sources.compact!
  stylesheet_link_tag(*sources, **options)
end