Skip to content

Commit da432e3

Browse files
Merge branch 'es6'
2 parents 4729868 + 9e11784 commit da432e3

File tree

11 files changed

+160
-144
lines changed

11 files changed

+160
-144
lines changed

.gitignore

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
node_modules
1+
/assets/css/main.css.map
2+
/dist
3+
/node_modules
4+
/sassdoc
25
.DS_Store
36
.sass-cache
47
npm-debug.log
5-
assets/css/main.css.map
6-
sassdoc/

.jshintrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"esnext": true
3+
}

Makefile

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
1-
SASS = sass
2-
UGLIFY = node_modules/uglify-js/bin/uglifyjs
1+
PATH := $(PWD)/node_modules/.bin:$(PATH)
32

4-
all: sass min
3+
SOURCES := $(wildcard src/*.js)
4+
DIST := $(SOURCES:src/%=dist/%)
5+
6+
all: lint dist min sass
7+
8+
lint:
9+
jshint $(SOURCES)
10+
11+
dist: $(DIST)
12+
13+
dist/%.js: src/%.js
14+
mkdir -p $(@D)
15+
6to5 --optional selfContained $< -o $@
516

617
min: assets/js/main.min.js
718

@@ -11,10 +22,12 @@ assets/js/main.min.js: \
1122
assets/js/search.js \
1223
assets/js/main.js \
1324
assets/js/vendor/prism.min.js
14-
cat $^ | $(UGLIFY) > $@
25+
cat $^ | uglifyjs > $@
1526

1627
sass:
17-
$(SASS) --update scss:assets/css --style compressed
28+
sass --update scss:assets/css --style compressed
1829

1930
clean:
20-
$(RM) -r assets/js/main.min.js assets/css
31+
rm -rf $(DIST) assets/js/main.min.js assets/css
32+
33+
.PHONY: all dist min sass clean

default.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
{
22
"display": {
3+
"annotations": {
4+
"function": ["description", "parameter", "return", "example", "throw", "require", "usedby", "since", "see", "todo", "link", "author"],
5+
"mixin": ["description", "parameter", "content", "output", "example", "throw", "require", "usedby", "since", "see", "todo", "link", "author"],
6+
"placeholder": ["description", "example", "throw", "require", "usedby", "since", "see", "todo", "link", "author"],
7+
"variable": ["description", "type", "property", "require", "example", "usedby", "since", "see", "todo", "link", "author"]
8+
},
39
"access": ["public", "private"],
410
"alias": false,
511
"watermark": true

index.js

Lines changed: 0 additions & 124 deletions
This file was deleted.

package.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "SassDoc's default theme",
44
"title": "SassDoc Default Theme",
55
"author": "SassDoc team",
6-
"version": "2.0.2",
6+
"version": "2.0.3",
77
"keywords": [
88
"sassdoc-theme"
99
],
@@ -14,22 +14,27 @@
1414
"files": [
1515
"assets",
1616
"views",
17+
"dist",
1718
"default.json",
1819
"index.js",
1920
"LICENSE.md",
2021
"README.md"
2122
],
23+
"main": "dist",
2224
"dependencies": {
23-
"bluebird": "^2.8.2",
25+
"6to5-runtime": "^3.2.1",
2426
"chroma-js": "^0.6.3",
2527
"extend": "^1.0.0",
28+
"fs-extra": "^0.1.0",
2629
"html-minifier": "^0.6.9",
30+
"promise-denodeify": "^1.2.2",
2731
"sassdoc-extras": "^2.0.0",
2832
"swig": "1.4.0",
29-
"swig-extras": "^0.0.1",
30-
"themeleon": "^3.0.0"
33+
"swig-extras": "^0.0.1"
3134
},
3235
"devDependencies": {
36+
"6to5": "^3.2.1",
37+
"jshint": "^2.6.0",
3338
"uglify-js": "^2.4.15"
3439
}
3540
}

src/index.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import chroma from 'chroma-js';
2+
import def from '../default';
3+
import denodeify from 'promise-denodeify';
4+
import extend from 'extend';
5+
import fs from 'fs';
6+
import fse from 'fs-extra';
7+
import { minify } from 'html-minifier';
8+
import path from 'path';
9+
import sassdocExtras from 'sassdoc-extras';
10+
import swig from './swig';
11+
12+
const copy = denodeify(fse.copy, Promise);
13+
const renderFile = denodeify(swig.renderFile, Promise);
14+
const writeFile = denodeify(fs.writeFile, Promise);
15+
16+
const applyDefaults = ctx =>
17+
extend({}, def, ctx, {
18+
groups: extend(def.groups, ctx.groups),
19+
display: extend(def.display, ctx.display),
20+
});
21+
22+
const shortcutIcon = (dest, ctx) => {
23+
if (!ctx.shortcutIcon) {
24+
ctx.shortcutIcon = { type: 'internal', url: 'assets/images/favicon.png' };
25+
} else if (ctx.shortcutIcon.type === 'internal') {
26+
ctx.shortcutIcon.url = 'assets/images/' + ctx.shortcutIcon.url;
27+
28+
return () =>
29+
copy(ctx.shortcutIcon.path, path.resolve(dest, ctx.shortcutIcon.url));
30+
}
31+
};
32+
33+
export default (dest, ctx) => {
34+
ctx = applyDefaults(ctx);
35+
36+
sassdocExtras.markdown(ctx);
37+
sassdocExtras.display(ctx);
38+
sassdocExtras.groupName(ctx);
39+
sassdocExtras.shortcutIcon(ctx);
40+
41+
ctx.data.byGroupAndType = sassdocExtras.byGroupAndType(ctx.data);
42+
43+
const index = path.resolve(__dirname, '../views/documentation/index.html.swig');
44+
45+
return Promise.all([
46+
copy(path.resolve(__dirname, '../assets'), path.resolve(dest, 'assets'))
47+
.then(shortcutIcon(dest, ctx)),
48+
49+
renderFile(index, ctx)
50+
.then(html => minify(html, { collapseWhitespace: true }))
51+
.then(html => writeFile(path.resolve(dest, 'index.html'), html)),
52+
]);
53+
};

src/swig.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import assert from 'assert';
2+
import chroma from 'chroma-js';
3+
import { Swig } from 'swig';
4+
import swigExtras from 'swig-extras';
5+
import swigFilters from 'swig/lib/filters';
6+
7+
const swig = new Swig();
8+
export default swig;
9+
10+
swigExtras.useFilter(swig, 'split');
11+
swigExtras.useFilter(swig, 'trim');
12+
swigExtras.useFilter(swig, 'groupby');
13+
14+
const safe = fn =>
15+
fn.safe = true && fn;
16+
17+
const isColor = value => {
18+
try {
19+
chroma(value);
20+
return true;
21+
} catch (e) {
22+
return false;
23+
}
24+
};
25+
26+
const displayAsType = input =>
27+
input.split('|')
28+
.map(x => x.trim())
29+
.map(swigFilters.capitalize)
30+
.join('</code> or <code>');
31+
32+
const yiq = ([red, green, blue]) =>
33+
((red * 299) + (green * 587) + (blue * 114)) / 1000;
34+
35+
const yiqContrast = rgb =>
36+
(yiq(rgb) >= 128) ? '#000' : '#fff';
37+
38+
const getChannel = (start, hex) =>
39+
parseInt(hex.substr(start, 2), 16);
40+
41+
const hexTorgb = hex =>
42+
[0, 2, 4].map(x => getChannel(x, hex));
43+
44+
const colorToHex = color =>
45+
chroma(color).hex().substr(1);
46+
47+
/**
48+
* Normalises a CSS color, then uses the YIQ algorithm to get the
49+
* correct contrast.
50+
*
51+
* @param {String} color
52+
* @return {String} `#000` or `#fff` depending on which one is a better.
53+
* @see {@link http://stackoverflow.com/questions/11867545/change-text-color-based-on-brightness-of-the-covered-background-area}
54+
*/
55+
const maybeYiqContrast = color =>
56+
isColor(color) ?
57+
yiqContrast(hexToRgb(colorToHex(color))) :
58+
'#000';
59+
60+
swig.setFilter('in', (key, object) => key in object);
61+
swig.setFilter('is_color', isColor);
62+
swig.setFilter('display_as_type', safe(displayAsType));
63+
swig.setFilter('yiq', maybeYiqContrast);

views/includes/partials/footer.html.swig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
{% if display.watermark %}
3434
<a class="footer__watermark" href="http://sassdoc.com">
35-
<img src="{{ base }}/assets/images/logo_light_inline.svg" alt="SassDoc Logo" />
35+
<img src="assets/images/logo_light_inline.svg" alt="SassDoc Logo" />
3636
</a>
3737
{% endif %}
3838
</div>
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
<meta charset="utf-8" />
22

33
<title>{{ project_title }}{% if package.version %} - v{{ package.version }}{% endif %}</title>
4-
<link rel="stylesheet" href="{{ base }}/assets/css/main.css" />
4+
<link rel="stylesheet" href="assets/css/main.css" />
55
<link href='http://fonts.googleapis.com/css?family=Open+Sans:400,500,700' rel='stylesheet' type='text/css'>
66
<meta name="viewport" content="width=device-width">
77
<meta content="IE=edge, chrome=1" http-equiv="X-UA-Compatible">
88

99
<!-- Thanks to Sass-lang.com for the icons -->
10-
{% if shortcutIcon.type == 'internal' %}
11-
<link href="{{ base }}/{{ shortcutIcon.url }}" rel="shortcut icon">
12-
{% else %}
1310
<link href="{{ shortcutIcon.url }}" rel="shortcut icon">
14-
{% endif %}

0 commit comments

Comments
 (0)