Created
March 13, 2012 02:24
-
-
Save audionerd/2026206 to your computer and use it in GitHub Desktop.
Mustache support for Middleman
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'tilt-mustache' | |
# Mustache Renderer | |
module Middleman::Renderers::Mustache | |
class << self | |
def registered(app) | |
# Mustache is not included in the default gems, | |
# but we'll support it if available. | |
begin | |
# Require Gem | |
require "mustache" | |
# After config, setup mustache partial paths | |
app.after_configuration do | |
Mustache.template_path = source_dir | |
# Convert data object into a hash for mustache | |
provides_metadata %r{\.mustache$} do |path| | |
{ :locals => { :data => data.to_h } } | |
end | |
end | |
rescue LoadError | |
end | |
end | |
alias :included :registered | |
end | |
end | |
Middleman::Base.register Middleman::Renderers::Mustache |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why is there the explicit call to register? With the current build, I get an error saying Base is not in scope.
Also, am I correct in thinking this passes the data through only for files that end in
.mustache
(e.g. not.ms
)? I didn't see whereprovides_metadata
was located.