# frozen_string_literal: true module Proscenium module Phlex::CssModules include Proscenium::CssModule def self.included(base) base.extend CssModule::Path base.extend ClassMethods end module ClassMethods # Set of CSS module paths that have been resolved after being transformed from 'class' HTML # attributes. See #process_attributes. This is here because Phlex caches attributes. Which # means while the CSS class names will be transformed, any resolved paths will be lost in # subsequent requests. attr_accessor :resolved_css_module_paths end def before_template self.class.resolved_css_module_paths ||= Concurrent::Set.new super end def after_template self.class.resolved_css_module_paths.each do |path| Proscenium::Importer.import path end super end # Resolve and side load any CSS modules in the "class" attributes, where a CSS module is a class # name beginning with a `@`. The class name is resolved to a CSS module name based on the file # system path of the Phlex class, and any CSS file is side loaded. # # For example, the following will side load the CSS module file at # app/components/user/component.module.css, and add the CSS Module name `user_name` to the #