diff --git a/spec/layout_spec.cr b/spec/layout_spec.cr index 0069eb4..2433188 100644 --- a/spec/layout_spec.cr +++ b/spec/layout_spec.cr @@ -23,19 +23,37 @@ module ToHtml::LayoutSpec end end + class MyScript + ToHtml.class_template do + script do + <<-JS + console.log("Hello World!"); + JS + end + end + end + class MyId ToHtml.class_tag_attrs do id = "the-id" end end + class OtherAttrs + ToHtml.class_tag_attrs do + style = "background-color: red;" + end + end + class MyLayout < Layout getter something : Something delegate :window_title, to: something add_to_head MyStyle + add_to_head MyScript body_attributes MyId + body_attributes OtherAttrs ToHtml.instance_template do super do @@ -60,8 +78,11 @@ module ToHtml::LayoutSpec background-color: #EEEEEE; } + - +
42
diff --git a/src/layout.cr b/src/layout.cr index 31fdea2..89561db 100644 --- a/src/layout.cr +++ b/src/layout.cr @@ -35,7 +35,7 @@ module ToHtml macro add_to_head(*objs) def head_children - {% if @type.methods.map(&.name).includes?("head_children") %} + {% if @type.methods.map(&.name).includes?("head_children".id) %} previous_def + Tuple.new({{objs.splat}}) {% else %} super + Tuple.new({{objs.splat}}) @@ -49,7 +49,7 @@ module ToHtml macro body_attributes(*objs) def _body_attributes - {% if @type.methods.map(&.name).includes?("_body_attributes") %} + {% if @type.methods.map(&.name).includes?("_body_attributes".id) %} previous_def + Tuple.new({{objs.splat}}) {% else %} super + Tuple.new({{objs.splat}})