Module: Proscenium::CssModule

Extended by:
ActiveSupport::Autoload
Included in:
Phlex::CssModules, ViewComponent::CssModules
Defined in:
lib/proscenium/css_module.rb,
lib/proscenium/css_module/rewriter.rb

Defined Under Namespace

Modules: Path Classes: Name, Rewriter, TransformError, Transformer

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.



46
47
48
49
50
# File 'lib/proscenium/css_module.rb', line 46

def class_names(*names, path: nil)
  names = names.flatten.compact
  transformer = path.nil? ? cssm : Transformer.new(path)
  transformer.class_names(*names).map { |name, _| name }.join(' ') unless names.empty?
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.



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

def css_module(*names, path: nil)
  transformer = path.nil? ? cssm : Transformer.new(path)
  transformer.class_names(*names, require_prefix: false).map { |name, _| name }.join(' ')
end