Skip to content

Instantly share code, notes, and snippets.

@taijiweb
Created March 11, 2015 12:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taijiweb/8a4441e1f440dc58e015 to your computer and use it in GitHub Desktop.
Save taijiweb/8a4441e1f440dc58e015 to your computer and use it in GitHub Desktop.
a coffee file to convert template to js by using peasy.coffee
es = require('event-stream')
gutil = require('gulp-util')
# compile transform function from templates by using modules/transform/transformparser
# template is in /modules/transform/textualizer/someTemplateTogenerateJavascript
generateFromTemplateFile = (file) ->
{TemplateParser, FieldTemplateListParser} = require './src/modules/transform/transformparser'
filepath = file.history[0]
#console.log JSON.stringify filepath
filename = filepath.slice(filepath.lastIndexOf('\\')+1, filepath.length-4)
#console.log filename
#console.log JSON.stringify file.contents
moduleHead = """exports.makeActions = function(t){ return """
parser = new FieldTemplateListParser
dict = parser.parse(file.contents.toString('utf8'))
moduleTail = """;}; """
#console.log dict
moduleHead+dict+moduleTail
jsTemplatePlugin = (data) ->
es.map (file, cb) ->
file.contents = new Buffer generateFromTemplateFile(file)
cb(null, file)
module.exports = jsTemplatePlugin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment