-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.coffee
More file actions
29 lines (26 loc) · 768 Bytes
/
index.coffee
File metadata and controls
29 lines (26 loc) · 768 Bytes
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
async = require 'async'
jsdom = require 'jsdom'
jQuery = require 'jquery'
module.exports = class htmlmagick
$:null
magicks:null
add:(magick)->
@remove magick
@magicks.push magick
return
remove:(magick)->
@magicks ?= []
while ~(index = @magicks.indexOf magick) then @magicks.splice index,1
return
exec:(html,callback)->
document = jsdom.jsdom html
window = document.parentWindow
jQuery window
doMagick = (html,magick,next)->
magick.call window,html,(error,html)->
if html instanceof String or html is ''
next error,html
else
next error,[document.doctype.toString(),document.documentElement.outerHTML].join '\n'
async.reduce @magicks,html,doMagick,callback
return