From 8b657ad97c945d85b484814bdaeaddfb8c067649 Mon Sep 17 00:00:00 2001 From: Stefan Bilharz Date: Tue, 18 Feb 2025 20:38:12 +0100 Subject: [PATCH 1/2] HTML-44 Rename `add_to_head` to `append_to_head` --- spec/layout_spec.cr | 4 ++-- src/layout.cr | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/layout_spec.cr b/spec/layout_spec.cr index 2433188..5344b70 100644 --- a/spec/layout_spec.cr +++ b/spec/layout_spec.cr @@ -50,8 +50,8 @@ module ToHtml::LayoutSpec delegate :window_title, to: something - add_to_head MyStyle - add_to_head MyScript + append_to_head MyStyle + append_to_head MyScript body_attributes MyId body_attributes OtherAttrs diff --git a/src/layout.cr b/src/layout.cr index 89561db..1170203 100644 --- a/src/layout.cr +++ b/src/layout.cr @@ -33,7 +33,7 @@ module ToHtml Tuple.new end - macro add_to_head(*objs) + macro append_to_head(*objs) def head_children {% if @type.methods.map(&.name).includes?("head_children".id) %} previous_def + Tuple.new({{objs.splat}}) From 68d348113f6e6bbc8c70cb1f6e6bf2208e37aa96 Mon Sep 17 00:00:00 2001 From: Stefan Bilharz Date: Tue, 18 Feb 2025 20:39:42 +0100 Subject: [PATCH 2/2] HTML-44 Introduce `prepend_to_head` macro --- spec/layout_spec.cr | 8 ++++---- src/layout.cr | 10 ++++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/spec/layout_spec.cr b/spec/layout_spec.cr index 5344b70..b07746f 100644 --- a/spec/layout_spec.cr +++ b/spec/layout_spec.cr @@ -51,7 +51,7 @@ module ToHtml::LayoutSpec delegate :window_title, to: something append_to_head MyStyle - append_to_head MyScript + prepend_to_head MyScript body_attributes MyId body_attributes OtherAttrs @@ -73,14 +73,14 @@ module ToHtml::LayoutSpec Surprise! + -
42
diff --git a/src/layout.cr b/src/layout.cr index 1170203..1ab6afd 100644 --- a/src/layout.cr +++ b/src/layout.cr @@ -43,6 +43,16 @@ module ToHtml end end + macro prepend_to_head(*objs) + def head_children + {% if @type.methods.map(&.name).includes?("head_children".id) %} + Tuple.new({{objs.splat}}) + previous_def + {% else %} + Tuple.new({{objs.splat}}) + super + {% end %} + end + end + def _body_attributes Tuple.new end