Skip to content

Instantly share code, notes, and snippets.

@andrewmcodes
Last active June 11, 2021 23:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewmcodes/33c7c0f869586d604d678a4b85139f4a to your computer and use it in GitHub Desktop.
Save andrewmcodes/33c7c0f869586d604d678a4b85139f4a to your computer and use it in GitHub Desktop.
Simple Bridgetown ViewComponent Example
# src/_components/base_component.rb
class BaseComponent < ViewComponent::Base
include Bridgetown::ViewComponentHelpers
TWITTER_PROFILE_URL = "https://twitter.com/andrewmcodes"
def twitter_link
link_to "Twitter", TWITTER_PROFILE_URL
end
end
<%# src/_components/header.erb %>
<header class="p-2 text-white bg-blue-600">
<h1><%= @title %></h1>
<%= markdownify @description %>
<%= twitter_link %>
</header>
# src/_components/header_component.rb
class HeaderComponent < BaseComponent
def initialize(title:, description:)
@title = title
@description = description
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment