wingedfox / dgeni-alive

Live docs on top of dgeni documentation generator
MIT License
26 stars 14 forks source link

Adding a sortOrder tag to documents #4

Closed andy-dorman closed 8 years ago

andy-dorman commented 8 years ago

I've added a config call that processes @sortOrder markup in my documents:

.config(function(parseTagsProcessor) {
  parseTagsProcessor.tagDefinitions.push(require('./ngdocs/config/tag-defs/sortOrder'));
})

that looks like this:

module.exports = {
  name: 'sortOrder',
  transforms: function(doc, tag, value) {
    return parseInt(value, 10);
  }
};

and that this is allowing me to write markup that looks like this

@ngdoc overview
@name ie
@title Internet Explorer Compatibility
@sortOrder 530
@area guide

and I can see that this is being processed correctly in a subsequent processor:

.processor(require('./ngdocs/processors/orderNavItems'))

that looks like this

var _ = require('lodash');

module.exports = function generatePagesDataProcessor(log) {
  return {
    $runAfter: ['paths-computed'],
    $runBefore: ['rendering-docs'],
    $process: function(docs) {
      // We are only interested in docs that are in an area
      docs = _(docs)
      .sortBy(function(g) {
        return g.sortOrder;
      })
      .value();

    }
  }
};

How can I get this ordering to be respected in the subsequent mapper processors? I'm sure I'm simply misunderstanding the order of things in dgeni...

wingedfox commented 8 years ago

Hi Andy,

Sorry for the late answer.

There's no way to change the sort order inside the docs, except manual reordering. Anyway, I've added the @sortOrder tag and it's support to 'docs' and 'guide' mapper.

See https://github.com/wingedfox/dgeni-alive/blob/master/src/packages/navigation/tag-defs/sort-order.js https://github.com/wingedfox/dgeni-alive/blob/master/src/packages/navigation/processors/nav-area-mapper/guide.js#L18

Also, sortBy mapper field is configurable as well and you can use

.config(function(navigationMapper_GUIDE) {
  navigationMapper_GUIDE.sortBy.unshift('myCustomProp');
});