From 41baf2bd5a0737eedd245f06d4466b7b1d3a3d62 Mon Sep 17 00:00:00 2001 From: Stefan Bilharz Date: Thu, 25 Jul 2024 21:02:16 +0200 Subject: [PATCH] HTML-38 Implement NamedTuple#to_html_attrs --- spec/instance_template/attributes_spec.cr | 4 ++-- src/ext/named_tuple.cr | 7 +++++++ src/to_html.cr | 1 + 3 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 src/ext/named_tuple.cr diff --git a/spec/instance_template/attributes_spec.cr b/spec/instance_template/attributes_spec.cr index 24f4a9d..06492bb 100644 --- a/spec/instance_template/attributes_spec.cr +++ b/spec/instance_template/attributes_spec.cr @@ -7,7 +7,7 @@ module ToHtml::InstanceTemplate::AttributesSpec ToHtml.instance_template do div MyCssClass, MyOtherCssClass, {"class", "so-unique"}, more_css_classes do - span(SPECIAL_CSS_CLASSES) { "Blah" } + span(SPECIAL_CSS_CLASSES, {class: "moo"}) { "Blah" } img SPECIAL_CSS_CLASSES, more_css_classes, {"class", nil} div MyStimulusController do p({"class", "so-special"}) do @@ -80,7 +80,7 @@ module ToHtml::InstanceTemplate::AttributesSpec expected = <<-HTML
- Blah + Blah

Some content

diff --git a/src/ext/named_tuple.cr b/src/ext/named_tuple.cr new file mode 100644 index 0000000..84fd59b --- /dev/null +++ b/src/ext/named_tuple.cr @@ -0,0 +1,7 @@ +struct NamedTuple + def to_html_attrs(_tag, attr_hash) + each do |key, value| + attr_hash[key.to_s] = value + end + end +end diff --git a/src/to_html.cr b/src/to_html.cr index f433143..031d025 100644 --- a/src/to_html.cr +++ b/src/to_html.cr @@ -1,2 +1,3 @@ require "./instance_template" require "./instance_tag_attrs" +require "./ext/**"