Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion spec/layout_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -60,8 +78,11 @@ module ToHtml::LayoutSpec
background-color: #EEEEEE;
}
</style>
<script>
console.log("Hello World!");
</script>
</head>
<body id="the-id">
<body id="the-id" style="background-color: red;">
<div>42</div>
</body>
</html>
Expand Down
4 changes: 2 additions & 2 deletions src/layout.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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}})
Expand All @@ -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}})
Expand Down