Module: Frails::Helper

Defined in:
lib/frails/helper.rb

Instance Method Summary collapse

Instance Method Details

#image_pack_tag(name, **options) ⇒ Object



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

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

rubocop:enable Metrics/AbcSize



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/frails/helper.rb', line 31

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



67
68
69
# File 'lib/frails/helper.rb', line 67

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

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

rubocop:disable Metrics/AbcSize



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

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
      return view_renderer.render_component(self, options, &block) if options.key?(:component)

      options[:side_load_assets] = sload_assets
      if block_given?
        view_renderer.render_partial(self, options.merge(partial: options[:layout]), &block)
      else
        view_renderer.render(self, options)
      end
    end
  else
    if options.is_a?(Class) && options < Frails::Component::Base
      return view_renderer.render_component(self, { component: options, locals: locals }, &block)
    end

    view_renderer.render_partial(self, side_load_assets: sload_assets, partial: options,
                                       locals: locals.extract_options!, &block)
  end
end

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



50
51
52
53
54
55
56
57
58
59
# File 'lib/frails/helper.rb', line 50

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