Sha256: 83a72fac4fee5795cb1cdd74901e97db9c24954968f0f7ef3e5bb361a4a69178
Contents?: true
Size: 1.55 KB
Versions: 56
Compression:
Stored size: 1.55 KB
Contents
# frozen_string_literal: true module Proscenium::CssModule extend ActiveSupport::Autoload autoload :Path autoload :Transformer class TransformError < StandardError def initialize(name, additional_msg = nil) msg = "Failed to transform CSS module `#{name}`" msg << ' - ' << additional_msg if additional_msg super(msg) end end class Name def initialize(name, transform) @name = name @transform = transform end def to_s @transform end def to_sym @name end end # Accepts one or more CSS class names, and transforms them into CSS module names. # # @param name [String,Symbol,Array<String,Symbol>] # @param path [Pathname] the path to the CSS module file to use for the transformation. # @return [String] the transformed CSS module names concatenated as a string. 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 # @param name [String,Symbol,Array<String,Symbol>] # @param path [Pathname] the path to the CSS file to use for the transformation. # @return [String] the transformed CSS module names concatenated as a string. 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 private def cssm @cssm ||= Transformer.new(self.class.css_module_path) end end
Version data entries
56 entries across 56 versions & 1 rubygems