Created
February 2, 2012 21:11
-
-
Save itsbth/1725803 to your computer and use it in GitHub Desktop.
Uploaded by UploadToGist for Sublime Text 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fs = require 'fs' | |
| page = require('webpage').create() | |
| HS = '"""' | |
| url = phantom.args[0] | |
| page.open url, (status) -> | |
| try | |
| result = page.evaluate -> | |
| templates = {} | |
| for template in document.querySelectorAll('div[data-template]') | |
| text = template.innerHTML.replace /ZZ([a-z]+)ZZ/g, (_, name) -> | |
| '#{' + name + '}' | |
| templates[template.dataset.template] = | |
| args: JSON.parse(template.dataset.args), | |
| text: text | |
| templates | |
| out = 'window.TPL ||= {}\n' | |
| for name, tpl of result | |
| out += "TPL.#{name} = (#{tpl.args.join ', '}) ->\n #{HS}#{tpl.text.replace '\n', '\n '}#{HS}\n" | |
| fs.write phantom.args[1], out, 'w' | |
| phantom.exit() | |
| catch e | |
| console.log e | |
| phantom.exit(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment