Skip to content

Commit

Permalink
Update fp doc generation.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalton committed Feb 15, 2016
1 parent 19613be commit cf1a4f8
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 2 deletions.
40 changes: 38 additions & 2 deletions lib/fp/build-doc.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,45 @@
'use strict';

var _ = require('lodash'),
fs = require('fs-extra'),
path = require('path'),
util = require('../common/util');

var basePath = path.join(__dirname, '..', '..'),
docPath = path.join(basePath, 'doc'),
readmePath = path.join(docPath, 'FP-Guide.md');

var mapping = require('../../fp/_mapping'),
templatePath = path.join(__dirname, 'template/doc'),
template = util.globTemplate(path.join(templatePath, '*.jst'));

var templateData = {
'mapping': mapping,
'toFuncList': toFuncList
};

function toFuncList(array) {
var chunks = _.chunk(array.slice().sort(), 5),
lastChunk = _.last(chunks),
last = lastChunk ? lastChunk.pop() : undefined;

var result = '`' + _.map(chunks, function(chunk) {
return chunk.join('`, `') + '`';
}).join(',\n`');

return result + (last == null ? '' : (', & `' + last + '`'));
}

/*----------------------------------------------------------------------------*/

function build(type) {
function onComplete(error) {
if (error) {
throw error;
}
}

function build() {
fs.writeFile(readmePath, template.wiki(templateData), onComplete);
}

build(_.last(process.argv));
build();

This comment has been minimized.

Copy link
@jfmengels

jfmengels Feb 18, 2016

Contributor

Hey, just wanted to know if this is supposed to fully replace the work done in #1963. I understand this is much simpler to maintain and more correct than what was done there. Not taking the removal of #1963's code personally, but my original intention was to have a more "lodash docs'-like version of this, and I would still like to have that at some point. Is there anything I can do to help get back on that track?

This comment has been minimized.

Copy link
@jdalton

jdalton Feb 18, 2016

Author Member

Hi @jfmengels!

First off you rock. Thank you for your contributions, I hope this doesn't discourage you.
I think this approach is a better fit for the time being. Generating things from the map file is straight forward and answers the questions of "what's different" the easiest. I dig what you've started though so I could see that continuing as a side repo until things get ironed out.

64 changes: 64 additions & 0 deletions lib/fp/template/doc/wiki.jst
Original file line number Diff line number Diff line change
@@ -1 +1,65 @@
## lodash/fp

The lodash/fp module is an instance of lodash with its methods wrapped to produce
immutable auto-curried iteratee-first data-last methods.

## Installation

In a browser:
```html
<script src='path/to/lodash.js'></script>
<script src='path/to/lodash.fp.js'></script>
```

In Node.js:
```js
// load the fp build
var _ = require('lodash/fp');

// or a method category
var array = require('lodash/fp/object');

// or method for smaller builds with browserify/rollup/webpack
var extend = require('lodash/fp/extend');
```

## Notes

#### Arity

Methods with arity capped to one argument:<br>
<%= toFuncList(mapping.aryMethod[1]) %>

Methods with arity capped to two arguments:<br>
<%= toFuncList(mapping.aryMethod[2]) %>

Methods with arity capped to three arguments:<br>
<%= toFuncList(mapping.aryMethod[3]) %>

Methods with arity capped to four arguments:<br>
<%= toFuncList(mapping.aryMethod[4]) %>

#### Iteratees

Methods which provide iteratees one argument:<br>
<%= toFuncList(_.keys(_.pick(mapping.iterateeAry, _.partial(_.eq, _, 1)))) %>

Methods which provide iteratees two argument:<br>
<%= toFuncList(_.keys(_.pick(mapping.iterateeAry, _.partial(_.eq, _, 2)))) %>

#### New Methods

Methods created to accommodate Lodash’s variadic methods:<br>
<%= toFuncList(_.keys(mapping.remap)) %>

#### Exceptions

Methods which have argument order unchanged:<br>
<%= toFuncList(_.keys(mapping.skipRearg)) %>

#### Aliases

There are <%= _.size(mapping.aliasToReal) %> method aliases:<br>
<%= _.map(mapping.aliasToReal, function(realName, alias) {
return ' - Added `_.' + alias + '` as an alias of `_.' + realName + '`';
}).join('\n') %>
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"build:main": "node lib/main/build-dist.js",
"build:main-modules": "node lib/main/build-modules.js",
"doc": "node lib/main/build-doc github",
"doc:fp": "node lib/fp/build-doc",
"doc:site": "node lib/main/build-doc site",
"prepublish": "npm run style",
"pretest": "npm run build",
Expand Down

0 comments on commit cf1a4f8

Please sign in to comment.