Module: Proscenium::Helper

Defined in:
lib/proscenium/helper.rb

Instance Method Summary collapse

Instance Method Details

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

Returns the transformed CSS module names concatenated as a string.

Parameters:

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

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

Returns:

  • (String)

    the transformed CSS module names concatenated as a string.



42
43
44
45
46
47
48
49
# File 'lib/proscenium/helper.rb', line 42

def class_names(*names, path: nil)
  names = names.flatten.compact

  return if names.empty?

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

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

Overriden to allow regular use of javascript_include_tag and stylesheet_link_tag, while still building with Proscenium. It’s important to note that ‘include_assets` will not call this, as those asset paths all begin with a slash, which the Rails asset helpers do not pass through to here.



18
19
20
21
22
23
24
25
# File 'lib/proscenium/helper.rb', line 18

def compute_asset_path(path, options = {})
  if %i[javascript stylesheet].include?(options[:type])
    result = Proscenium::Builder.build_to_path(path, base_url: request.base_url)
    return result.split('::').last.delete_prefix 'public'
  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:



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

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



51
52
53
# File 'lib/proscenium/helper.rb', line 51

def include_assets
  include_stylesheets + include_javascripts
end

#include_javascriptsString Also known as: side_load_javascripts

Includes all javascripts that have been imported and side loaded.

Returns:

  • (String)

    the HTML tags for the javascripts.



64
65
66
# File 'lib/proscenium/helper.rb', line 64

def include_javascripts
  '<!-- [PROSCENIUM_LAZY_SCRIPTS] --><!-- [PROSCENIUM_JAVASCRIPTS] -->'.html_safe
end

#include_stylesheetsObject Also known as: side_load_stylesheets



55
56
57
# File 'lib/proscenium/helper.rb', line 55

def include_stylesheets
  '<!-- [PROSCENIUM_STYLESHEETS] -->'.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