Module: CleoDesignTokens::TreeWalker

Defined in:
lib/cleo_design_tokens/tree_walker.rb

Overview

Walks a token tree, skipping $-prefixed keys, yielding each leaf's path and node to the block. Keys are the JSON path, dot-joined — the files carry no color.primitives/color.semantic wrapper to strip, and segments are already normalised on disk, so there's nothing left for a caller to do to a path.

Class Method Summary collapse

Class Method Details

.walk(node, path = [], &on_leaf) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/cleo_design_tokens/tree_walker.rb', line 17

def self.walk(node, path = [], &on_leaf)
  return unless node.is_a?(Hash)
  return on_leaf.call(path, node) if leaf?(node)

  node.each do |child_key, child_value|
    next if child_key.start_with?("$")

    walk(child_value, path + [child_key], &on_leaf)
  end
end