Permalink
Browse files

[refactor] Depend on external blacksmith tool

  • Loading branch information...
1 parent dc132da commit a78f0c297c50c5e5f80fbe1f17369abd0438a721 @jfhbrook jfhbrook committed Nov 5, 2011
Showing with 3 additions and 1,386 deletions.
  1. +2 −2 README.md
  2. +0 −38 bin/docs
  3. 0 conf/docs.json → config.json
  4. +0 −105 lib/docs.js
  5. +0 −217 lib/fs2.js
  6. +0 −52 lib/generators/authors.js
  7. +0 −230 lib/generators/content.js
  8. +0 −81 lib/generators/errors.js
  9. +0 −55 lib/generators/rss.js
  10. +0 −64 lib/generators/theme.js
  11. +0 −22 lib/generators/toc.js
  12. +0 −161 lib/helpers.js
  13. +0 −167 lib/jquery.js
  14. +0 −178 lib/toc.js
  15. +1 −14 package.json
View
@@ -19,11 +19,11 @@ Browse /articles/ folder or http://docs.nodejitsu.com
### To generate the docs
- node bin/docs generate
+ blacksmith generate
### To start the docs server
- node bin/docs serve
+ blacksmith preview
## Contribution Guide
View
@@ -1,38 +0,0 @@
-var argv = require("optimist").argv,
- path = require("path"),
- docs = require("../lib/docs");
-require("colors");
-
-var task = argv._[0],
- dir = (argv.length - 1) ? (argv._[argv._.length - 1]) : ".";
-
-switch (task) {
- case "generate":
- console.log("GENERATING YOUR FILES".yellow);
- docs.generate(dir+"/pages", dir+"/public");
- break;
-
- case "serve":
-
- console.log("SERVING YOUR FILES".yellow);
-
- var HTTPServer = require('http-server').HTTPServer;
- var httpServer = new HTTPServer({root: dir+'/public/'});
-
- httpServer.start();
-
- process.on('SIGINT', function() {
- httpServer.log('http-server stopped.'.red);
- return process.exit();
- });
-
- break;
- default:
- console.log("Invalid instructions!".red);
- console.log();
- console.log("You may either:");
- console.log();
- console.log("* blacksmith generate <folder>");
- console.log("* blacksmith serve <folder>");
- console.log();
-}
File renamed without changes.
View
@@ -1,105 +0,0 @@
-/*
- * Docs - Top-level include for the docs project
- *
- * (C) 2011, Nodejitsu Inc.
- *
- */
-
-var docs = {},
- traverse = require('traverse'),
- path = require('path'),
- jsdom = require('jsdom'),
- markdown = require('github-flavored-markdown'),
- mkdirp = require('mkdirp'),
- fs = require('fs'),
- nconf = require('nconf'),
- findit = require('findit');
-
-docs = exports;
-
-docs.helpers = require('./helpers');
-
-// Use nconf to manage global configuration. Attached to docs object for later
-// use.
-nconf.add("global", { type: "file", file: __dirname + "/../conf/docs.json"});
-docs.config = nconf;
-
-// docs.generators is a list of key/value pairs so we can depend on method
-// execution being in-order. This is important, for example, in the case of
-// authors, since their loaded data is also used for extending metadata for the
-// articles.
-docs.generators = [
- { authors : require('./generators/authors')},
- { toc : require('./generators/toc')},
- { theme : require('./generators/theme')},
- { content : require('./generators/content')},
- { rss : require('./generators/rss')},
- { errors : require('./generators/errors')}
-];
-
-// docs.content will store static content during generation.
-// Examples include articles, themes and authors.
-docs.content = {};
-
-docs.generate = exports.generate = function (src, dst) {
-
- // Attach source and destination paths to the docs. This will eventually
- // enable multi-site generation.
- docs.src = path.resolve(src);
- docs.dst = path.resolve(dst);
-
- jsdom.env( "<html><body></body></html>", ['./jquery.js'], function (err, window) {
- if (err) {
- console.log("jsdom error: "+err);
- throw err;
- }
-
- // This is so we can call jquery later (docs.window.$)
- docs.window = window;
-
- // We pass an empty DOM element to each generator. This is used for
- // Weld-based templating.
- //
- // We could pass the window object around, or create multiple windows, or
- // even just create multiple jsdoms. Using a div, however, is simple and
- // relatively performant.
- var div = window.document.createElement('div');
-
- console.log('ready to generate docs...');
-
- // Iterate through every generator, each of which may output a set of
- // files and/or directories.
- // This block is wrapped in a try / catch since JSDOM is squashing some
- // errors.
- try {
- docs.generators.forEach( function (generator) {
- // Grabs the name given to the generator.
- var name = Object.keys(generator)[0];
-
- // Load assets
- docs.content[name] = generator[name].load(true);
-
- // Perform a weld on the div.
- generator[name].weld(div, docs.content[name]);
-
- // Write the content to disk.
- //
- // Note: jsdom strips doctypes. If we were using full doms we could
- // access the doctype for each individual page, but
- // because we're using the div to contain our document this
- // information never gets added to jsdom.
- //
- // The doctype for jsdom gets set explicitly during content loading.
- generator[name].generate(
- docs.window.document.doctype
- + "\n"
- + div.innerHTML, docs.content[name]
- );
- });
- } catch (err) {
- console.log(err.stack);
- }
- });
-
-};
-
View
@@ -1,217 +0,0 @@
-/*
- * fs2.js
- *
- * Contains tools for reading in directories of data.
- *
- */
-
-var fs2 = exports;
-
-var fs = require('fs'),
- path = require('path'),
- mkdirp = require('mkdirp'),
- traverse = require('traverse'),
- Hash = require('hashish'),
- findit = require('findit');
-
-// This transforms a list of files (such as findit's output) into an object
-// where the keys are file paths and values are file contents if "resolve" is
-// set to "true" and an empty string otherwise.
-fs2.filesArrayToObject = function( files, resolve ) {
-
- var _files = {};
-
- // Loop over the list of files and attach the result to _files as a key/value
- // pair.
- files.forEach( function (file) {
- var contents = '';
-
- if (resolve) {
-
- // Check to see if the path represents a directory or file.
- var stat = fs.statSync(file);
-
- if (stat.isDirectory()) {
-
- // This means that you can test for isDirectory with
- // dir[path].isDirectory
- contents = { "isDirectory": true };
- } else {
-
- // Read in the contents of the file.
- contents = fs.readFileSync(file);
- }
-
- }
-
- _files[file] = contents;
-
- });
-
- return _files;
-}
-
-// Convert a flat list of directories (ie, output from findit)
-// into a tree of the form:
-//
-// { "foo": {"bar": {} } }
-//
-fs2.filesToTree = function(files){
-
- files = files.reduce(function (acc, file) {
-
- // Splits the file path into a list.
- // Also takes care of double slashes to avoid blank keys.
- var ps = file.replace('//', '').split('/');
-
- // Filter out dot-paths.
- ps = ps.filter(function (e) {
- return e !== "."
- });
-
- // Use traverse to set acc[p[0]][p[1]]...[p[n-1]] to {}.
- // Traverse takes care of creating necessary objects.
- traverse(acc).set(ps, {});
- return acc;
- }, {});
-
- return files;
-
-}
-
-
-// Convert a flat directory object (such as that output by filesArrayToObject)
-// into a tree of the form:
-//
-// { "foo": {"bar": {} } }
-//
-fs2.dirToTree = function (dir) {
-
- // Same as filesToTree, except we use Object.keys which is equivalent to the
- // original list of files.
- return fs2.filesToTree(Object.keys(dir));
-
-}
-
-
-// orderedTree takes a nested tree (such as that output by dirToTree) and
-// transforms it into a structure of the form:
-//
-// [ { "foo": [ { "bar": {} ] }]
-//
-// The conversion from a hash with multiple keys into a list of hashes with
-// single keys gives our structure a sense of ordering.
-fs2.orderedTree = function (tree) {
-
- // This function is called recursively with the tree.
- function ordered (tree) {
-
- // Take each subtree in the hash and replace it with an ordered subtree.
- var subtrees = Hash(tree).map(function (v) {
- return ordered(v);
- }).items,
- _tree = [];
-
- // This tree still needs to be ordered itself!
- Object.keys(subtrees).forEach(function(k) {
- var obj = {};
-
- // Obj only has one key/value pair.
- obj[k] = subtrees[k];
-
- // Push this key/value pair onto our list.
- _tree.push(obj);
- });
-
- return _tree;
- }
-
- // Call it!
- return ordered(tree);
-}
-
-// Reads in an entire directory and converts it into an object
-// where the keys are file paths and the values are file contents if "resolve"
-// is set to "true" (and an empty string otherwise).
-//
-// Arguments:
-//
-// * path: The path of the directory
-// * resolve [optional]: If set to "true," file contents are set to their
-// corresponding values.
-// * filter(element) [optional]: If defined, output of findit is filtered using
-// this function.
-// * callback(err, result)
-fs2.readDir = function (p, resolve, filter, cb) {
-
- // Since resolve and filter are optional, we need to handle the cases where
- // not every argument is defined.
- if (!filter) {
- cb = resolve;
- resolve = false;
- } else if (!cb) {
- cb = filter;
- filter = null;
- }
-
-
- var files = [],
- finder;
-
- // Finder throws errors instead of passing them, so we use a "try" to funnel
- // any errors to the callback.
- try {
- finder = findit.find(p, function (f) {
- // This gets called for each individual file. Here we collect them all.
- files.push(f);
- });
-
- // Once finder is done, we can finish up.
- finder.on("end", function () {
- // Apply the filter, if any.
- if (typeof filter === 'function') {
- files = files.filter(filter);
- }
-
- // Convert the list from findit into an object structure.
- cb(null, fs2.filesArrayToObject(files, resolve));
-
- });
- } catch (e) {
- cb(e);
- }
-};
-
-
-// This is the syncronous version of readDir. It does not take a callback and
-// throws its errors, but is otherwise equivalent.
-fs2.readDirSync = function (p, resolve, filter) {
-
- // findit.sync returns a list of directories already.
- var files = findit.sync(p);
-
- if ( typeof filter === 'function') {
- // Apply the filter, if any.
- files = files.filter(filter);
- }
-
- // Convert the list from findit into an object structure.
- return fs2.filesArrayToObject(files, resolve);
-
-};
-
-
-// fs2.writeFile forces a file write by using mkdirp to recurisvely build
-// directories. Otherwise, the API mirrors that of fs.writeFile.
-fs2.writeFile = function(filePath, contents, callback) {
-
- var fileDir = path.dirname(filePath);
-
- mkdirp(fileDir, 0755, function(err){
- if (err) {
- callback(err);
- }
- fs.writeFile(filePath, contents, callback);
- });
-
-};
Oops, something went wrong.

0 comments on commit a78f0c2

Please sign in to comment.