Skip to content

Instantly share code, notes, and snippets.

@RX14

RX14/output Secret

Last active July 9, 2016 16:17
Show Gist options
  • Save RX14/73fcce2affdf6c8a638a8146e250f43d to your computer and use it in GitHub Desktop.
Save RX14/73fcce2affdf6c8a638a8146e250f43d to your computer and use it in GitHub Desktop.
$ crystal hook.cr
<html>
<chunk of="html">...</chunk>
</html>
require "ecr"
macro content_for(key)
__blocks__[{{key}}] = ->() {
__kilt_io__ = MemoryIO.new
{{ yield }}
__kilt_io__.to_s
}
nil
end
macro yield_content(key)
__blocks__[{{key}}].call
end
__blocks__ = Hash(Symbol, Proc(String)).new
ECR.embed "test.ecr", STDOUT
<% content_for :some_key do %>
<chunk of="html">...</chunk>
<% end %>
<html>
<%= yield_content :some_key %>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment