Skip to content

Commit

Permalink
HTML-38 Implement NamedTuple#to_html_attrs
Browse files Browse the repository at this point in the history
  • Loading branch information
sbsoftware committed Jul 25, 2024
1 parent c331c01 commit 41baf2b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions spec/instance_template/attributes_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -80,7 +80,7 @@ module ToHtml::InstanceTemplate::AttributesSpec

expected = <<-HTML
<div class="my-css-class my-other-css-class so-unique my-third-css-class that-other-css-class">
<span class="my-css-class my-other-css-class">Blah</span>
<span class="my-css-class my-other-css-class moo">Blah</span>
<img class="my-css-class my-other-css-class my-third-css-class that-other-css-class">
<div data-controller="my" data-action="click->handle_click()">
<p class="so-special">Some content</p>
Expand Down
7 changes: 7 additions & 0 deletions src/ext/named_tuple.cr
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions src/to_html.cr
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
require "./instance_template"
require "./instance_tag_attrs"
require "./ext/**"

0 comments on commit 41baf2b

Please sign in to comment.