Class: Guardrails::Tokens::TailwindConfigParser
- Inherits:
-
Object
- Object
- Guardrails::Tokens::TailwindConfigParser
- Defined in:
- lib/guardrails/tokens/tailwind_config_parser.rb
Overview
Best-effort regex/character-walk parser for Tailwind v3 config files. Extracts color entries from ‘theme.colors` and `theme.extend.colors` blocks. Handles flat scalars and one level of nested scales (per Tailwind convention: `gray: { 50: “#f9fafb” }` flattens to `gray-50`).
Known limitations (out of scope for V0):
-
Function-valued entries (‘primary: defineColor(“blue”)`)
-
Spread operators (‘…palette`)
-
require()/import() of external palettes
-
Computed keys
-
TypeScript configs with type annotations on values
For any of these the entry is silently skipped; the user is encouraged to migrate to Tailwind v4 ‘@theme` (CSS-first) which parses cleanly through the existing CSS custom property path.
Defined Under Namespace
Classes: Entry
Constant Summary collapse
- COLORS_BLOCK_HEADER =
/\bcolors\s*:\s*\{/
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(content) ⇒ TailwindConfigParser
constructor
A new instance of TailwindConfigParser.
- #parse ⇒ Object
Constructor Details
#initialize(content) ⇒ TailwindConfigParser
Returns a new instance of TailwindConfigParser.
30 31 32 |
# File 'lib/guardrails/tokens/tailwind_config_parser.rb', line 30 def initialize(content) @content = content end |
Class Method Details
.parse(content) ⇒ Object
26 27 28 |
# File 'lib/guardrails/tokens/tailwind_config_parser.rb', line 26 def self.parse(content) new(content).parse end |
Instance Method Details
#parse ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/guardrails/tokens/tailwind_config_parser.rb', line 34 def parse entries = [] scan_colors_blocks do |body| entries.concat(extract_entries(body)) end entries end |