Skip to content

Instantly share code, notes, and snippets.

@itsbth
Created February 2, 2012 21:11
Show Gist options
  • Select an option

  • Save itsbth/1725803 to your computer and use it in GitHub Desktop.

Select an option

Save itsbth/1725803 to your computer and use it in GitHub Desktop.
Uploaded by UploadToGist for Sublime Text 2
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