0

I'd like to add .jade support to Middleman. I don't need to use any of jade's dynamic features, but I'd like to compile my app in middleman rather than with my own messy compile script.

What is the simplest way to add a new file type to Middleman?

doubledriscoll
  • 1,179
  • 3
  • 12
  • 21

1 Answers1

3

Middleman's templating is built on Tilt, so using the tilt-jade gem it should be pretty straightforward.

Here's some code for adding Mustache templates to 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

that should be quite easy to adapt to work with Jade.

Alex Peattie
  • 26,633
  • 5
  • 50
  • 52