Mustdown

Mustdown provides helpers to ease the use markdown, mustache and both of them.

Installation

Add the gem to your Gemfile :

gem 'mustdown'

Then call bundle install to install it for your application.

Provided helpers

markdown

This will render the given text through Markdown.

<%= markdown "# Hello World" %>

Output:

<h1>Hello World</h1>

mustache

The mustache helper renders a mustache template with the given binding object.

<%= mustache "Hello {{name}}", name: 'John' %>

Output:

Hello John

mustdown

This helper is more complex since it provides the two previous helpers in one.

<%= mustdown "# {{title}}", title: 'Hello World' %>

Output:

<h1>Hello World</h1>

Mustdown configuration

You can generate a default initializer by calling:

bundle exec rails generate mustdown:install

The markdown configuration is provided by Redcarpet. All Redcarpet options are available.

Overriding the configuration from the view

The markdown and mustdown helpers accept additional parameters for markdown configuration. The settings you pass are merged with the default ones and take precedence.

<%= markdown "**Hello World**", { autolink: false }, { hard_wrap: true} %>

Using with I18n

A very useful technique is to use templates from I18n.

Let's take an example. Given the following models in your app:

Company(name) -> Project(title,url)

Define the following in config/locales/en.yml:

en:
  companies:
    show:
      text: |
        # {{name}}

        {{name}} is a great company ! Here are some of their projects:

        {{#projects}}
        * [{{title}}]({{url}})
        {{/projects}}

Now we can use it in our show template (located in app/views/companies/show.html.erb):

<%= mustdown t('.text'), @company %>

Output:

<h1>Github</h1>

<p>Github is a great company ! Here are some of their projects:</p>

<ul>
  <li><a href="https://github.com/github/hubot">Hubot</a></li>
  <li><a href="https://github.com/github/gollum">Gollum</a></li>
</ul>