Skip to content

Instantly share code, notes, and snippets.

@trapped
Last active August 29, 2015 14:26
Show Gist options
  • Save trapped/127cb61d13ffc29005c5 to your computer and use it in GitHub Desktop.
Save trapped/127cb61d13ffc29005c5 to your computer and use it in GitHub Desktop.
<html>
<head>
<title><%= page_title %></title>
<link rel="stylesheet" type="text/css" href="/bootstrap.css">
</head>
<body>
<%= partial_body %>
</body>
</html>
class HeaderView < View
def initialize(response : Http::Response)
@controller = self
@response = response
@partial_body = response.body
@page_title = ""
end
ecr_file "#{__DIR__}/views/header.ecr"
def render
new_body = StringIO.new
to_s(new_body)
new_body.to_s
end
end
class HeaderMiddleware < Middleware::Base
def call(request)
response = @app.call(request)
response.body = HeaderView.new(response).render
response
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment