-
-
Save shawnbot/b92f28c5b84aaee2922f1d9d3e20a18c to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env node | |
'use strict'; | |
// note: meta-template is not published on npm yet, so you will | |
// need to clone it and run `npm install && npm link` first! | |
const mt = require('meta-template'); | |
var input = '{% if foo %}{{ foo }}{% else %}no foo!{% endif %}'; | |
var ast = mt.parse.string(input); | |
// or read from stdin with something like: | |
// process.stdin.pipe(require('concat-stream')(buffer => { | |
// ast = mt.parse.buffer(buffer); | |
// })); | |
mt.ast.walk(ast, node => { | |
if (node.type === 'TemplateData') { | |
// you can do whatever you want with node.value here, e.g. | |
// node.value = '(' + node.value + ')'; | |
} | |
}); | |
var out = mt.format.php(ast); | |
console.log(out); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment