Skip to content
Browse files

reduced code size and greatly improved simplicity

  • Loading branch information...
1 parent 6b98d71 commit 80b91e48083d6957e80ca2a659a067d1fc3ef4af @neocotic neocotic committed Mar 19, 2013
Showing with 18 additions and 35 deletions.
  1. +11 −20 docco.js
  2. +7 −15 docco.litcoffee
View
31 docco.js
@@ -7,29 +7,20 @@
if (options == null) {
options = {};
}
+ if (callback == null) {
+ callback = function(error) {
+ if (error) {
+ throw error;
+ }
+ };
+ }
configure(options);
return exec("mkdir -p " + config.output, function() {
- var complete, completed, files, nextFile, steps;
+ var complete, files, nextFile;
- steps = 2;
- completed = 0;
- complete = function(error) {
- if (error) {
- if (_.isFunction(callback)) {
- return callback(error);
- } else {
- throw error;
- }
- }
- if (++completed === steps) {
- return typeof callback === "function" ? callback() : void 0;
- }
+ complete = function() {
+ return exec(["cp -f " + config.css + " " + config.output, fs.existsSync(config["public"]) ? "cp -fR " + config["public"] + " " + config.output : void 0].join('&'), callback);
};
- exec("cp -f " + config.css + " " + config.output, complete);
- if (fs.existsSync(config["public"])) {
- steps++;
- exec("cp -fR " + config["public"] + " " + config.output, complete);
- }
files = config.sources.slice();
nextFile = function() {
var source;
@@ -39,7 +30,7 @@
var code, sections;
if (error) {
- complete(error);
+ return callback(error);
}
code = buffer.toString();
sections = parse(source, code);
View
22 docco.litcoffee
@@ -77,31 +77,23 @@ assets, reading all the source files in, splitting them up into prose+code
sections, highlighting each file in the appropriate language, and printing them
out in an HTML template.
- document = (options = {}, callback) ->
+ document = (options = {}, callback = (error) -> throw error if error) ->
configure options
exec "mkdir -p #{config.output}", ->
- steps = 2
- completed = 0
+ complete = ->
+ exec [
+ "cp -f #{config.css} #{config.output}"
+ "cp -fR #{config.public} #{config.output}" if fs.existsSync config.public
+ ].join('&'), callback
- complete = (error) ->
- if error
- if _.isFunction callback then return callback error
- else throw error
-
- callback?() if ++completed is steps
-
- exec "cp -f #{config.css} #{config.output}", complete
- if fs.existsSync config.public
- steps++
- exec "cp -fR #{config.public} #{config.output}", complete
files = config.sources.slice()
nextFile = ->
source = files.shift()
fs.readFile source, (error, buffer) ->
- complete error if error
+ return callback error if error
code = buffer.toString()
sections = parse source, code

0 comments on commit 80b91e4

Please sign in to comment.
Something went wrong with that request. Please try again.