Permalink
Browse files

Make a sorted array of components available in project metadata.

  • Loading branch information...
1 parent 2f60951 commit 0fe28475455a8625ce6c7bcf655afd24e02d3e9c @rgrove committed Jul 29, 2011
Showing with 67 additions and 15 deletions.
  1. +9 −4 bin/selleck
  2. +11 −1 lib/selleck.js
  3. +29 −10 lib/server.js
  4. +18 −0 lib/util.js
View
@@ -264,7 +264,12 @@ if (options.server) {
});
});
- project.components = components;
+ project.meta.components = util.values(components).sort(function (a, b) {
+ var aName = a.meta.displayName.toLowerCase(),
+ bName = b.meta.displayName.toLowerCase();
+
+ return aName < bName ? -1 : (aName > bName ? 1 : 0);
+ });
generateProject();
});
@@ -291,12 +296,12 @@ if (options.server) {
function generateComponents(err) {
if (err) { return finish(err); }
- var toGenerate = util.size(project.components);
+ var toGenerate = util.size(components);
if (!toGenerate) { return finish(); }
// Generate component docs.
- util.each(project.components, function(component) {
+ util.each(components, function(component) {
var path = component.path;
log('Generating component docs for ' + path, 'info');
@@ -329,7 +334,7 @@ if (options.server) {
project : util.merge(project.meta, options.overrideMeta)
};
- util.each(project.components, function (component) {
+ util.each(components, function (component) {
var data = util.merge(component.meta);
delete data.componentDefaults;
View
@@ -93,6 +93,12 @@ function findDocs(dir, docs) {
return docs;
}
+ // TODO: implement a proper ignore list someday.
+ if (path.basename(dir) === 'node_modules') {
+ log('Ignoring node_modules dir: ' + dir, 'info');
+ return docs;
+ }
+
if (isComponentDirectory(dir)) {
docs.components.push({path: dir});
} else if (isProjectDirectory(dir)) {
@@ -327,7 +333,7 @@ function prepare(inDir, options, callback) {
// - project metadata
// - theme metadata (lowest precedence)
- if (options.component && options.meta.componentDefaults) {
+ if (options.component && options.meta && options.meta.componentDefaults) {
meta = options.meta.componentDefaults;
}
@@ -353,6 +359,10 @@ function prepare(inDir, options, callback) {
// else.
util.mix(options.meta, options.overrideMeta);
+ if (options.overrideMeta && options.overrideMeta.componentDefaults) {
+ util.mix(options.meta, options.overrideMeta.componentDefaults);
+ }
+
// Set a default asset path if one isn't specified in the metadata.
if (!options.meta.projectAssets) {
options.meta.projectAssets = options.component ? '../assets' : 'assets';
View
@@ -20,14 +20,23 @@ module.exports = function (config) {
docs = selleck.findDocs(config.rootPath, docs);
projectPath = docs.project && docs.project.path;
- // Gather the names of all components.
- docs.components.forEach(function (component) {
- var path = component.path,
- meta = selleck.getMetadata(path, 'component');
+ // Initial pass to load all component info.
+ docs.components.forEach(function(component, index) {
+ var path = component.path;
+
+ selleck.prepare(path, {
+ component: true,
+ index : index,
+ path : path
+ }, function (err, result) {
+ if (err) { throw err; }
+
+ if (result.meta.examples) {
+ result.meta.hasOwnExamples = true;
+ }
- if (meta.name) {
- components[meta.name] = path;
- }
+ components[result.meta.name] = result;
+ });
});
app.configure(function () {
@@ -53,7 +62,6 @@ module.exports = function (config) {
var component = req.params[1],
filePath = req.params[2],
fullPath = req.params[0],
- root = component ? components[component] || projectPath : projectPath,
paths = [],
foundPath, testPath;
@@ -63,7 +71,7 @@ module.exports = function (config) {
// (if any), then project, and finally theme. First one that matches
// wins.
if (component && components[component]) {
- paths.push(fsPath.join(components[component], 'assets', filePath));
+ paths.push(fsPath.join(components[component].path, 'assets', filePath));
}
paths.push(fsPath.join(projectPath, 'assets', fullPath));
@@ -99,6 +107,13 @@ module.exports = function (config) {
selleck.prepare(projectPath, options, function (err, options, compiled) {
if (err) { return next(err); }
+ options.meta.components = util.values(components).sort(function (a, b) {
+ var aName = a.meta.displayName.toLowerCase(),
+ bName = b.meta.displayName.toLowerCase();
+
+ return aName < bName ? -1 : (aName > bName ? 1 : 0);
+ });
+
var view = new selleck.View(options.meta, pageName),
layout = options.layouts[view.layout];
@@ -115,7 +130,7 @@ module.exports = function (config) {
// Component docs.
app.get(/^\/([\w\-]+)(?:\/|\/([\w\-]+)\.html)$/, function (req, res, next) {
var component = req.params[0],
- docPath = components[component],
+ docPath = components[component] && components[component].path,
options = {component: true},
pageName = req.params[1] || 'index';
@@ -143,6 +158,10 @@ module.exports = function (config) {
selleck.prepare(docPath, options, function (err, options, compiled) {
if (err) { return next(err); }
+ if (options.meta.examples) {
+ options.meta.hasOwnExamples = true;
+ }
+
var view = new selleck.ComponentView(options.meta, pageName),
layout = options.layouts[view.layout];
View
@@ -120,6 +120,24 @@ function size(obj) {
exports.size = size;
/**
+Returns an array of values in _obj_.
+
+@method values
+@param {Array|Object} obj Array or object.
+@return {Array} Values.
+**/
+function values(obj) {
+ var result = [];
+
+ each(obj, function (value) {
+ result.push(value);
+ });
+
+ return result;
+}
+exports.values = values;
+
+/**
Creates a stack for multiple callback management:
var s = new util.Stack();

0 comments on commit 0fe2847

Please sign in to comment.