Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Template Rendering Methods & Layout Engines #110

krainboltgreene opened this Issue Oct 29, 2010 · 7 comments


None yet
3 participants

See: http://github.com/sinatra/sinatra/blob/master/lib/sinatra/base.rb#L463

The rendering engine choice for layouts is forced, and there is zero option to change it at any point. Examples:

get '/' do
    haml :index

The above renders the index.haml file with the HAML rendering engine. It does the same for the layout. With HAML it makes sense. Much like sass/scss Markdown engines aren't meant to have "layouts". They're designed for formatting documents (in emails, for instance), not building web pages.

For this reason I believe markdown & textile template rendering methods should default to layout: false, like sass/scss.

In addition to this I believe there should be a way to set the layout of the entire page. Example:

get '/' do
    layout :haml
    haml :index

rkh commented Oct 30, 2010

Yeah, this has been proposed already, but the discussion (in which I didn't take part at that time) is lost.

Sass and friends don't use layouts. However, this is not true for Markdown/Textile at the moment (usually not an issue, as you don't have a layout specified).

The change, however, would involve modifying Sinatra's API:

layout { "= yield" } # no info what engine to use

get '/' do
  layout :haml # what to do now?
  markdown :index

I don't think this is impossible to solve, but it has to be done carefully.
Maybe somewhat like this

# use the same engine for layout and for markup
haml :foo, :layout => :bar

# use a different engine
markdown :foo, :layout => :"bar.haml"

This is the first time I've been able to actively contribute to a FOSS project, so I'm a bit excited but here's my suggestion:

get '/' do
    markdown :foo, :layout_engine => :haml

I'll clone the source and test some ideas for modification, but I don't think it'll be too big a change.

Crap, looks like I accidentally closed this?


rkh commented Oct 30, 2010

No worries, I reopened it.
Yeah, I like the layout_engine idea.


rkh commented Oct 30, 2010

What makes this even better, you could do things like this:

set :markdown, :layout_engine => :haml
get '/' do
  markdown :foo

I throw my vote in for this. I am migrating a project that uses erb to haml, having the ability to separate the layout engine from the template engine will allow us to mix and match.


rkh commented Dec 14, 2010

Add layout_engine option to #render.

This will render an erb file with a haml layout:

get('/') { erb :index, :layout_engine => :haml }

Whereas this will cause all markdown templates to be rendered with an erb
layout (unless, of course, :layout_engine is set explicitly):

set :markdown, :layout_engine => :erb

Closed by 29e45e9.

@7stud 7stud pushed a commit to 7stud/sinatra that referenced this issue Aug 27, 2014

@rkh rkh Merge pull request #110 from digitaldeployment/master
Add Digital Deployment to Sinatra in The Wild page

This issue was closed.

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