Skip to content

Instantly share code, notes, and snippets.

@audionerd
Created March 13, 2012 02:24
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save audionerd/2026206 to your computer and use it in GitHub Desktop.
Save audionerd/2026206 to your computer and use it in GitHub Desktop.
Mustache support for Middleman
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
@jamiefolson
Copy link

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 where provides_metadata was located.

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