Skip to content

Commit

Permalink
ADDEdD - Support for templates anywhere in production mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Lesperance committed Jul 4, 2012
1 parent 9c8cc4c commit fc10075
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 64 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -3,3 +3,5 @@ npm-debug.log
.DS_Store
.project
.settings
.DS_Store
___*
81 changes: 26 additions & 55 deletions lib/client/client.js
Expand Up @@ -138,7 +138,7 @@ function compileViews() {

]

, function(err) { if (err) { throw err; } top_callback(err)}
, function(err) { if (err) { throw err; } top_callback(err); }

);

Expand Down Expand Up @@ -261,8 +261,7 @@ function optimizeDir(dir_path, dst_tmpdir, options_tmpdir, callback) {

, options_file_path = path.join(options_tmpdir.path, options_filename)

, options = {
appDir : dir_path
, options = { appDir : options_tmpdir.path
, baseUrl : './'
, dir : dst_tmpdir.path
, modules : []
Expand Down Expand Up @@ -336,6 +335,10 @@ function optimizeDir(dir_path, dst_tmpdir, options_tmpdir, callback) {
});

}

, function (callback) {
compileViews(dir_path, options_tmpdir.path, options.paths, callback);
}

, async.apply(fs.readdir, dir_path)

Expand All @@ -347,61 +350,29 @@ function optimizeDir(dir_path, dst_tmpdir, options_tmpdir, callback) {

, function iterator(filename, callback) {

var module_path = path.join(dir_path, filename)
, symlink_path = path.join(options_tmpdir.path, filename)
, module_name
var module_name
;

if (filename === REQUIRE_JS_CONFIG_FILE_NAME) {

callback(null);
return;
}

var suffix = '_client.js';

} else if (filename === CLIENT_VIEWS_DIR_NAME) {
if (filename.substr(-suffix.length) === suffix) {
module_name = filename.substr(0, filename.length - 3);

views = true;

async.waterfall(
[
function(callback) { fs.mkdir(symlink_path, '0755', callback); }
, function(callback) { compileViews(module_path, symlink_path, options.paths, callback); }
]
, callback
options.modules.push(
{ name : module_name
, exclude : external_modules
}
);

return;

}

fs.symlink(module_path, symlink_path, function(err) {

if (err) {

callback(err);
return;

}

var suffix = '_client.js';

if (filename.substr(-suffix.length) === suffix) {

module_name = filename.substr(0, filename.length - 3);

options.modules.push(
{ name : module_name
, exclude : external_modules
}
);

}

callback(null);

});

callback(null);
}

, callback
)

Expand Down Expand Up @@ -446,20 +417,20 @@ function optimizeDir(dir_path, dst_tmpdir, options_tmpdir, callback) {
*/
function watchAndOptimize(path, dst_tmpdir, options_tmpdir, callback) {

var tree_event_emitter = asyncFs.watchTree(path);
;
// var tree_event_emitter = asyncFs.watchTree(path);
// ;

tree_event_emitter.on('change', function() {
// tree_event_emitter.on('change', function() {

process.stdout.write('\n-- Change in tree detected');
// process.stdout.write('\n-- Change in tree detected');

optimizeDir(path, dst_tmpdir, options_tmpdir, function(err) {
// optimizeDir(path, dst_tmpdir, options_tmpdir, function(err) {

if (err) { throw err; }
// if (err) { throw err; }

});
// });

});
// });

optimizeDir(path, dst_tmpdir, options_tmpdir, function(err) {

Expand Down
16 changes: 8 additions & 8 deletions lib/controller.js
Expand Up @@ -32,14 +32,6 @@ var rocket_tmpl = {};
, require_configuration = global.require_configuration || {}
;

header.push("<script>");
header.push("var _b = " + JSON.stringify(args) + "; ");
header.push("var require = " + JSON.stringify(require_configuration) + ";");
header.push("require.deps || (require.deps = []);");
header.push("require.deps.push('" + controller_name + "_client" + "')");
header.push("require.callback = " + "function() { require(['" + controller_name + "_client" + "'], function(m) { m && m.init && m.init.apply(m, _b); })}");
header.push("</script>")

return header.join('\n');

};
Expand All @@ -50,9 +42,17 @@ var rocket_tmpl = {};
, controller_name = args.shift().replace(/[.,-;\s]+/g, '_')

, footer = []

, require_configuration = global.require_configuration || {}
;

footer.push("<script>");
footer.push("var _b = " + JSON.stringify(args) + "; ");
footer.push("var require = " + JSON.stringify(require_configuration) + ";");
footer.push("require.deps || (require.deps = []);");
footer.push("require.deps.push('" + controller_name + "_client" + "')");
footer.push("require.callback = " + "function() { require(['" + controller_name + "_client" + "'], function(m) { m && m.init && m.init.apply(m, _b); })}");

footer.push("document.write('<script src=\"/js/rocket/vendors/require.min.js\"><\\/script>')");
footer.push("</script>");

Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -2,7 +2,7 @@
"name": "rocket"
, "description": "The rapid development framework for node.js"
, "keywords": ["mvc", "model view controller", "comet","rapid development", "Rocket", "framework"]
, "version": "0.4.1"
, "version": "0.4.2"
, "homepage": "http://wavo.me"
, "repository":
{ "type" : "git"
Expand Down

0 comments on commit fc10075

Please sign in to comment.