Created
March 29, 2018 12:42
-
-
Save nicolas-brousse/fda23564f0725c14b970a26cd9aed30a to your computer and use it in GitHub Desktop.
Komponent gem usage example
This file contains hidden or 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
| = content_tag(:div, html_attributes) do | |
| = yield_or_property(:message) |
This file contains hidden or 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
| .container(data-controller="container") | |
| = yield |
This file contains hidden or 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
| 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" |
This file contains hidden or 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
| # 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