From 7bbe0653223d03c0999dbed76070804676daf901 Mon Sep 17 00:00:00 2001 From: Stefan Bilharz Date: Thu, 20 Jun 2024 22:54:28 +0200 Subject: [PATCH 1/2] HTML-36 Always convert attribute values to String --- spec/instance_template/attributes_spec.cr | 4 ++-- src/attribute_hash.cr | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/instance_template/attributes_spec.cr b/spec/instance_template/attributes_spec.cr index a1584ca..174406c 100644 --- a/spec/instance_template/attributes_spec.cr +++ b/spec/instance_template/attributes_spec.cr @@ -17,10 +17,10 @@ module ToHtml::InstanceTemplate::AttributesSpec end fieldset do - label for: SomeId.to_s do + label for: SomeId do "Options" end - select_tag id: SomeId.to_s, name: "myselect" do + select_tag id: SomeId, name: "myselect" do option(value: "", selected: false) { "-" } ["one", "two", "three"].each do |val| option(value: val, selected: val == DEFAULT_VALUE) { val } diff --git a/src/attribute_hash.cr b/src/attribute_hash.cr index d279ce7..4e27bc4 100644 --- a/src/attribute_hash.cr +++ b/src/attribute_hash.cr @@ -19,7 +19,7 @@ module ToHtml if attributes.has_key?(key) attributes[key] += " #{value}" else - attributes[key] = value + attributes[key] = value.to_s end end From 62d90ee879f1ae6f87c7ed481799a1e3261da293 Mon Sep 17 00:00:00 2001 From: Stefan Bilharz Date: Thu, 20 Jun 2024 22:55:05 +0200 Subject: [PATCH 2/2] HTML-36 Don't concatenate blank on nil attribute value --- spec/instance_template/attributes_spec.cr | 2 +- src/attribute_hash.cr | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/instance_template/attributes_spec.cr b/spec/instance_template/attributes_spec.cr index 174406c..24f4a9d 100644 --- a/spec/instance_template/attributes_spec.cr +++ b/spec/instance_template/attributes_spec.cr @@ -8,7 +8,7 @@ module ToHtml::InstanceTemplate::AttributesSpec ToHtml.instance_template do div MyCssClass, MyOtherCssClass, {"class", "so-unique"}, more_css_classes do span(SPECIAL_CSS_CLASSES) { "Blah" } - img SPECIAL_CSS_CLASSES, more_css_classes + img SPECIAL_CSS_CLASSES, more_css_classes, {"class", nil} div MyStimulusController do p({"class", "so-special"}) do "Some content" diff --git a/src/attribute_hash.cr b/src/attribute_hash.cr index 4e27bc4..9a1b288 100644 --- a/src/attribute_hash.cr +++ b/src/attribute_hash.cr @@ -17,7 +17,7 @@ module ToHtml def []=(key, value) if attributes.has_key?(key) - attributes[key] += " #{value}" + attributes[key] += " #{value}" if value else attributes[key] = value.to_s end