lib/content_handler.js
function(callback) {
		var self = this;
		var sections = [Path.join("/")];
		var paths_to_traverse = [];

		var should_exclude = function(entry) {
			return entry[0] === "." || entry[0] === "_" || entry === "shared";
		};

		var traverse_path = function() {
			var current_path = paths_to_traverse.shift() || "";
			Fs.readdir(Path.join(self.contentDir, current_path), function(err, entries) {
				if (err) {
					throw err;
				}

				var run_callbacks = function() {
					if (entries.length) {
						return next_entry();
					} else if (paths_to_traverse.length) {
						return traverse_path();
					} else {
						return callback(sections);
					}
				};

				var next_entry = function() {
					var current_entry = entries.shift();
					if (should_exclude(current_entry)) {
						return run_callbacks();
					}

					var current_entry_path = Path.join(current_path, current_entry);
					Fs.stat(Path.join(self.contentDir, current_entry_path), function(err, stat) {
						if (err) {
							return run_callbacks();
						}

						if (stat.isDirectory()) {
							sections.push(Path.join("/",current_entry_path));
							paths_to_traverse.push(current_entry_path);
						}

						return run_callbacks();
					});
				};

				return run_callbacks();
			});
		};
		return traverse_path();
	}
function(callback) {
		var self = this;
		var sections = [Path.join("/")];
		var paths_to_traverse = [];

		var should_exclude = function(entry) {
			return entry[0] === "." || entry[0] === "_" || entry === "shared";
		};

		var traverse_path = function() {
			var current_path = paths_to_traverse.shift() || "";
			Fs.readdir(Path.join(self.contentDir, current_path), function(err, entries) {
				if (err) {
					throw err;
				}

				var run_callbacks = function() {
					if (entries.length) {
						return next_entry();
					} else if (paths_to_traverse.length) {
						return traverse_path();
					} else {
						return callback(sections);
					}
				};

				var next_entry = function() {
					var current_entry = entries.shift();
					if (should_exclude(current_entry)) {
						return run_callbacks();
					}

					var current_entry_path = Path.join(current_path, current_entry);
					Fs.stat(Path.join(self.contentDir, current_entry_path), function(err, stat) {
						if (err) {
							return run_callbacks();
						}

						if (stat.isDirectory()) {
							sections.push(Path.join("/",current_entry_path));
							paths_to_traverse.push(current_entry_path);
						}

						return run_callbacks();
					});
				};

				return run_callbacks();
			});
		};
		return traverse_path();
	}
function ( callback ) { var self = this ; var sections = [ Path . join ( "/" ) ] ; var paths_to_traverse = [ ] ; var should_exclude = function ( entry ) { return entry [ 0 ] === "." || entry [ 0 ] === "_" || entry === "shared" ; } ; var traverse_path = function ( ) { var current_path = paths_to_traverse . shift ( ) || "" ; Fs . readdir ( Path . join ( self . contentDir , current_path ) , function ( err , entries ) { if ( err ) { throw err ; } var run_callbacks = function ( ) { if ( entries . length ) { return next_entry ( ) ; } else if ( paths_to_traverse . length ) { return traverse_path ( ) ; } else { return callback ( sections ) ; } } ; var next_entry = function ( ) { var current_entry = entries . shift ( ) ; if ( should_exclude ( current_entry ) ) { return run_callbacks ( ) ; } var current_entry_path = Path . join ( current_path , current_entry ) ; Fs . stat ( Path . join ( self . contentDir , current_entry_path ) , function ( err , stat ) { if ( err ) { return run_callbacks ( ) ; } if ( stat . isDirectory ( ) ) { sections . push ( Path . join ( "/" , current_entry_path ) ) ; paths_to_traverse . push ( current_entry_path ) ; } return run_callbacks ( ) ; } ) ; } ; return run_callbacks ( ) ; } ) ; } ; return traverse_path ( ) ; }
returns all available sections rooting from the given path
returns all available sections rooting from the given path