Module: Proscenium::Helper

Defined in:
lib/proscenium/helper.rb

Instance Method Summary collapse

Instance Method Details

#compute_asset_path(path, options = {}) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/proscenium/helper.rb', line 14

def compute_asset_path(path, options = {})
  if %i[javascript stylesheet].include?(options[:type])
    return Proscenium::Manifest[path] || "/#{path}"
  end

  super
end

#css_module(*names, path: nil) ⇒ String

Accepts one or more CSS class names, and transforms them into CSS module names.

Parameters:

  • name (String, Symbol, Array<String,Symbol>)
  • path (Pathname) (defaults to: nil)

    the path to the CSS module file to use for the transformation.

Returns:

  • (String)

    the transformed CSS module names concatenated as a string.

See Also:



28
29
30
31
32
# File 'lib/proscenium/helper.rb', line 28

def css_module(*names, path: nil)
  path ||= Pathname.new(@lookup_context.find(@virtual_path).identifier).sub_ext('')
  CssModule::Transformer.new(path).class_names(*names, require_prefix: false)
                        .map { |name, _| name }.join(' ')
end

#include_assetsObject



34
35
36
# File 'lib/proscenium/helper.rb', line 34

def include_assets
  include_stylesheets + include_javascripts
end

#include_javascriptsString

Includes all javascripts that have been imported and side loaded.

Returns:

  • (String)

    the HTML tags for the javascripts.



45
46
47
# File 'lib/proscenium/helper.rb', line 45

def include_javascripts
  SideLoad::JS_COMMENT.html_safe
end

#include_stylesheetsObject



38
39
40
# File 'lib/proscenium/helper.rb', line 38

def include_stylesheets
  SideLoad::CSS_COMMENT.html_safe
end

#sideload_assets(value) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/proscenium/helper.rb', line 5

def sideload_assets(value)
  if value.nil?
    @current_template.instance_variable_defined?(:@sideload_assets_options) &&
      @current_template.remove_instance_variable(:@sideload_assets_options)
  else
    @current_template.instance_variable_set :@sideload_assets_options, value
  end
end