Skip to content
This repository has been archived by the owner on Jan 23, 2022. It is now read-only.

Commit

Permalink
feat(ngdocs): use lodash
Browse files Browse the repository at this point in the history
  • Loading branch information
m7r committed Jan 26, 2018
1 parent 067a058 commit 7963898
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"readmeFilename": "README.md",
"dependencies": {
"marked": "~0.3.2",
"lodash": "^4.0.0",
"shelljs": "~0.3.0",
"upath": "~0.2.0"
},
Expand Down
23 changes: 12 additions & 11 deletions tasks/grunt-ngdocs.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

var reader = require('../src/reader.js'),
ngdoc = require('../src/ngdoc.js'),
template = require('lodash/template'),
flatten = require('lodash/flatten'),
union = require('lodash/union'),
path = require('path'),
upath = require('upath'),
vm = require('vm');
Expand All @@ -21,8 +24,7 @@ var repohosts = [
];

module.exports = function(grunt) {
var _ = grunt.util._,
unittest = {},
var unittest = {},
templates = path.resolve(__dirname, '../src/templates');

grunt.registerMultiTask('ngdocs', 'build documentation', function() {
Expand Down Expand Up @@ -50,9 +52,8 @@ module.exports = function(grunt) {
var gruntStylesFolder = 'grunt-styles';

// If the options.script is an array of arrays ( useful when working with variables, for example: ['<%= vendor_files %>','<%= app_files %>'] )
// convert to a single array with _.flatten ( http://underscorejs.org/#flatten )
options.scripts = _.flatten(options.scripts);
options.scripts = _.map(options.scripts, function(file) {
// convert to a single array ( https://lodash.com/docs/4.17.4#flatten )
options.scripts = flatten(options.scripts).map(function(file) {
if (file === 'angular.js') {
return 'js/angular.min.js';
}
Expand All @@ -75,7 +76,7 @@ module.exports = function(grunt) {
options.image = gruntStylesFolder + '/' + options.image;
}

options.styles = _.map(options.styles, function(file) {
options.styles = options.styles.map(function(file) {
if (linked.test(file)) {
return file;
}
Expand Down Expand Up @@ -112,7 +113,7 @@ module.exports = function(grunt) {

ngdoc.checkBrokenLinks(reader.docs, setup.apis, options);

setup.pages = _.union(setup.pages, ngdoc.metadata(reader.docs));
setup.pages = union(setup.pages, ngdoc.metadata(reader.docs));

if (options.navTemplate) {
options.navContent = grunt.template.process(grunt.file.read(options.navTemplate));
Expand Down Expand Up @@ -146,7 +147,7 @@ module.exports = function(grunt) {
values.rev = '' + sha.output;
values.sha = values.rev.slice(0, 7);
}
tmpl = _.template(tmpl, undefined, {'interpolate': /\{\{(.+?)\}\}/g});
tmpl = template(tmpl, {'interpolate': /\{\{(.+?)\}\}/g});
return function(file, line, codeline) {
values.file = file;
values.line = line;
Expand Down Expand Up @@ -194,7 +195,7 @@ module.exports = function(grunt) {
vm.runInNewContext(data, context, file);
setup = context.NG_DOCS;
// keep only pages from other build tasks
setup.pages = _.filter(setup.pages, function(p) {return p.section !== section;});
setup.pages = setup.pages.filter(function(p) {return p.section !== section;});
} else {
// build clean dest
setup = {sections: {}, pages: [], apis: {}};
Expand All @@ -210,7 +211,7 @@ module.exports = function(grunt) {
content, data = {
scripts: options.scripts,
styles: options.styles,
sections: _.keys(setup.sections).join('|'),
sections: Object.keys(setup.sections).join('|'),
discussions: options.discussions,
analytics: options.analytics,
navContent: options.navContent,
Expand All @@ -233,7 +234,7 @@ module.exports = function(grunt) {
setup.editExample = options.editExample;
setup.startPage = options.startPage;
setup.discussions = options.discussions;
setup.scripts = _.map(options.scripts, function(url) { return path.basename(url); });
setup.scripts = options.scripts.map(function(url) { return path.basename(url); });
grunt.file.write(setup.__file, 'NG_DOCS=' + JSON.stringify(setup, replacer, 2) + ';');
}

Expand Down

0 comments on commit 7963898

Please sign in to comment.