helper-license
Advanced tools
Comparing version 0.1.3 to 0.2.0
85
index.js
'use strict'; | ||
var mdu = require('markdown-utils'); | ||
var _ = require('lodash'); | ||
var pluck = require('arr-pluck'); | ||
var merge = require('mixin-deep'); | ||
/** | ||
* Add a basic license statement | ||
* | ||
* ```js | ||
* {%= license() %} | ||
* //=> Released under the MIT license | ||
* | ||
* {%= license({linkify: true}) %} | ||
* //=> Released under the [MIT](https://github.com/jonschlinkert/helper-license/blob/master/LICENSE-MIT) license | ||
* ``` | ||
* | ||
* @return {String} Complete license statement. | ||
*/ | ||
module.exports = function license_(locals) { | ||
var o = typeof locals === 'object' ? locals : {}; | ||
module.exports = function(locals) { | ||
var context = {}; | ||
// compatibility with template, verb and assemble. | ||
// support Template, verb and assemble. | ||
if (this && this.app && this.context) { | ||
context = _.merge({}, this.options, this.app.cache.data, this.context); | ||
this.app.union('reflinks', ['verb', 'template', 'assemble']); | ||
o = merge({}, this.options, this.context, o); | ||
} | ||
var o = _.merge({}, context, locals); | ||
if (!o.license && !o.licenses) { | ||
throw new Error('helper-license expects a "license" or "licenses" property'); | ||
} | ||
if (typeof o.license === 'string') { | ||
o.license = {type: o.license}; | ||
} | ||
var licenses = Array.isArray(o.licenses) ? o.licenses : [o.license]; | ||
var res = 'Released under the '; | ||
var len = licenses.length; | ||
var urls = []; | ||
try { | ||
if (o.licenses) { | ||
if (o.linkify === true) { | ||
o.licenses.forEach(function (license) { | ||
if (license.type && license.url) { | ||
urls.push(mdu.link(license.type, license.url)); | ||
} | ||
}); | ||
if (o.linkify === true) { | ||
licenses.forEach(function (license) { | ||
if (license.type && license.url) { | ||
urls.push(mdu.link(license.type, license.url)); | ||
} | ||
}); | ||
} | ||
if (urls.length > 0) { | ||
res += urls.join(', ') + ' license' + (o.licenses.length <= 1 ? '' : 's'); | ||
} else { | ||
res += _.pluck(o.licenses, 'type').join(', ') + ' license' + (o.licenses.length <= 1 ? '' : 's'); | ||
} | ||
} else if (o.license) { | ||
var license; | ||
if (typeof o.license === 'object') { | ||
if (o.linkify === true && o.license.type && o.license.url) { | ||
license = mdu.link(o.license.type, o.license.url); | ||
} else { | ||
license = o.license.type; | ||
} | ||
} | ||
if (typeof o.license === 'string') { | ||
license = o.license; | ||
} | ||
res += license + (o.suffix || ' license'); | ||
} | ||
} catch (err) { | ||
err.origin = __filename; | ||
console.warn('No "license" or "licenses" properties found.', err); | ||
var s = len <= 1 ? '.' : 's.'; | ||
if (urls.length > 0) { | ||
res += urls.join(', ') + ' license' + s; | ||
} else { | ||
res += pluck(licenses, 'type').join(', ') + ' license' + s; | ||
} | ||
return res; | ||
}; |
{ | ||
"name": "helper-license", | ||
"description": "Template helper for dynamically generating a basic, one-line license statement based on the given context, e.g. `Released under the MIT license`. Should work with any Handlebars, Lo-Dash, underscore, or any template engine that allows helper functions to be registered.", | ||
"version": "0.1.3", | ||
"version": "0.2.0", | ||
"homepage": "https://github.com/helpers/helper-license", | ||
@@ -17,7 +17,8 @@ "author": { | ||
}, | ||
"licenses": [ | ||
{ | ||
"type": "MIT", | ||
"url": "https://github.com/helpers/helper-license/blob/master/LICENSE-MIT" | ||
} | ||
"license": { | ||
"type": "MIT", | ||
"url": "https://github.com/helpers/helper-license/blob/master/LICENSE" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
@@ -29,12 +30,14 @@ "main": "index.js", | ||
"scripts": { | ||
"test": "mocha -R spec" | ||
"test": "mocha" | ||
}, | ||
"dependencies": { | ||
"lodash": "^2.4.1", | ||
"markdown-utils": "^0.1.0" | ||
"arr-pluck": "^0.1.0", | ||
"markdown-utils": "^0.6.0", | ||
"mixin-deep": "^1.0.1" | ||
}, | ||
"devDependencies": { | ||
"handlebars": "^2.0.0", | ||
"lodash": "^3.7.0", | ||
"should": "^4.2.1" | ||
} | ||
} |
103
README.md
@@ -1,2 +0,2 @@ | ||
# helper-license [![NPM version](https://badge.fury.io/js/helper-license.svg)](http://badge.fury.io/js/helper-license) | ||
# helper-license [![NPM version](https://badge.fury.io/js/helper-license.svg)](http://badge.fury.io/js/helper-license) [![Build Status](https://travis-ci.org/helpers/helper-license.svg)](https://travis-ci.org/helpers/helper-license) | ||
@@ -6,4 +6,3 @@ > Template helper for dynamically generating a basic, one-line license statement based on the given context, e.g. `Released under the MIT license`. Should work with any Handlebars, Lo-Dash, underscore, or any template engine that allows helper functions to be registered. | ||
## Install | ||
### Install with [npm](npmjs.org) | ||
## Install with [npm](npmjs.org) | ||
@@ -14,21 +13,50 @@ ```bash | ||
## Usage example | ||
## Run tests | ||
Add a basic license statement to a document with [verb]: | ||
```bash | ||
npm test | ||
```js | ||
{%= license() %} | ||
//=> Released under the MIT license | ||
{%= license({linkify: true}) %} | ||
//=> Released under the [MIT](https://github.com/jonschlinkert/helper-license/blob/master/LICENSE-MIT) license | ||
``` | ||
## Other engines/apps | ||
## Register the helper | ||
Add a basic license statement | ||
> This should work with any engine, here are a few examples | ||
```js | ||
var pkg = require('./package.json'); | ||
### [template](https://github.com/jonschlinkert/template) | ||
// handlebars | ||
Handlebars.compile('{{license this}}')(pkg); | ||
// lo-dash | ||
_.template('<%= license({licenses: licenses}) %>', ) | ||
// verb | ||
verb.render('{%= license({licenses: licenses}) %}', pkg); | ||
// all result in: | ||
//=> Released under the MIT license | ||
``` | ||
Linkify: | ||
```js | ||
_.template('<%= license({licenses: licenses, linkify: true}) %>', pkg); | ||
//=> Released under the [MIT](https://github.com/jonschlinkert/helper-license/blob/master/LICENSE-MIT) license | ||
``` | ||
## Registering the helper | ||
> This should work with any engine, here are a few examples to get you started | ||
### [template] | ||
```js | ||
template.helper('license', require('helper-license')); | ||
``` | ||
### [assemble](https://github.com/assemble/assemble) | ||
### [assemble] | ||
@@ -39,3 +67,3 @@ ```js | ||
### [verb](https://github.com/jonschlinkert/verb) | ||
### [verb] | ||
@@ -46,3 +74,3 @@ ```js | ||
### [handlebars](https://github.com/wycats/handlebars.js/) | ||
### [handlebars] | ||
@@ -54,28 +82,16 @@ ```js | ||
## Example usage | ||
## Related projects | ||
* [helper-copyright](https://github.com/helpers/helper-copyright): Template helper for adding a basic, one-line copyright statement, with… [more](https://github.com/helpers/helper-copyright) | ||
* [helper-reflinks](https://github.com/helpers/helper-reflinks): Template helper for generating a list of markdown formatted reference… [more](https://github.com/helpers/helper-reflinks) | ||
* [helper-related](https://github.com/helpers/helper-related): Template helper for generating a list of links to the… [more](https://github.com/helpers/helper-related) | ||
* [template-helpers](https://github.com/jonschlinkert/template-helpers): Generic JavaScript helpers that can be used with any template… [more](https://github.com/jonschlinkert/template-helpers) | ||
* [verb](https://github.com/assemble/verb): Verb makes it dead simple to generate markdown documentation, using… [more](https://github.com/assemble/verb) | ||
Add a basic license statement | ||
## Running tests | ||
Install dev dependencies: | ||
```js | ||
var pkg = require('./package.json'); | ||
// handlebars | ||
Handlebars.compile('{{license this}}')(pkg); | ||
// lo-dash | ||
_.template('<%= license({licenses: licenses}) %>', ) | ||
// verb | ||
verb.render('{%= license({licenses: licenses}) %}', pkg); | ||
// all result in: | ||
//=> Released under the MIT license | ||
```bash | ||
npm i -d && npm test | ||
``` | ||
Linkify: | ||
```js | ||
_.template('<%= license({licenses: licenses, linkify: true}) %>', pkg); | ||
//=> Released under the [MIT](https://github.com/jonschlinkert/helper-license/blob/master/LICENSE-MIT) license | ||
``` | ||
## Contributing | ||
@@ -85,10 +101,9 @@ Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/helpers/helper-license/issues) | ||
## Author | ||
**Jon Schlinkert** | ||
+ [github/helpers](https://github.com/helpers) | ||
+ [twitter/helpers](http://twitter.com/helpers) | ||
+ [github/jonschlinkert](https://github.com/jonschlinkert) | ||
+ [twitter/jonschlinkert](http://twitter.com/jonschlinkert) | ||
## License | ||
Copyright (c) 2014 Jon Schlinkert | ||
Copyright (c) 2015 Jon Schlinkert | ||
Released under the MIT license | ||
@@ -98,2 +113,10 @@ | ||
_This file was generated by [verb](https://github.com/jonschlinkert/verb) on November 11, 2014._ | ||
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on April 23, 2015._ | ||
<!-- reflinks --> | ||
[template]: https://github.com/jonschlinkert/template | ||
[verb]: https://github.com/assemble/verb | ||
[assemble]: http://assemble.io | ||
[handlebars]: http://www.handlebarsjs.com/ | ||
[lodash]: https://lodash.com/ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
116
7013
3
3
4
36
+ Addedarr-pluck@^0.1.0
+ Addedmixin-deep@^1.0.1
+ Addedarr-map@2.0.2(transitive)
+ Addedarr-pluck@0.1.0(transitive)
+ Addedarray-slice@0.2.3(transitive)
+ Addedexpand-range@1.8.2(transitive)
+ Addedfill-range@2.2.4(transitive)
+ Addedfor-in@1.0.2(transitive)
+ Addedis-buffer@1.1.6(transitive)
+ Addedis-extendable@1.0.1(transitive)
+ Addedis-number@1.1.22.1.04.0.0(transitive)
+ Addedis-plain-object@2.0.4(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedisobject@2.1.03.0.1(transitive)
+ Addedkind-of@3.2.26.0.3(transitive)
+ Addedlist-item@0.1.2(transitive)
+ Addedmake-iterator@1.0.1(transitive)
+ Addedmarkdown-utils@0.6.1(transitive)
+ Addedmath-random@1.0.4(transitive)
+ Addedmixin-deep@1.3.2(transitive)
+ Addedrandomatic@3.1.1(transitive)
+ Addedrepeat-element@1.1.4(transitive)
+ Addedrepeat-string@1.6.1(transitive)
- Removedlodash@^2.4.1
- Removedexport-files@0.1.4(transitive)
- Removedlodash@2.4.2(transitive)
- Removedmarkdown-utils@0.1.3(transitive)
- Removedrepeat-string@0.2.2(transitive)
Updatedmarkdown-utils@^0.6.0