Skip to content

Instantly share code, notes, and snippets.

@KonnorRogers
Created September 2, 2022 16:51
Show Gist options
  • Save KonnorRogers/e6349f1cebca29e6718a11a5bd5d2503 to your computer and use it in GitHub Desktop.
Save KonnorRogers/e6349f1cebca29e6718a11a5bd5d2503 to your computer and use it in GitHub Desktop.
single file view component using HTML
# 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