Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Syntax highlighting plugin for mustache.rb

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README.md
Octocat-spinner-32 Rakefile
Octocat-spinner-32 example.rb
README.md

Mustache Syntax Highlighter

A plugin for mustache.rb that lets you syntax highlight blocks of code using sections.

Essentially a demo of Mustache's "Higher Order Sections" functionality.

For example, this template:

I wrote some great code!

{{# highlight_ruby}}
def hello
  puts "Hi world!"
end
{{/ highlight_ruby}}

Sweet. It works.

Will produce this text:

I wrote some great code!

<div class="highlight"><pre><span class="k">def</span> <span class="nf">hello</span>
  <span class="nb">puts</span> <span class="s2">&quot;Hi world!&quot;</span>
<span class="k">end</span>
</pre></div>

Sweet. It works.

Just include the Pygments css file and you're ready to roll.

If you want to use this in a Mustache view you can include it in your subclass:

class BlogPost < Mustache
  include Mustache::Plugins::SyntaxHighlighter

  def name
    "Bobs"
  end
end

The code you want to highlight will be rendered before being passed to the highlighter.

So this:

{{# highlight_ruby}}
def hello
  puts "Hi {{name}}!"
end
{{/ highlight_ruby}}

Becomes this:

<div class="highlight"><pre><span class="k">def</span> <span class="nf">hello</span>
  <span class="nb">puts</span> <span class="s2">&quot;Hi Bobs!&quot;</span>
<span class="k">end</span>
</pre></div>

Note the Hi Bobs!

Available Lexers

This is currently only a demo, so we've hardcoded a small number of lexers:

  • ruby
  • js
  • python
  • scheme

Use {{# highlight_scheme}} code {{/ highlight_scheme}}, for example, to activate one of the lexers.

To get a complete list run rake lexers in the root of this project.

Dependencies

  • Pygments
  • Mustache 0.11.0
Something went wrong with that request. Please try again.