Skip to content

Instantly share code, notes, and snippets.

@djanowski
Created July 13, 2015 21:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djanowski/a9683649b2f3c77b5cf4 to your computer and use it in GitHub Desktop.
Save djanowski/a9683649b2f3c77b5cf4 to your computer and use it in GitHub Desktop.
require "hmote"
class Page
include HMote::Helpers
attr_accessor :path
attr_accessor :layout
attr_accessor :params
def initialize(path, layout = nil)
@path = path
@layout = layout
@params = {}
end
def render(options = {})
content = hmote(@path, @params.merge(options))
if @layout
return @layout.render(@params.merge(content: content))
else
return content
end
end
def partial(relative_path, params = {})
path = File.expand_path(relative_path, File.dirname(@path))
return hmote(path + ".mote", @params.merge(params))
end
alias to_s render
end
module Syro::Render
def page(path)
template(path, "layout")
end
def template(path, layout = nil)
TEMPLATES[[path, layout]] ||= begin
dir = File.join("views", self.class.prefix)
Page.new("#{dir}/#{path}.mote", (template(layout) if layout))
end
end
def render(page)
res.headers[Rack::CONTENT_TYPE] = HTML
res.write(page)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment