Skip to content

Commit aecccdb

Browse files
committed
initial commit
0 parents  commit aecccdb

17 files changed

+1869
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
npm-debug.log
3+
tmp

.jshintrc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"curly": true,
3+
"eqeqeq": true,
4+
"immed": true,
5+
"latedef": true,
6+
"newcap": true,
7+
"noarg": true,
8+
"sub": true,
9+
"undef": true,
10+
"boss": true,
11+
"eqnull": true,
12+
"node": true
13+
}

Gruntfile.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* grunt-documentation
3+
* https://github.com/SunboX/grunt-documentation
4+
*
5+
* Copyright (c) 2015 André Fiedler
6+
* Licensed under the MIT license.
7+
*/
8+
9+
'use strict';
10+
11+
module.exports = function(grunt) {
12+
13+
// Project configuration.
14+
grunt.initConfig({
15+
jshint: {
16+
all: [
17+
'Gruntfile.js',
18+
'tasks/*.js',
19+
'<%= nodeunit.tests %>'
20+
],
21+
options: {
22+
jshintrc: '.jshintrc'
23+
}
24+
}
25+
26+
});
27+
28+
// Actually load this plugin's task(s).
29+
grunt.loadTasks('tasks');
30+
31+
// These plugins provide necessary tasks.
32+
grunt.loadNpmTasks('grunt-contrib-jshint');
33+
34+
// By default, lint and run all tests.
35+
grunt.registerTask('default', ['jshint', 'test']);
36+
37+
};

LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Copyright (c) 2015 André Fiedler
2+
3+
Permission is hereby granted, free of charge, to any person
4+
obtaining a copy of this software and associated documentation
5+
files (the "Software"), to deal in the Software without
6+
restriction, including without limitation the rights to use,
7+
copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
copies of the Software, and to permit persons to whom the
9+
Software is furnished to do so, subject to the following
10+
conditions:
11+
12+
The above copyright notice and this permission notice shall be
13+
included in all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22+
OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# grunt-documentation
2+
3+
Use [Grunt](http://gruntjs.com/) with
4+
[documentation](https://github.com/documentationjs/documentation)
5+
to generate great documentation for your JavaScript projects.
6+
7+
## Getting Started
8+
This plugin requires Grunt `~0.4.5`
9+
10+
If you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
11+
12+
```shell
13+
npm install grunt-documentation --save-dev
14+
```
15+
16+
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
17+
18+
```js
19+
grunt.loadNpmTasks('grunt-documentation');
20+
```
21+
22+
## The "documentation" task
23+
24+
### Overview
25+
In your project's Gruntfile, add a section named `documentation` to the data object passed into `grunt.initConfig()`.
26+
27+
```js
28+
grunt.initConfig({
29+
documentation: {
30+
default: {
31+
files: [{
32+
"expand": true,
33+
"cwd": "src",
34+
"src": ["**/*.js"]
35+
}],
36+
options: {
37+
destination: "docs",
38+
}
39+
},
40+
}
41+
});
42+
```
43+
44+
### Options
45+
46+
#### options.destination
47+
Type: `String`
48+
49+
The destination folder for the generated docs.
50+
51+
#### options.format
52+
Type: `String`
53+
Default value: `'html'`
54+
55+
Either `'html'`, `'md'`, `'json'`, or `'docset'`.
56+
57+
#### options.filename
58+
Type: `String`
59+
60+
Custom filename for md or json output.
61+
62+
## Contributing
63+
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/).
64+
65+
## Release History
66+
_(Nothing yet)_

demo/Gruntfile.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* grunt-documentation demo
3+
*
4+
* Copyright (c) 2015 André Fiedler
5+
* Licensed under the MIT license.
6+
*/
7+
'use strict';
8+
9+
module.exports = function(grunt) {
10+
11+
// Project configuration.
12+
grunt.initConfig({
13+
14+
documentation: {
15+
default: {
16+
files: [{
17+
'expand': true,
18+
'cwd': 'src',
19+
'src': ['**/*.js']
20+
}],
21+
options: {
22+
destination: 'docs',
23+
}
24+
},
25+
}
26+
27+
});
28+
29+
// Actually load this plugin's task(s).
30+
grunt.loadTasks('../tasks');
31+
32+
// By default, run.
33+
grunt.registerTask('default', ['documentation']);
34+
35+
};

demo/docs/assets/anchor.js

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
/*!
2+
* AnchorJS - v1.2.1 - 2015-07-02
3+
* https://github.com/bryanbraun/anchorjs
4+
* Copyright (c) 2015 Bryan Braun; Licensed MIT
5+
*/
6+
7+
function AnchorJS(options) {
8+
'use strict';
9+
10+
this.options = options || {};
11+
12+
this._applyRemainingDefaultOptions = function(opts) {
13+
this.options.icon = this.options.hasOwnProperty('icon') ? opts.icon : '\ue9cb'; // Accepts characters (and also URLs?), like '#', '¶', '❡', or '§'.
14+
this.options.visible = this.options.hasOwnProperty('visible') ? opts.visible : 'hover'; // Also accepts 'always'
15+
this.options.placement = this.options.hasOwnProperty('placement') ? opts.placement : 'right'; // Also accepts 'left'
16+
this.options.class = this.options.hasOwnProperty('class') ? opts.class : ''; // Accepts any class name.
17+
};
18+
19+
this._applyRemainingDefaultOptions(options);
20+
21+
this.add = function(selector) {
22+
var elements,
23+
elsWithIds,
24+
idList,
25+
elementID,
26+
i,
27+
roughText,
28+
tidyText,
29+
index,
30+
count,
31+
newTidyText,
32+
readableID,
33+
anchor;
34+
35+
this._applyRemainingDefaultOptions(this.options);
36+
37+
// Provide a sensible default selector, if none is given.
38+
if (!selector) {
39+
selector = 'h1, h2, h3, h4, h5, h6';
40+
} else if (typeof selector !== 'string') {
41+
throw new Error('The selector provided to AnchorJS was invalid.');
42+
}
43+
44+
elements = document.querySelectorAll(selector);
45+
if (elements.length === 0) {
46+
return false;
47+
}
48+
49+
this._addBaselineStyles();
50+
51+
// We produce a list of existing IDs so we don't generate a duplicate.
52+
elsWithIds = document.querySelectorAll('[id]');
53+
idList = [].map.call(elsWithIds, function assign(el) {
54+
return el.id;
55+
});
56+
57+
for (i = 0; i < elements.length; i++) {
58+
59+
if (elements[i].hasAttribute('id')) {
60+
elementID = elements[i].getAttribute('id');
61+
} else {
62+
roughText = elements[i].textContent;
63+
64+
// Refine it so it makes a good ID. Strip out non-safe characters, replace
65+
// spaces with hyphens, truncate to 32 characters, and make toLowerCase.
66+
//
67+
// Example string: // '⚡⚡⚡ Unicode icons are cool--but they definitely don't belong in a URL fragment.'
68+
tidyText = roughText.replace(/[^\w\s-]/gi, '') // ' Unicode icons are cool--but they definitely dont belong in a URL fragment'
69+
.replace(/\s+/g, '-') // '-Unicode-icons-are-cool--but-they-definitely-dont-belong-in-a-URL-fragment'
70+
.replace(/-{2,}/g, '-') // '-Unicode-icons-are-cool-but-they-definitely-dont-belong-in-a-URL-fragment'
71+
.substring(0, 64) // '-Unicode-icons-are-cool-but-they-definitely-dont-belong-in-a-URL'
72+
.replace(/^-+|-+$/gm, '') // 'Unicode-icons-are-cool-but-they-definitely-dont-belong-in-a-URL'
73+
.toLowerCase(); // 'unicode-icons-are-cool-but-they-definitely-dont-belong-in-a-url'
74+
75+
// Compare our generated ID to existing IDs (and increment it if needed)
76+
// before we add it to the page.
77+
newTidyText = tidyText;
78+
count = 0;
79+
do {
80+
if (index !== undefined) {
81+
newTidyText = tidyText + '-' + count;
82+
}
83+
// .indexOf is supported in IE9+.
84+
index = idList.indexOf(newTidyText);
85+
count += 1;
86+
} while (index !== -1);
87+
index = undefined;
88+
idList.push(newTidyText);
89+
90+
// Assign it to our element.
91+
// Currently the setAttribute element is only supported in IE9 and above.
92+
elements[i].setAttribute('id', newTidyText);
93+
94+
elementID = newTidyText;
95+
}
96+
97+
readableID = elementID.replace(/-/g, ' ');
98+
99+
// The following code builds the following DOM structure in a more effiecient (albeit opaque) way.
100+
// '<a class="anchorjs-link ' + this.options.class + '" href="#' + elementID + '" aria-label="Anchor link for: ' + readableID + '" data-anchorjs-icon="' + this.options.icon + '"></a>';
101+
anchor = document.createElement('a');
102+
anchor.className = 'anchorjs-link ' + this.options.class;
103+
anchor.href = '#' + elementID;
104+
anchor.setAttribute('aria-label', 'Anchor link for: ' + readableID);
105+
anchor.setAttribute('data-anchorjs-icon', this.options.icon);
106+
107+
if (this.options.visible === 'always') {
108+
anchor.style.opacity = '1';
109+
}
110+
111+
if (this.options.icon === '\ue9cb') {
112+
anchor.style.fontFamily = 'anchorjs-icons';
113+
anchor.style.fontStyle = 'normal';
114+
anchor.style.fontVariant = 'normal';
115+
anchor.style.fontWeight = 'normal';
116+
anchor.style.lineHeight = 1;
117+
}
118+
119+
if (this.options.placement === 'left') {
120+
anchor.style.position = 'absolute';
121+
anchor.style.marginLeft = '-1em';
122+
anchor.style.paddingRight = '0.5em';
123+
elements[i].insertBefore(anchor, elements[i].firstChild);
124+
} else { // if the option provided is `right` (or anything else).
125+
anchor.style.paddingLeft = '0.375em';
126+
elements[i].appendChild(anchor);
127+
}
128+
}
129+
130+
return this;
131+
};
132+
133+
this.remove = function(selector) {
134+
var domAnchor,
135+
elements = document.querySelectorAll(selector);
136+
for (var i = 0; i < elements.length; i++) {
137+
domAnchor = elements[i].querySelector('.anchorjs-link');
138+
if (domAnchor) {
139+
elements[i].removeChild(domAnchor);
140+
}
141+
}
142+
return this;
143+
};
144+
145+
this._addBaselineStyles = function() {
146+
// We don't want to add global baseline styles if they've been added before.
147+
if (document.head.querySelector('style.anchorjs') !== null) {
148+
return;
149+
}
150+
151+
var style = document.createElement('style'),
152+
linkRule =
153+
' .anchorjs-link {' +
154+
' opacity: 0;' +
155+
' text-decoration: none;' +
156+
' -webkit-font-smoothing: antialiased;' +
157+
' -moz-osx-font-smoothing: grayscale;' +
158+
' }',
159+
hoverRule =
160+
' *:hover > .anchorjs-link,' +
161+
' .anchorjs-link:focus {' +
162+
' opacity: 1;' +
163+
' }',
164+
anchorjsLinkFontFace =
165+
' @font-face {' +
166+
' font-family: "anchorjs-icons";' +
167+
' font-style: normal;' +
168+
' font-weight: normal;' + // Icon from icomoon; 10px wide & 10px tall; 2 empty below & 4 above
169+
' src: url(data:application/x-font-ttf;charset=utf-8;base64,AAEAAAALAIAAAwAwT1MvMg8SBTUAAAC8AAAAYGNtYXAWi9QdAAABHAAAAFRnYXNwAAAAEAAAAXAAAAAIZ2x5Zgq29TcAAAF4AAABNGhlYWQEZM3pAAACrAAAADZoaGVhBhUDxgAAAuQAAAAkaG10eASAADEAAAMIAAAAFGxvY2EAKACuAAADHAAAAAxtYXhwAAgAVwAAAygAAAAgbmFtZQ5yJ3cAAANIAAAB2nBvc3QAAwAAAAAFJAAAACAAAwJAAZAABQAAApkCzAAAAI8CmQLMAAAB6wAzAQkAAAAAAAAAAAAAAAAAAAABEAAAAAAAAAAAAAAAAAAAAABAAADpywPA/8AAQAPAAEAAAAABAAAAAAAAAAAAAAAgAAAAAAADAAAAAwAAABwAAQADAAAAHAADAAEAAAAcAAQAOAAAAAoACAACAAIAAQAg6cv//f//AAAAAAAg6cv//f//AAH/4xY5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8AbgBzUmVndWxhcgBSAGUAZwB1AGwAYQByYW5jaG9yanMtaWNvbnMAYQBuAGMAaABvAHIAagBzAC0AaQBjAG8AbgBzRm9udCBnZW5lcmF0ZWQgYnkgSWNvTW9vbi4ARgBvAG4AdAAgAGcAZQBuAGUAcgBhAHQAZQBkACAAYgB5ACAASQBjAG8ATQBvAG8AbgAuAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==) format("truetype");' +
170+
' }',
171+
pseudoElContent =
172+
' [data-anchorjs-icon]::after {' +
173+
' content: attr(data-anchorjs-icon);' +
174+
' }',
175+
firstStyleEl;
176+
177+
style.className = 'anchorjs';
178+
style.appendChild(document.createTextNode('')); // Necessary for Webkit.
179+
180+
// We place it in the head with the other style tags, if possible, so as to
181+
// not look out of place. We insert before the others so these styles can be
182+
// overridden if necessary.
183+
firstStyleEl = document.head.querySelector('[rel="stylesheet"], style');
184+
if (firstStyleEl === undefined) {
185+
document.head.appendChild(style);
186+
} else {
187+
document.head.insertBefore(style, firstStyleEl);
188+
}
189+
190+
style.sheet.insertRule(linkRule, style.sheet.cssRules.length);
191+
style.sheet.insertRule(hoverRule, style.sheet.cssRules.length);
192+
style.sheet.insertRule(pseudoElContent, style.sheet.cssRules.length);
193+
style.sheet.insertRule(anchorjsLinkFontFace, style.sheet.cssRules.length);
194+
};
195+
}
196+
197+
var anchors = new AnchorJS();

0 commit comments

Comments
 (0)