Created
July 13, 2015 21:51
-
-
Save djanowski/a9683649b2f3c77b5cf4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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