Skip to content
This repository was archived by the owner on Aug 3, 2024. It is now read-only.

Commit e1ca329

Browse files
committed
Add compile step that bundles and compresses JS files
Also, manage dependencies on third-party JS libraries using NPM.
1 parent fe4c6c7 commit e1ca329

File tree

105 files changed

+3240
-1999
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+3240
-1999
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919
tags
2020
TAGS
2121

22+
/haddock-api/resources/html/node_modules
23+
2224
.cabal-sandbox
25+
.ghc.environment.*
2326
cabal.sandbox.config
2427

2528
.stack-work/

haddock-api/haddock-api.cabal

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,9 @@ extra-source-files:
2020
data-dir:
2121
resources
2222
data-files:
23-
html/index.js
24-
html/fuse.js
25-
html/preact.js
23+
html/quick-jump.min.js
24+
html/haddock-bundle.min.js
2625
html/solarized.css
27-
html/haddock-util.js
2826
html/highlight.js
2927
html/Classic.theme/haskell_icon.gif
3028
html/Classic.theme/minus.gif

haddock-api/resources/html/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Compiling
2+
3+
* Install [node](https://nodejs.org/) and [npm](https://www.npmjs.com)
4+
* Run `npm install` and `npm install gulp-cli -g` in this directory.
5+
* Run `gulp` in this directory. This rebuilds the minified JS files.
6+
7+
# Manual Testing
8+
9+
Generate haddock docs for some Haskell project and replace the generated JS files:
10+
11+
```
12+
gulp && cp *.min.js path-to/generated-haddock-docs
13+
```

haddock-api/resources/html/fuse.js

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const gulp = require('gulp');
2+
const uglify = require('gulp-uglify');
3+
const browserify = require('browserify');
4+
const source = require('vinyl-source-stream');
5+
const buffer = require('vinyl-buffer');
6+
7+
function buildJS(targetFileName, files) {
8+
var b = browserify({ entries: files });
9+
return b
10+
.bundle()
11+
.pipe(source(targetFileName))
12+
.pipe(buffer())
13+
.pipe(uglify().on('error', function(e) { console.log(e); }))
14+
.pipe(gulp.dest('.'));
15+
}
16+
17+
gulp.task('build-js', function() {
18+
buildJS('quick-jump.min.js', ['./js-src/quick-jump.js']);
19+
buildJS('haddock-bundle.min.js', ['./js-src/init.js']);
20+
});
21+
22+
gulp.task('default', ['build-js']);

haddock-api/resources/html/haddock-bundle.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

haddock-api/resources/html/haddock-util.js renamed to haddock-api/resources/html/js-src/haddock-util.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ function toggleSection(id)
5656
return b;
5757
}
5858

59+
// TODO: get rid of global variables
60+
if (typeof window !== 'undefined') { window.toggleSection = toggleSection; }
61+
5962
var collapsed = {};
6063
function rememberCollapsed(id)
6164
{
@@ -88,6 +91,8 @@ function restoreCollapsed()
8891
}
8992
}
9093

94+
exports.restoreCollapsed = restoreCollapsed;
95+
9196
function setCookie(name, value) {
9297
document.cookie = name + "=" + escape(value) + ";path=/;";
9398
}
@@ -145,6 +150,8 @@ function addStyleMenu() {
145150
}
146151
}
147152

153+
exports.addStyleMenu = addStyleMenu;
154+
148155
function setActiveStyleSheet(title) {
149156
var as = styles();
150157
var i, a, found;
@@ -171,16 +178,9 @@ function resetStyle() {
171178
if (s) setActiveStyleSheet(s);
172179
}
173180

181+
exports.resetStyle = resetStyle;
174182

175183
function styleMenu(show) {
176184
var m = document.getElementById('style-menu');
177185
if (m) toggleShow(m, show);
178-
}
179-
180-
181-
function pageLoad() {
182-
addStyleMenu();
183-
resetStyle();
184-
restoreCollapsed();
185-
}
186-
186+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
var util = require('./haddock-util');
2+
var quickJump = require('./quick-jump');
3+
4+
function onDomReady(callback) {
5+
if (document.readyState === 'interactive') {
6+
callback();
7+
} else {
8+
document.addEventListener('readystatechange', function () {
9+
if (document.readyState === 'interactive') {
10+
callback();
11+
}
12+
});
13+
}
14+
}
15+
16+
onDomReady(function() {
17+
util.addStyleMenu();
18+
util.resetStyle();
19+
util.restoreCollapsed();
20+
quickJump.init();
21+
});

haddock-api/resources/html/index.js renamed to haddock-api/resources/html/js-src/quick-jump.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
var Fuse = require('fuse.js');
2+
var preact = require('preact');
3+
14
quickNav = (function() {
25

36
var baseUrl;
@@ -230,7 +233,7 @@ var App = createClass({
230233
onFocus: this.show.bind(this),
231234
onClick: this.show.bind(this),
232235
onInput: this.updateResults.bind(this)
233-
}),
236+
})
234237
),
235238
h('div', {
236239
id: 'search-results',
@@ -276,8 +279,8 @@ var App = createClass({
276279
: h('li', { class: 'more-results' },
277280
this.actionLink(expand, {}, "show " + (items.length - visibleItems.length) + " more results from this module")
278281
)
279-
),
280-
)
282+
)
283+
);
281284
},
282285

283286
navigationLink: function(href, attrs) {
@@ -355,13 +358,13 @@ var KeyboardShortcuts = function() {
355358
h('tr', null,
356359
h('td', null, h('span', { class: 'key' }, "↵")),
357360
h('td', null, "Go to active search result")
358-
),
361+
)
359362
);
360363
};
361364

362365
var IntroMsg = function() {
363366
return h('p', null,
364-
"You can find any exported type, constructor, class, function or pattern defined in this package by (approximate) name.",
367+
"You can find any exported type, constructor, class, function or pattern defined in this package by (approximate) name."
365368
);
366369
};
367370

@@ -374,10 +377,10 @@ var NoResultsMsg = function(props) {
374377
),
375378
h('p', null,
376379
h('code', null, 'Nothing'),
377-
" matches your query for '" + props.searchString + "'.",
380+
" matches your query for '" + props.searchString + "'."
378381
),
379382
h('p', null,
380-
h('code', null, 'Left "no matches for \'' + props.searchString + '\'" :: Either String (NonEmpty SearchResult)'),
383+
h('code', null, 'Left "no matches for \'' + props.searchString + '\'" :: Either String (NonEmpty SearchResult)')
381384
)
382385
];
383386

@@ -392,3 +395,5 @@ return {
392395
}
393396
}
394397
})();
398+
399+
if (typeof exports === 'object') { exports.init = quickNav.init; }

0 commit comments

Comments
 (0)