Last active
February 1, 2024 20:15
-
-
Save bradgessler/c8385cd54b9b146a92acb77ecef80b1d to your computer and use it in GitHub Desktop.
Component helper
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
module ComponentHelper | |
def component(name, *args, **kwargs, &block) | |
render componentize(name).new(*args, **kwargs), &block | |
end | |
private | |
def componentize(name) | |
"#{name.to_s.classify}Component".constantize | |
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
<%= component :title, "Hello there", variant: "medium" %> |
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
class TitleComponent < ApplicationComponent | |
def initialize(title, variant: "large") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment