-
-
Save paulcsmith/5392b466ba88ede134175097d8f74812 to your computer and use it in GitHub Desktop.
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
abstract class LuckyWeb::HTMLView | |
abstract def render | |
def initialize | |
@io = IO::Memory.new | |
end | |
EMPTY_HTML_ATTRS = {} of String => String | |
def h6(&block) | |
h6(EMPTY_HTML_ATTRS) do | |
yield | |
end | |
end | |
def h6(content, options) | |
h6(options) do | |
text content | |
end | |
end | |
def h6(content, **options) | |
h6(options) do | |
text content | |
end | |
end | |
def h6(content : String) | |
h6(EMPTY_HTML_ATTRS) do | |
text content | |
end | |
end | |
def h6(options, &block) | |
tag_attrs = build_tag_attrs(options) | |
@io << %(<h6#{tag_attrs}>) | |
yield | |
@io << %(</h6>) | |
end | |
def text(content : String) | |
@io << content | |
end | |
private def build_tag_attrs(options) | |
tag_attrs = String.build do |attrs| | |
options.each do |key, value| | |
attrs << %( #{key}="#{value}") | |
end | |
end | |
end | |
private def build_tag_attrs(**options) | |
tag_attrs = String.build do |attrs| | |
options.each do |key, value| | |
attrs << %( #{key}="#{value}") | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment