-
Notifications
You must be signed in to change notification settings - Fork 6
/
plugin.coffee
32 lines (25 loc) · 969 Bytes
/
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
CoffeeScript = require('coffee-script')
path = require 'path'
async = require 'async'
fs = require 'fs'
module.exports = (env, callback) ->
class CoffeePlugin extends env.ContentPlugin
constructor: (@_filepath, @_text) ->
getFilename: ->
@_filepath.relative.replace /(coffee|litcoffee|coffee\.md)$/, 'js'
getView: ->
return (env, locals, contents, templates, callback) ->
try
js = CoffeeScript.compile @_text,
literate: CoffeeScript.helpers.isLiterate @_filepath.full
callback null, new Buffer js
catch error
callback error
CoffeePlugin.fromFile = (filepath, callback) ->
fs.readFile filepath.full, (error, buffer) ->
if error
callback error
else
callback null, new CoffeePlugin filepath, buffer.toString()
env.registerContentPlugin 'coffee', '**/*.*(coffee|litcoffee|coffee.md)', CoffeePlugin
callback()