Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

101 lines (65 sloc) 2.21 KB

Sinatra RDiscount Extension for Sinatra v0.10.1

The sinatra-rdiscount extension provides rdiscount helper method for rendering RDiscount templates.

To install it, run:

sudo gem install sinatra-rdiscount -v0.10.1

To test it, create a simple Sinatra application:

# app.rb
require 'rubygems'
require 'sinatra'

require 'sinatra/rdiscount'

get "/" do
  rdiscount "# Hello RDiscount"

and run it with:

ruby app.rb

The result could be seen at http://localhost:4567.

Another example could be find in the examples directory. Run it with:

rackup -p 4567

Template Languages (update to The Sinatra Book)

One important thing to remember is that you always have to reference templates and layouts with symbols, even if they’re in a subdirectory, for example :'subdir/template'. Rendering methods will render any strings passed to them directly.

RDiscount Templates

The following gems are required to render RDiscount templates: rdiscount, erubis.

This helper method:

get '/' do
  rdiscount :index

renders template ./views/index.rdiscount.

If a layout named layout.rdiscount exists, it will be used each time a template is rendered.

You can disable layouts by passing :layout => false to rdiscount helper. For example

get '/' do
  rdiscount :index, :layout => false

You can set a different layout from the default one with:

get '/' do
  rdiscount :index, :layout => :application

This renders ./views/index.rdiscount template within ./views/application.rdiscount layout.

Important Info

Layouts are RHTML — not RDiscount — files. Layout example:

<!DOCTYPE html>
    <title><%= @title || "My Sinatra App" %></title>
    <%= yield %>

Templates are Markdown files with ERB insertions delimited by '{% %}'. Template example:

# Hello {%= @name %}

Such a change in embedded code pattern was necessary, to avoid messing with RDiscount engine, which converts bare &lt; to &amp;lt;. Also I think that there is no way for RDiscount renderer to generate that line:

<!DOCTYPE html>
Jump to Line
Something went wrong with that request. Please try again.