Module: CleoDesignTokens
- Defined in:
- lib/cleo_design_tokens.rb,
lib/cleo_design_tokens/bucket.rb,
lib/cleo_design_tokens/errors.rb,
lib/cleo_design_tokens/version.rb,
lib/cleo_design_tokens/tree_walker.rb,
lib/cleo_design_tokens/lookup_builder.rb,
lib/cleo_design_tokens/semantic_entry.rb,
lib/cleo_design_tokens/semantic_bucket.rb
Overview
Reads Cleo's canonical colour design tokens (packages/tokens/tokens/color) into two frozen lookups, namespaced by token type then layer, with the theme passed alongside the key rather than baked into it.
CleoDesignTokens.colors.semantic.fetch("core.content.primary") # => "#47201C"
CleoDesignTokens.colors.semantic.fetch("core.content.primary", theme: :roast) # => "#F8F6F2"
CleoDesignTokens.colors.primitives.fetch("brown.800") # => "#47201C"
Defined Under Namespace
Modules: LookupBuilder, TreeWalker Classes: Bucket, Colors, DuplicateTokenError, SemanticBucket, SemanticEntry, UnknownThemeError, UnknownTokenError
Constant Summary collapse
- TOKENS_DIR =
File.("../tokens/color", __dir__)
- PRIMITIVES_PATH =
File.join(TOKENS_DIR, "primitives.json")
- SEMANTIC_PATH =
File.join(TOKENS_DIR, "semantic.json")
- PRIMITIVES_LOOKUP =
Built at load, into constants — not
@lookup ||=, which would race under concurrent access. Frozen from the moment the gem loads, so every reader in every thread sees the same immutable lookup. LookupBuilder.build_lookup(JSON.parse(File.read(PRIMITIVES_PATH))).freeze
- SEMANTIC_LOOKUP =
LookupBuilder.build_semantic_lookup(JSON.parse(File.read(SEMANTIC_PATH))).freeze
- COLORS =
Colors.new(primitives: Bucket.new(PRIMITIVES_LOOKUP), semantic: SemanticBucket.new(SEMANTIC_LOOKUP))
- VERSION =
The release workflow writes the computed version into
package.jsonbefore building either artifact. The gemspec ships that file alongsidelib/(seespec.files) so this read works from an installed gem too. JSON.parse(File.read(File.("../../package.json", __dir__))).fetch("version")
Class Method Summary collapse
Class Method Details
.colors ⇒ Object
42 43 44 |
# File 'lib/cleo_design_tokens.rb', line 42 def self.colors COLORS end |