@@ -196,6 +196,7 @@ def __init__(self, project_src_path):
196196 self .libraries = {}
197197 self .templates : dict [str , Template ] = {}
198198 self .global_template_context = {}
199+ self .css_class_names = []
199200
200201 def collect (self ):
201202 self .file_watcher_globs = self .get_file_watcher_globs ()
@@ -204,6 +205,7 @@ def collect(self):
204205 self .urls = self .get_urls ()
205206 self .libraries = self .get_libraries ()
206207 self .global_template_context = self .get_global_template_context ()
208+ self .css_class_names = self .get_css_class_names ()
207209
208210 # Third party collectors
209211 self .collect_for_wagtail ()
@@ -217,6 +219,7 @@ def to_json(self):
217219 "libraries" : self .libraries ,
218220 "templates" : self .templates ,
219221 "global_template_context" : self .global_template_context ,
222+ "css_class_names" : self .css_class_names ,
220223 },
221224 indent = 4 ,
222225 )
@@ -573,6 +576,23 @@ def collect_for_wagtail(self):
573576 model .context_object_name
574577 ] = (model .__module__ + "." + model .__name__ )
575578
579+ # CSS class names
580+ # ---------------------------------------------------------------------------------
581+ def get_css_class_names (self ):
582+ class_pattern = re .compile (r"\.(?!\d)([a-zA-Z0-9_-]+)" )
583+ class_names = set ()
584+
585+ for finder in get_finders ():
586+ for path , file_storage in finder .list (None ):
587+ if path .endswith (".css" ) and not path .startswith ("admin" ):
588+ try :
589+ with file_storage .open (path , "r" ) as f :
590+ content = f .read ()
591+ class_names .update (class_pattern .findall (content ))
592+ except Exception as e :
593+ logger .error (f"Could not parse CSS file: { e } " )
594+ return list (class_names )
595+
576596
577597#######################################################################################
578598# CLI
0 commit comments