Skip to content

Instantly share code, notes, and snippets.

@ryanbriones
Created August 3, 2012 02:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanbriones/3243872 to your computer and use it in GitHub Desktop.
Save ryanbriones/3243872 to your computer and use it in GitHub Desktop.
Plain HTML "templates", with ERB layout, from Sinatra
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
@ryanbriones
Copy link
Author

If this ends up being good for my workflow, I'll either write a Tilt/Sinatra extension to do this right, or submit patches

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment