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.
我想为Middleman添加.jade支持。我不需要使用任何jade的动态功能,但我想在midman中编译我的应用程序,而不是使用我自己的乱码编译脚本。
What is the simplest way to add a new file type to Middleman?
向Middleman添加新文件类型的最简单方法是什么?
1 个解决方案
#1
3
Middleman's templating is built on Tilt, so using the tilt-jade gem it should be pretty straightforward.
Middleman的模板建立在Tilt之上,因此使用倾斜玉石的宝石应该非常简单。
Here's some code for adding Mustache templates to Middleman:
以下是将一些Mustache模板添加到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.
应该很容易适应与Jade一起工作。
#1
3
Middleman's templating is built on Tilt, so using the tilt-jade gem it should be pretty straightforward.
Middleman的模板建立在Tilt之上,因此使用倾斜玉石的宝石应该非常简单。
Here's some code for adding Mustache templates to Middleman:
以下是将一些Mustache模板添加到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.
应该很容易适应与Jade一起工作。