forked from docpad/docpad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jade.plugin.coffee
40 lines (36 loc) · 982 Bytes
/
jade.plugin.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# Requires
DocpadPlugin = require "#{__dirname}/../../plugin.coffee"
jade = null
html2jade = null
# Define Plugin
class JadePlugin extends DocpadPlugin
# Plugin name
name: 'jade'
# Plugin priority
priority: 725
# Render some content
render: ({inExtension,outExtension,templateData,file}, next) ->
try
if inExtension is 'jade'
jade = require 'jade' unless jade
file.content = jade.compile(file.content, {
filename: file.fullPath
})(templateData)
next()
else if outExtension is 'jade' and inExtension is 'html'
try
unless html2jade
html2jade = require 'html2jade'
catch err
unless html2jade
html2jade = require path.resolve(__dirname, 'node_modules', 'html2jade', 'lib', 'html2jade.coffee')
html2jade.convertHtml file.content, {}, (err,result) ->
return next(err) if err
file.content = result
next()
else
next()
catch err
return next(err)
# Export Plugin
module.exports = JadePlugin