Last active
June 11, 2021 23:54
-
-
Save andrewmcodes/33c7c0f869586d604d678a4b85139f4a to your computer and use it in GitHub Desktop.
Simple Bridgetown ViewComponent Example
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
# 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 |
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
<%# src/_components/header.erb %> | |
<header class="p-2 text-white bg-blue-600"> | |
<h1><%= @title %></h1> | |
<%= markdownify @description %> | |
<%= twitter_link %> | |
</header> |
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
# 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