Skip to content

Commit

Permalink
api: new methods
Browse files Browse the repository at this point in the history
  • Loading branch information
indutny committed Aug 15, 2013
1 parent 65f8239 commit de0e1bd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
8 changes: 8 additions & 0 deletions lib/bemhtml/api.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
var bemhtml = require('../bemhtml');

exports.pretranslate = function pretranslate(ast, options) {
return new bemhtml.Compiler(options).pretranslate(ast);
};

exports.translate = function translate(ast, options) {
return new bemhtml.Compiler(options).translate(ast);
};

exports.pregenerate = function pregenerate(code, options) {
return new bemhtml.Compiler(options).pregenerate(code);
};

exports.generate = function generate(code, options) {
return new bemhtml.Compiler(options).generate(code);
};
Expand Down
15 changes: 14 additions & 1 deletion lib/bemhtml/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function Compiler(options) {
};
exports.Compiler = Compiler;

Compiler.prototype.translate = function translate(ast) {
Compiler.prototype.pretranslate = function pretranslate(ast) {
// Ok, I admit it. Translation process is a bit fucked.
var self = this;
var allowed = {
Expand Down Expand Up @@ -72,6 +72,11 @@ Compiler.prototype.translate = function translate(ast) {
i += exprs.length - 1;
}

return ast;
};

Compiler.prototype.translate = function translate(ast) {
ast = this.pretranslate(ast);
return xjst.translate(ast, this.options);
};

Expand Down Expand Up @@ -589,6 +594,14 @@ Compiler.prototype.traceChanges = function traceChanges(changes, expr) {
};
};

Compiler.prototype.pregenerate = function pregenerate(code) {
var ast = esprima.parse(code);

ast = this.pretranslate(ast);

return uglify.AST_Node.from_mozilla_ast(ast).print_to_string();
};

Compiler.prototype.generate = function generate(code) {
if (this.options['no-opt'] || this.options.optimize === false) {
return xjst.generate('\n' +
Expand Down

0 comments on commit de0e1bd

Please sign in to comment.