-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from javierav/feature/helper
Add helper module for defining variants
- Loading branch information
Showing
4 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module ClassVariants | ||
module Helper | ||
module ClassMethods | ||
def class_variants(...) | ||
@_class_variants_instance = ClassVariants.build(...) | ||
end | ||
|
||
def _class_variants_instance | ||
@_class_variants_instance | ||
end | ||
end | ||
|
||
def self.included(base) | ||
base.extend(ClassMethods) | ||
end | ||
|
||
def class_variants(...) | ||
raise "You must configure class_variants in class definition" unless self.class._class_variants_instance | ||
|
||
self.class._class_variants_instance.render(...) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require "test_helper" | ||
|
||
class HelperTest < Minitest::Test | ||
class DemoClass | ||
include ClassVariants::Helper | ||
|
||
class_variants base: "rounded border" | ||
end | ||
|
||
def test_call_from_instance | ||
assert_equal "rounded border", DemoClass.new.class_variants | ||
end | ||
end |