Skip to content

Commit

Permalink
added in stylus support, bumped version
Browse files Browse the repository at this point in the history
  • Loading branch information
tbranyen committed Jul 18, 2012
1 parent 6b8d71d commit 26c71e4
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 19 deletions.
3 changes: 3 additions & 0 deletions grunt.js
Expand Up @@ -5,13 +5,16 @@ module.exports = function(grunt) {
test: {
files: ["test/**/*.js"]
},

lint: {
files: ["grunt.js", "tasks/**/*.js", "test/**/*.js"]
},

watch: {
files: "<config:lint.files>",
tasks: "default"
},

jshint: {
options: {
curly: true,
Expand Down
5 changes: 2 additions & 3 deletions package.json
@@ -1,7 +1,7 @@
{
"name": "bbb",
"description": "Backbone Boilerplate Build Tool",
"version": "0.1.6",
"version": "0.1.7",
"homepage": "https://github.com/tbranyen/bbb",
"author": {
"name": "Tim Branyen (@tbranyen)",
Expand All @@ -23,8 +23,7 @@
"requirejs": "2.0.2",
"express": "2.5.9",

"cdir": "0.1.2",
"phantom": "0.3.5"
"stylus": "0.28.2"
},
"devDependencies": {
"grunt": "~0.3.10"
Expand Down
2 changes: 1 addition & 1 deletion tasks/init
Submodule init updated 1 files
+1 −1 bbb/root
71 changes: 56 additions & 15 deletions tasks/server.js
Expand Up @@ -59,27 +59,68 @@ module.exports = function(grunt) {
});

grunt.registerHelper("server", function(options) {
// Require libraries
// Require libraries.
var fs = require("fs");
var path = require("path");
var stylus = require("stylus");
var express = require("express");
var site = express.createServer();

// Map static folders
Object.keys(options.folders).sort().reverse().forEach(function(key) {
site.use("/" + key, function(req, res, next){
express.static.send(req, res, next, {
root: options.folders[key],
path: req.url,
getOnly: true,

callback: function(err) {
res.send(404);
}
// If the server is already available use it.
if (options.server) {
site = options.server;
}

// Process stylus stylesheets.
site.get("/assets/css/stylus!*", function(req, res) {
var url = req.url.split("!")[1];
var file = path.join("assets/css", url);

fs.readFile(file, function(err, contents) {
var processer = stylus(contents.toString());

processer.set("paths", ["assets/css/"]);
processer.render(function(err, css) {
res.header("Content-type", "text/css");
res.send(css);
});
});
});

// Map static files
// Map static folders.
Object.keys(options.folders).sort().reverse().forEach(function(key) {
site.get("/" + key + "*", function(req, res, next) {
// Find filename.
var filename = req.url.slice(key.length + 1);

res.sendfile(path.join(options.folders[key] + filename));

//fs.createReadStream(filename).pipe(res);
// Send the static file.
//express.static.send(req, res, next, {
// root: options.folders[key],
// path: req.url,
// getOnly: true,

// callback: function(err) {
// res.send(404);
// }
//});
});
//site.use("/" + key, function(req, res, next){
// express.static.send(req, res, next, {
// root: options.folders[key],
// path: req.url,
// getOnly: true,

// callback: function(err) {
// res.send(404);
// }
// });
//});
});

// Map static files.
if (_.isObject(options.files)) {
Object.keys(options.files).sort().reverse().forEach(function(key) {
site.get("/" + key, function(req, res) {
Expand All @@ -88,9 +129,9 @@ module.exports = function(grunt) {
});
}

// Serve favicon.ico
// Serve favicon.ico.
site.use(express.favicon(options.favicon));

// Ensure all routes go home, client side app..
site.get("*", function(req, res) {
fs.createReadStream(options.index).pipe(res);
Expand Down

0 comments on commit 26c71e4

Please sign in to comment.