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
10 changes: 5 additions & 5 deletions spec/layout_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -73,14 +73,14 @@ module ToHtml::LayoutSpec
<head>
<title>Surprise!</title>
<meta charset="utf-8" name="viewport" content="width=device-width, initial-scale=1.0">
<script>
console.log("Hello World!");
</script>
<style>
body {
background-color: #EEEEEE;
}
</style>
<script>
console.log("Hello World!");
</script>
</head>
<body id="the-id" style="background-color: red;">
<div>42</div>
Expand Down
12 changes: 11 additions & 1 deletion src/layout.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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}})
Expand All @@ -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
Expand Down