Created
September 2, 2022 16:51
-
-
Save KonnorRogers/e6349f1cebca29e6718a11a5bd5d2503 to your computer and use it in GitHub Desktop.
single file view component using HTML
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
# https://replit.com/@paramagician/Single-File-View-Component#app/components/greeting_component.rb | |
class GreetingComponent < ViewComponent::Base | |
TEMPLATE = <<~HTML.freeze | |
<div> | |
<%= @greeting %> | |
</div> | |
HTML | |
COMPILED_TEMPLATE = ERB.new(TEMPLATE) | |
def initialize | |
@greeting = 'hi' | |
end | |
def call | |
COMPILED_TEMPLATE.result(binding) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment