Skip to content
Browse files

Switching over to anonymous modules. Using trick from @jrburke to get…

… real support for same named modules and templates. No more all.js helper \o/ too!
  • Loading branch information...
1 parent b0d689a commit 7fdeb6d6e4b3809429b57694da4b86d297a6de96 @SlexAxton committed Dec 2, 2011
Showing with 16 additions and 14 deletions.
  1. +1 −1 demo/json2.js
  2. +1 −1 demo/main.js
  3. +1 −1 demo/template/helpers/yeller.js
  4. +1 −1 demo/underscore.js
  5. +12 −10 hbs.js
View
2 demo/json2.js
@@ -355,7 +355,7 @@ var JSON = window.JSON || {};
}
}());
-define('json2',function(){
+define(function(){
return JSON;
});
// otherwise just leave it alone
View
2 demo/main.js
@@ -1,5 +1,5 @@
// Require our template with the handlebars plugin
-define('main',['hbs!template/one'], function (tmplOne) {
+define(['hbs!template/one'], function (tmplOne) {
// Find our container
var container = document.getElementById('demo-app-container');
// Run your template function, and inject it.
View
2 demo/template/helpers/yeller.js
@@ -1,4 +1,4 @@
-define('template/helpers/yeller', ['Handlebars'], function ( Handlebars ){
+define(['Handlebars'], function ( Handlebars ){
function yeller ( context, options ) {
// Assume it's a string for simplicity.
return context + "!!!!!!oneone!!one1";
View
2 demo/underscore.js
@@ -1404,7 +1404,7 @@
}(root));
// Register as a named module with AMD.
-define('underscore', function() {
+define(function() {
return _;
});
}).call({});
View
22 hbs.js
@@ -11,7 +11,7 @@
define: false, process: false, window: false */
define([
//>>excludeStart('excludeAfterBuild', pragmas.excludeAfterBuild)
-'Handlebars', 'underscore', 'Handlebars/i18nprecompile', 'json2', 'template/helpers/all' // need json for older browser support, kill if you don't need it
+'Handlebars', 'underscore', 'Handlebars/i18nprecompile', 'json2'
//>>excludeEnd('excludeAfterBuild')
], function (
//>>excludeStart('excludeAfterBuild', pragmas.excludeAfterBuild)
@@ -126,16 +126,18 @@ define([
write: function (pluginName, name, write) {
if (name in buildMap) {
var text = buildMap[name];
- write(text);
+ write.asModule(pluginName + "!" + name, text);
}
},
version: '1.0.3beta',
load: function (name, parentRequire, load, config) {
//>>excludeStart('excludeAfterBuild', pragmas.excludeAfterBuild)
+
- var partialDeps = [];
+ var compiledName = name + "@hbs",
+ partialDeps = [];
function recursiveNodeSearch( statements, res ) {
_(statements).forEach(function ( statement ) {
@@ -364,17 +366,17 @@ define([
var prec = precompile( text, _.extend( langMap, config.localeMapping ) );
text = "/* START_TEMPLATE */\n" +
- "define('hbs!"+name+"',['hbs','Handlebars'"+depStr+helpDepStr+"], function( hbs, Handlebars ){ \n" +
+ "define(['hbs','Handlebars'"+depStr+helpDepStr+"], function( hbs, Handlebars ){ \n" +
"var t = Handlebars.template(" + prec + ");\n" +
"Handlebars.registerPartial('" + name.replace( /\//g , '_') + "', t);\n" +
debugProperties +
"return t;\n" +
"});\n" +
"/* END_TEMPLATE */\n";
-
+
//Hold on to the transformed text if a build.
if (config.isBuild) {
- buildMap[name] = text;
+ buildMap[compiledName] = text;
}
//IE with conditional comments on cannot handle the
@@ -393,23 +395,23 @@ define([
if ( !config.isBuild ) {
require( deps, function (){
- load.fromText(path, text);
+ load.fromText(compiledName, text);
//Give result to load. Need to wait until the module
//is fully parse, which will happen after this
//execution.
- parentRequire([path], function (value) {
+ parentRequire([compiledName], function (value) {
load(value);
});
});
}
else {
- load.fromText(path, text);
+ load.fromText(compiledName, text);
//Give result to load. Need to wait until the module
//is fully parse, which will happen after this
//execution.
- parentRequire([path], function (value) {
+ parentRequire([compiledName], function (value) {
load(value);
});
}

0 comments on commit 7fdeb6d

Please sign in to comment.
Something went wrong with that request. Please try again.