Module: Playbook::Tokens
- Defined in:
- lib/playbook/tokens.rb
Overview
Playbook design tokens for Rails. One JSON file per token type, generated by scripts/generate-tokens.js (yarn generate:tokens, run from playbook/). Source: token SCSS + types.
— Current design — Only colors: tokens/colors.json (accessible keys from _colors.module.scss + types/colors.ts). When you add or change accessible color tokens, run ‘yarn generate:tokens` and stage the updated colors.json; otherwise Overcommit will run the generator on commit and fail until you do.
— Next steps for additional token types —
-
One JSON per type (tokens/typography.json, tokens/spacing.json, …) and one method per type below.
-
For each new type: add a method (e.g. def typography) that loads the JSON and wraps in ColorHash (or a similar wrapper if the shape differs [TODO: Rename ColorHash to TokenHash if appropriate]). Add a reload_typography! (or reload_*!) if needed.
-
Ensure generate-tokens.js is extended to write that JSON (same pattern: compile SCSS → extract → write).
-
Update .overcommit.yml include paths and .git-hooks/pre_commit/verify_tokens.sh to compare the new generated file so commits stay in sync.
Example for typography:
def typography @typography ||= ColorHash.new(JSON.parse(File.read(File.join(__dir__, "tokens", "typography.json")), symbolize_names: true)) end def reload_typography! @typography = nil; typography end
Defined Under Namespace
Classes: ColorHash
Class Method Summary collapse
-
.colors ⇒ ColorHash
Load colors from generated tokens/colors.json (accessible keys only).
-
.reload_colors! ⇒ Object
Reload colors from JSON (useful after regenerating).
Class Method Details
.colors ⇒ ColorHash
Load colors from generated tokens/colors.json (accessible keys only).
40 41 42 43 44 45 46 |
# File 'lib/playbook/tokens.rb', line 40 def colors @colors ||= begin json_path = File.join(__dir__, "tokens", "colors.json") hash = JSON.parse(File.read(json_path), symbolize_names: true) ColorHash.new(hash) end end |
.reload_colors! ⇒ Object
Reload colors from JSON (useful after regenerating)
49 50 51 52 |
# File 'lib/playbook/tokens.rb', line 49 def reload_colors! @colors = nil colors end |