Created
August 3, 2012 02:54
-
-
Save ryanbriones/3243872 to your computer and use it in GitHub Desktop.
Plain HTML "templates", with ERB layout, from Sinatra
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
class MySinatraApplication < Sinatra::Base | |
get "/some-mockup-path" do | |
html :somemockup | |
end | |
helpers do | |
def html(template, options = {}, locals = {}) | |
render :html, template, options, locals | |
end | |
def compile_template(engine, data, options, views) | |
return super(:erb, data, options, views) if data == :layout | |
case engine | |
when :html | |
template = Object.new | |
template.instance_variable_set :@data, data | |
def template.render(scope, locals = {}) | |
view_path = File.join(settings.views, "#{@data}.html") | |
File.read(view_path) | |
end | |
template | |
else | |
super | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If this ends up being good for my workflow, I'll either write a Tilt/Sinatra extension to do this right, or submit patches