Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REQUEST: Allow custom output filenames in process #18

Open
phun-ky opened this issue Sep 22, 2014 · 1 comment
Open

REQUEST: Allow custom output filenames in process #18

phun-ky opened this issue Sep 22, 2014 · 1 comment

Comments

@phun-ky
Copy link

phun-ky commented Sep 22, 2014

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
Copy link
Owner

cbou commented Oct 5, 2014

This could be a nice feature.

If you want you could post a pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants