Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
57 lines (45 sloc) 1.65 KB
(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)))