diff --git a/spec/layout_spec.cr b/spec/layout_spec.cr index 2433188..b07746f 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 + 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 89561db..1ab6afd 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}}) @@ -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