Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/class_variants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,17 @@ def configure(&block)
def build(...)
Instance.new(...)
end

def definitions
@definitions ||= {}
end

def define(name, ...)
definitions[name.to_sym] = Instance.new(...)
end

def for(name)
definitions[name.to_sym]
end
end
end
22 changes: 22 additions & 0 deletions test/definitions_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require "test_helper"

class DefinitionsTest < Minitest::Test
def setup
ClassVariants.define :button do
variant color: :primary, class: "bg-orange-500"
end

ClassVariants.define :link do
variant color: :primary, class: "bg-blue-500"
end
end

def teardown
ClassVariants.instance_variable_set(:@definitions, nil)
end

def test_definitions
assert_equal "bg-orange-500", ClassVariants.for(:button).render(color: :primary)
assert_equal "bg-blue-500", ClassVariants.for(:link).render(color: :primary)
end
end