Skip to content

Instantly share code, notes, and snippets.

@nicolas-brousse
Created March 29, 2018 12:42
Show Gist options
  • Save nicolas-brousse/fda23564f0725c14b970a26cd9aed30a to your computer and use it in GitHub Desktop.
Save nicolas-brousse/fda23564f0725c14b970a26cd9aed30a to your computer and use it in GitHub Desktop.
Komponent gem usage example
= content_tag(:div, html_attributes) do
= yield_or_property(:message)
- if link?
= link_to @href, link_attributes do
= yield_or_property(:text)
- else
= button_tag button_attributes do
= yield_or_property(:text)
.container(data-controller="container")
= yield
nav.navigation.navbar.navbar-expand-lg.navbar-light.bg-light.sticky-top
= c "container" do
= link_to t("brand_name"), root_path, class: "navbar-brand mb-0 h1"
button.navbar-toggler(type="button" data-toogle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toogle navigation")
span.navbar-toggler-icon
#navbarSupportedContent.collapse.navbar-collapse
ul.navbar-nav.mr-auto
li.nav-item.active
= link_to t("event").pluralize, "#", class: "nav-link"
= c "button", href: "#" do
= t("sign_up")
doctype html
html lang=I18n.locale
head
title Cultcheers
meta charset="utf-8"
/ meta name="ROBOTS" content="NOODP"
meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"
= csrf_meta_tags
= csp_meta_tag
= javascript_pack_tag "application"
= stylesheet_pack_tag "application", media: "all"
body
= c "navigation"
= c "alert" do
| Alert!
= c "container" do
= yield
= c "footer"
# frozen_string_literal: true
module ComponentHelper
def yield_or_property(property_name)
if block_given_to_component?
block_given_to_component
elsif properties.key? property_name
properties[property_name]
else
raise ArgumentError, "Missing required block component or parameter: #{property_name}"
end
end
def property_or_yield(property_name)
if properties.key? property_name
properties[property_name]
elsif block_given_to_component?
block_given_to_component
else
raise ArgumentError, "Missing required block component or parameter: #{property_name}"
end
end
private
def block_given_to_component
@_block_given_to_component = capture(&@block_given_to_component) if block_given_to_component?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment