Skip to content

Commit

Permalink
Updated repo, added search options to CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
cliftonc committed Oct 20, 2011
1 parent 28fc8a6 commit 101b9f5
Show file tree
Hide file tree
Showing 15 changed files with 518 additions and 211 deletions.
3 changes: 2 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,9 @@ function bootApplication(next) {
// Load placeholder, replaced later
app.use(app.mwHelpers.staticMiddleware(''));

// Media paths
// Core static paths
app.use(express["static"](path + '/media', {maxAge: 86400000}));
app.use(express["static"](path + '/lib/client/js', {maxAge: 86400000}));

// connect-form
app.use(form({
Expand Down
11 changes: 5 additions & 6 deletions bin/calipso
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,11 @@ function runLauncher(appLauncher) {

// Check if this is a calipso src folder
if(isLibrary() && !appLauncher.src) {
console.log('\x1b[1mTo run this from the src folder, you need to add an "-s true" parameter, or please run from an empty directory or an installed calipso site\x1b[0m\r\n');
return;
console.log('\r\nWARNING:'.yellow.bold + ' You are running this from a Calipso source folder.'.white.bold);
}

// Check if this is a calipso site
if(!isCalipso() && appLauncher.command != 'site' && !appLauncher.src) {
if(!isCalipso() && appLauncher.command != 'site' && !isLibrary()) {
console.log('\x1b[1mThis is not a Calipso site - you must run:\x1b[0m calipso site SiteName\r\n');
return;
}
Expand All @@ -95,7 +94,7 @@ function runLauncher(appLauncher) {
var modules = require('lib/cli/Modules')
modules.moduleRouter(path,appLauncher.script.params,true,function(err) {
if(err) {
console.log("\r\n" + err.message.red + "\r\n");
console.log("\r\n" + err.message.red.bold + "\r\n");
}
process.exit();
});
Expand All @@ -108,7 +107,7 @@ function runLauncher(appLauncher) {
var themes = require('lib/cli/Themes')
themes.themeRouter(path,appLauncher.script.params,true,function(err) {
if(err) {
console.log("\r\n" + err.message.red + "\r\n");
console.log("\r\n" + err.message.red.bold + "\r\n");
}
process.exit();
});
Expand Down Expand Up @@ -230,7 +229,7 @@ function createApplicationAt(path) {
mkdir(path + '/tmp',self.parallel());
copy(calipsoPath + '/app-cluster.js',path + '/',self.parallel());
copy(calipsoPath + '/app.js',path + '/',self.parallel());
copy(calipsoPath + '/package.json',path + '/',self.parallel());
copy(calipsoPath + '/package.json',path + '/',self.parallel());
copy(calipsoPath + '/logo.js',path + '/',self.parallel());
},
function done() {
Expand Down
46 changes: 21 additions & 25 deletions lib/Helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ exports = module.exports = {
request: function(req, res, calipso){
return req;
},

/**
* Config shortcut
*/
Expand Down Expand Up @@ -156,16 +156,14 @@ exports = module.exports = {
};

},

/**
* Retrieves the params parsed during module routing
*/
getParams: function(req, res, calipso) {

getParams: function(req, res, calipso) {
return function() {
return res.params;
}

},

/**
Expand All @@ -191,32 +189,30 @@ exports = module.exports = {
return urlFrags.join('-');
},

/**
* TODO Include a script in the response.
* Thoughts ... What this will actually do is add the file to a internal list.
* It will check if any of the files are different to the last request, if so,
* it will minify the contents of all the files, write to a temp js file, and reference
* that in the response (e.g. in the header of the template via another helper function).
* If nothing has changed it will just include the link to the previously generated file?
*/
includeScript: function(req, res, calipso){

return function(block) {

// TODO - not yet implemented
};
addScript: function(req, res, calipso) {
return function(options) {
res.client.addScript(options);
}
},

/**
* TODO Retrieve the concatenated / minified js scripts to add to template.
*/
getScripts: function(req, res, calipso){
getScripts: function(req, res, calipso) {
return function(next) {
res.client.listScripts(next);
}
},

return function() {

// TODO - not yet implemented
addStyle: function(req, res, calipso) {
return function(options) {
res.client.addStyle(options);
}
},

};
getStyles: function(req, res, calipso) {
return function(next) {
res.client.listStyles(next);
}
},

/**
Expand Down
44 changes: 22 additions & 22 deletions lib/Theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ module.exports.Theme = function(theme, next) {

// Scan through each layout
var layout = res.layout ? res.layout : "default";

calipso.silly("Using layout " + layout);

if(!theme.config.layouts[layout]) {
layout = "default";
if(!theme.config.layouts[layout]) {
Expand All @@ -120,16 +120,16 @@ module.exports.Theme = function(theme, next) {
return;
}
}


processTheme(req,res,layout,theme,function(err) {

// If something went wrong ...
if(err) {
next(err,null);
return;
}

// Now, process the layout template itself
var themeOptions = createOptions(req,res,res.bufferedOutput);

Expand Down Expand Up @@ -225,7 +225,7 @@ function processSection(req, res, section, sectionPath, layoutConfig, theme, nex
if(typeof sectionCacheFn === "function") {

sectionCacheFn(req,themeOptions,function(err,fnOptions) {

if(err) {
err.xMessage = "Issue executing the theme function for section " + section + ", check " + sectionPath.replace(".","/") + ".js";
localNext(err);
Expand Down Expand Up @@ -287,25 +287,25 @@ function processTheme(req, res, layout, theme, next) {

var copyConfig = theme.config.layouts[layoutConfig.copyFrom].layout;
layoutConfig.sections = layoutConfig.sections || {};

// Copy over any missing sections from default
for(var copySection in copyConfig.sections) {

var sectionExists = layoutConfig.sections && layoutConfig.sections[copySection];
var disable = layoutConfig.sections && layoutConfig.sections[copySection] && layoutConfig.sections[copySection].disable;
var disable = layoutConfig.sections && layoutConfig.sections[copySection] && layoutConfig.sections[copySection].disable;
if(!sectionExists && !disable) {
layoutConfig.sections[copySection] = copyConfig.sections[copySection];
layoutConfig.sections[copySection].layout = "default"; // Flag override as below
}

}

}

// Create a section array
var sections = [];
for(section in layoutConfig.sections) {
disable = layoutConfig.sections[section].disable;
disable = layoutConfig.sections[section].disable;
if(!disable) {
sections.push(section);
}
Expand All @@ -318,11 +318,11 @@ function processTheme(req, res, layout, theme, next) {
// and better ability to debug
function localNext(err) {
totalDone += 1;

if(totalDone == totalCount) {
next();
}

}

for(section in layoutConfig.sections) {
Expand All @@ -333,13 +333,13 @@ function processTheme(req, res, layout, theme, next) {
var sectionPath = layoutOverride ? layoutOverride + "." + section : layout + "." + section;
var cache = layoutConfig.sections[section].cache;
var params = layoutConfig.sections[section].varyParams;
var cacheEnabled = calipso.config.get('performance:cache:enabled');
var cacheEnabled = calipso.config.get('performance:cache:enabled');
var isAdmin = req.session.user && req.session.user.isAdmin;
disable = layoutConfig.sections[section].disable;

disable = layoutConfig.sections[section].disable;

calipso.silly("Processing " + section + " ...");

// Sections are cacheable
if(!disable) {
if(cache && cacheEnabled && !isAdmin) {
Expand Down Expand Up @@ -436,7 +436,7 @@ function cacheTheme(themeConfig, themePath, next) {


// Add the templates
for(var section in layoutConfig.sections) {
for(var section in layoutConfig.sections) {
var template = layoutConfig.sections[section].template;
if(template) {
templates.push({
Expand Down Expand Up @@ -532,7 +532,7 @@ function loadTemplate(templateCache, template, themePath, next) {
path.exists(templatePath,function(exists) {

if(exists) {

fs.readFile(templatePath, 'utf8', function(err,data) {

if(!err) {
Expand All @@ -556,14 +556,14 @@ function loadTemplate(templateCache, template, themePath, next) {
if(exists) {
try {
templateCache[template.name].fn = require(templateFnPath);
} catch(ex) {
} catch(ex) {
next(ex);
return;
}
}
next(null,templateCache);
});
} else {
} else {
next(err);
}
});
Expand Down
4 changes: 2 additions & 2 deletions lib/Utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* General utility methods
*/

exports = module.exports = {
/**
* Basically like getProperty, different return
Expand Down Expand Up @@ -55,4 +55,4 @@ exports = module.exports = {
}
return obj;
}
}
}
Loading

0 comments on commit 101b9f5

Please sign in to comment.