Class: ViewComponentCssDsl::Verifier::CompiledCssOracle
- Inherits:
-
Object
- Object
- ViewComponentCssDsl::Verifier::CompiledCssOracle
- Defined in:
- lib/view_component_css_dsl/verifier/compiled_css_oracle.rb
Overview
The class-validity oracle for Verifier, built from a compiled Tailwind CSS file. Tailwind’s JIT generates a rule for every valid class it finds in your content globs — so as long as your component .rb files are in those globs, the compiled output contains exactly the valid classes among those you declared. A declared class missing from the output is a typo, a hallucination, or a value your theme doesn’t define.
oracle = ViewComponentCssDsl::Verifier::CompiledCssOracle.new(
"app/assets/builds/tailwind.css"
)
oracle.include?("bg-blue-500") # => true
oracle.include?("bg-blurple") # => false
Caveat: the oracle is only as fresh as the build. Rebuild Tailwind before verifying, or a just-added valid class will be flagged as unknown.
Constant Summary collapse
- CLASS_SELECTOR =
Class selector: a dot, then word chars / hyphens / CSS escapes. Tailwind escapes special chars with a backslash (‘.hover:bg-blue-500`) and leading digits as hex (`.32 xl:grid`).
/\.((?:\\[0-9a-fA-F]{1,6}\s?|\\.|[\w-])+)/
Instance Method Summary collapse
- #include?(class_name) ⇒ Boolean
-
#initialize(css_path) ⇒ CompiledCssOracle
constructor
A new instance of CompiledCssOracle.
- #size ⇒ Object
Constructor Details
#initialize(css_path) ⇒ CompiledCssOracle
Returns a new instance of CompiledCssOracle.
26 27 28 |
# File 'lib/view_component_css_dsl/verifier/compiled_css_oracle.rb', line 26 def initialize(css_path) @classes = parse(File.read(css_path)) end |
Instance Method Details
#include?(class_name) ⇒ Boolean
30 |
# File 'lib/view_component_css_dsl/verifier/compiled_css_oracle.rb', line 30 def include?(class_name) = @classes.include?(class_name) |
#size ⇒ Object
32 |
# File 'lib/view_component_css_dsl/verifier/compiled_css_oracle.rb', line 32 def size = @classes.size |