all files / packages/navigation/processors/ navigation.js

31.82% Statements 7/22
0% Branches 0/6
50% Functions 3/6
31.82% Lines 7/22
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71                                                                                                                               
'use strict';
 
var _ = require('lodash');
 
module.exports = function generateNavigationProcessor(aliasMap, log) {
 
  var debug = log.debug;
 
  var AREAS = {
  };
 
  return {
    $runAfter: ['paths-computed'],
    $runBefore: ['rendering-docs'],
    /**
     * Appends or replaces mappers
     */
    addMappers: function (mappers) {
      mappers.forEach(function(mapper) {
        AREAS[mapper.area] = mapper;
      })
    },
    $process: function (docs) {
 
      var areas = {}, areaIds = [];
      _(docs)
      .filter(function (it) {
        return it.area;
      }).groupBy('area').forEach(function (pages, key) {
        debug('Start process area:', key);
 
        // take area aliases and link doc to first one
        var doc = aliasMap.getDocs(key + ':index');
        if (doc.length > 0) {
            doc = doc[0];
        } else {
            log.warn('No index document found for "%s"\nCreate %s/index.ngdoc file in the documents area with template' +
                     '\n===================\n@ngdoc overview\n@name index\n@area %s\n@description Module Overview', key, key, key);
            doc = { path: key };
        }
 
        if (AREAS[key]) {
          areas[key] = {
            id: key,
            href: doc.path,
            name: AREAS[key].title || key,
            fullscreen: doc.fullscreen,
            navGroups: AREAS[key](pages, key)
          };
          doc.areaKey = key;
          areaIds.push(key);
        }
      });
 
      docs.push({
        area: 'nav-data',
        docType: 'nav-data',
        id: 'nav-data',
        areas: areas
      });
 
      docs.push({
        area: 'nav-data',
        docType: 'nav-data',
        id: 'area-data',
        areaIds: areaIds
      });
    }
  };
};