Skip to content

Commit

Permalink
Allow users to use stylus
Browse files Browse the repository at this point in the history
  • Loading branch information
richtera committed Sep 10, 2012
1 parent 47222f1 commit ef74609
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 23 deletions.
39 changes: 20 additions & 19 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,26 +152,27 @@ function bootApplication(next) {
app.mwHelpers = {};

// Load placeholder, replaced later
if(app.config.get('libraries:stylus:enabled')) {
if ((fs.existsSync || path.existsSync)(themePatch + '/stylus')) {
app.mwHelpers.stylusMiddleware = function (themePath) {
var mw = stylus.middleware({
src: themePath + '/stylus',
dest: themePath + '/public',
debug: false,
compile: function (str, path) { // optional, but recommended
return stylus(str)
.set('filename', path)
.set('warn', app.config.get('libraries:stylus:warn'))
.set('compress', app.config.get('libraries:stylus:compress'));
}
});
mw.tag = 'theme.stylus';
return mw;
};
app.use(app.mwHelpers.stylusMiddleware(''));
}
if(app.config.get('libraries:stylus:enable')) {
console.log('enabling stylus');
app.mwHelpers.stylusMiddleware = function (themePath) {
var mw = stylus.middleware({
src: themePath + '/stylus',
dest: themePath + '/public',
debug: false,
compile: function (str, path) { // optional, but recommended
console.log(str, path);
return stylus(str)
.set('filename', path)
.set('warn', app.config.get('libraries:stylus:warn'))
.set('compress', app.config.get('libraries:stylus:compress'));
}
});
mw.tag = 'theme.stylus';
return mw;
};
app.use(app.mwHelpers.stylusMiddleware(''));
}

// Static
app.mwHelpers.staticMiddleware = function (themePath) {
var mw = express["static"](themePath + '/public', {maxAge: 86400000});
Expand Down
7 changes: 5 additions & 2 deletions lib/calipso.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var calipso = module.exports = {
loadCore(calipso);

function loadCore(calipso) {

fs.readdirSync(__dirname + '/core').forEach(function(library) {
var isLibrary = library.split(".").length > 0 && library.split(".")[1] === 'js',
libName = library.split(".")[0].toLowerCase();
Expand Down Expand Up @@ -288,10 +289,12 @@ function configureTheme(next, overrideTheme) {
var foundMiddleware = false,
mw;
calipso.app.stack.forEach(function(middleware, key) {

if (middleware.handle.tag === 'theme.stylus') {
foundMiddleware = true;
mw = calipso.app.mwHelpers.stylusMiddleware(themeConfig.path);
if ((fs.existsSync || path.existsSync)(themeConfig.path + '/stylus'))
mw = calipso.app.mwHelpers.stylusMiddleware(themeConfig.path);
else
mw = null;
calipso.app.stack[key].handle = mw;
}

Expand Down
30 changes: 28 additions & 2 deletions modules/core/admin/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -734,10 +734,36 @@ function coreConfig(req, res, template, block, next) {
type:'select',
options: calipso.data.adminThemes,
description:'Administration theme [NOT YET IMPLEMENTED]'
},{
},
{
name:'theme:default',
type:'hidden'
}
},
{
label:'Stylus Middleware',
legend:'Stylus Middleware',
type:'fieldset',
fields:[
{
label:'Enable Stylus',
type:'checkbox',
defaultValue:false,
name:'libraries:stylus:enable'
},
{
label:'Show Warnings',
type:'checkbox',
defaultValue:false,
name:'libraries:stylus:warn'
},
{
label:'Compress CSS',
type:'checkbox',
defaultValue:false,
name:'libraries:stylus:compress'
}
]
}
]
},
{
Expand Down

0 comments on commit ef74609

Please sign in to comment.