cbou / markdox

Markdox is a documentation generator based on Dox and Markdown. It parse Javascript and even Coffeescript.
http://cbou.github.com/markdox
230 stars 27 forks source link

REQUEST: Allow custom output filenames in process #18

Open phun-ky opened 10 years ago

phun-ky commented 10 years ago

Currently, according to the documentation, I can only produce one '.md-file for all files that's given to markdox.

I am creating a multitask with grunt to take a set of files, create a *.md-file for each *.js-file, but it seems that I have to loop over each file in the set to produce a unique md file..

Current implementation

grunt.registerMultiTask('documentit', 'Create markdown documentation from JavaScript files with markdox', function(){

  var options = this.options({
      dest : 'docs/'
    });

  // Iterate over all src-dest file pairs.
  this.files.forEach(function(f) {

    var src = f.src.filter(function(filepath) {
      // Warn on and remove invalid source files (if nonull was set).
      if (!grunt.file.exists(filepath)) {
        grunt.log.warn('Source file "' + filepath + '" not found.');
        return false;
      } else {
        return true;
      }
    });

    if (src.length === 0) {
      grunt.log.warn('Destination (' + f.dest + ') not written because src files were empty.');
      return;
    }

    var _markdox_options = {
      output : ''
    };

    src.forEach(function(_f){

      var _dir_name =  path.dirname(_f),
      _new_name = path.basename(_dir_name);

      markdox.process(_f, options.dest + '' + _new_name + '-api.md', function(err){

        if(err){
          grunt.log.fatal(err);
        }

        grunt.log.success('Documentation generated to' + options.dest + '' + _new_name + '-api.md');

      });

    });

  });

});

Desired implementation

grunt.registerMultiTask('documentit', 'Create markdown documentation from JavaScript files with markdox', function(){

  var options = this.options({
      dest : 'docs/'
    });

  // Iterate over all src-dest file pairs.
  this.files.forEach(function(f) {

    var src = f.src.filter(function(filepath) {
      // Warn on and remove invalid source files (if nonull was set).
      if (!grunt.file.exists(filepath)) {
        grunt.log.warn('Source file "' + filepath + '" not found.');
        return false;
      } else {
        return true;
      }
    });

    if (src.length === 0) {
      grunt.log.warn('Destination (' + f.dest + ') not written because src files were empty.');
      return;
    }

    var _markdox_options = {
      // Use the filename of the processed file
      use_filename : true,
      // Prefix for the filename
      prefix : '',
      // Postfix for the filename
      postfix : '-api'
    };

    markdox.process(src, options, function(err){

      if(err){
        grunt.log.fatal(err);
      }

      grunt.log.success('Documentation generated');

    });

  });

});
cbou commented 10 years ago

This could be a nice feature.

If you want you could post a pull request.