-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.sibilant
56 lines (45 loc) · 1.65 KB
/
plugin.sibilant
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
(defvar sibilant (require 'sibilant)
path (require 'path)
async (require 'async)
fs (require 'fs))
(defun include (file)
(macros.include (path.join sibilant.dir file)))
(defmacro extend (dest src)
(concat
"for(var prop in "
(translate src)
" ){\n "
"var desc;"
(indent (concat "if(desc = Object.getOwnPropertyDescriptor(" (translate src) ", prop)){")
(indent (concat "Object.defineProperty(" (translate dest) ", prop, desc);"))
(concat "} else if(" (translate src) ".hasOwnProperty(prop)){")
(indent (concat (translate dest)
"[prop] = " (translate src) "[prop];"))
"}")
"}"))
(defun init-plugin (context)
(defvar plugin {})
(defun plugin.init (context filename base text)
(defvar content {})
(extend content context.ContentPlugin.prototype)
(setf
content.*filename filename
content.*base base
content.*text text)
(defun content.get-filename ()
(content.*filename.replace (regex 'sibilant) 'js))
(defun content.render (locals contents templates fn)
(console.log "in render: " content.*filename)
(defvar js (sibilant.translate-file
(path.join content.*base content.*filename)))
(fn null (new (Buffer js))))
content)
(defun plugin.from-file (filename base fn)
(fs.read-file (path.join base filename) (lambda (error buffer)
(if error
(fn error)
(fn null (plugin.init context filename base (buffer.to-string)))))))
plugin)
(set module 'exports (lambda (wintersmith fn)
(wintersmith.register-content-plugin 'sibilant', "**/*.sibilant", (init-plugin wintersmith))
(fn)))