Expose current Handlebars namespace fields

This commit is contained in:
kpdecker
2013-10-01 21:41:09 -05:00
parent e676e43dc5
commit fd09ff0e1b
5 changed files with 44 additions and 33 deletions
+2 -2
View File
@@ -4,7 +4,7 @@ module.exports = {
files: [{
expand: true,
cwd: 'lib/',
src: '**/*.js',
src: '**/!(index).js',
dest: 'tmp'
}]
},
@@ -14,7 +14,7 @@ module.exports = {
files: [{
expand: true,
cwd: 'lib/',
src: '**/*.js',
src: '**/!(index).js',
dest: 'dist/cjs/'
}]
},
+21 -29
View File
@@ -1,38 +1,47 @@
import { HandlebarsEnvironment, createFrame, logger, log } from "./handlebars/base";
module base from "./handlebars/base";
// Each of these augment the Handlebars object. No need to setup here.
// (This is done to easily share code between commonjs and browse envs)
import SafeString from "./handlebars/safe-string";
import Exception from "./handlebars/exception";
import { extend, escapeExpression, isEmpty } from "./handlebars/utils";
import { compile, precompile } from "./handlebars/compiler/compiler";
import { template } from "./handlebars/runtime";
module Utils from "./handlebars/utils";
module runtime from "./handlebars/runtime";
// Compiler imports
module AST from "./handlebars/compiler/ast";
import { parser as Parser, parse } from "./handlebars/compiler/base";
import { Compiler, compile, precompile } from "./handlebars/compiler/compiler";
import JavaScriptCompiler from "./handlebars/compiler/javascript-compiler";
// For compatibility and usage outside of module systems, make the Handlebars object a namespace
var create = function() {
var hb = {},
env = new HandlebarsEnvironment();
env = new base.HandlebarsEnvironment();
// support new environments in global namespace mode
hb.HandlebarsEnvironment = HandlebarsEnvironment;
hb.registerHelper = env.registerHelper.bind(env);
hb.registerPartial = env.registerPartial.bind(env);
Utils.extend(hb, base);
hb.SafeString = SafeString;
hb.Exception = Exception;
hb.Utils = { extend: extend, escapeExpression: escapeExpression, isEmpty: isEmpty };
hb.Utils = Utils;
hb.VM = runtime;
hb.template = runtime.template;
hb.compile = function(input, options) {
options = options || {};
options.env = options.env || env;
return compile(input, options);
};
hb.precompile = precompile;
hb.template = template;
hb.createFrame = createFrame;
hb.log = log;
hb.logger = logger;
hb.AST = AST;
hb.Compiler = Compiler;
hb.JavaScriptCompiler = JavaScriptCompiler;
hb.Parser = Parser;
hb.parse = parse;
return hb;
};
@@ -41,20 +50,3 @@ var Handlebars = create();
Handlebars.create = create;
export default Handlebars;
// Publish a Node.js require() handler for .handlebars and .hbs files
if (typeof require !== 'undefined' && require.extensions) {
var extension = function(module, filename) {
var fs = require("fs");
var templateString = fs.readFileSync(filename, "utf8");
module.exports = Handlebars.compile(templateString);
};
require.extensions[".handlebars"] = extension;
require.extensions[".hbs"] = extension;
}
// USAGE:
// var handlebars = require('handlebars');
// var singleton = handlebars.Handlebars,
// local = handlebars.create();
+1 -1
View File
@@ -1,7 +1,7 @@
import parser from "./parser";
module AST from "./ast";
export var parser = parser;
export { parser };
export function parse(input) {
// Just return if an already-compile AST was passed in.
+19
View File
@@ -0,0 +1,19 @@
// USAGE:
// var handlebars = require('handlebars');
// var local = handlebars.create();
var Handlebars = require('../dist/cjs/handlebars').default;
module.exports = Handlebars;
// Publish a Node.js require() handler for .handlebars and .hbs files
if (typeof require !== 'undefined' && require.extensions) {
var extension = function(module, filename) {
var fs = require("fs");
var templateString = fs.readFileSync(filename, "utf8");
module.exports = Handlebars.compile(templateString);
};
require.extensions[".handlebars"] = extension;
require.extensions[".hbs"] = extension;
}
+1 -1
View File
@@ -1,6 +1,6 @@
require('./common');
global.Handlebars = require('../../dist/cjs/handlebars');
global.Handlebars = require('../../lib');
global.CompilerContext = {
compile: function(template, options, env) {