Skip to content

Commit

Permalink
Docs improvements: Build-time Syntax highlighting, scroll perf improv…
Browse files Browse the repository at this point in the history
…ements, docs dev/deployment fixes (#38)
  • Loading branch information
lazd authored Dec 5, 2018
2 parents bb27003 + 4cb2240 commit 0312550
Show file tree
Hide file tree
Showing 15 changed files with 154 additions and 554 deletions.
186 changes: 119 additions & 67 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"postcss-nested": "^3.0.0",
"postcss-remtopx": "^1.0.0",
"postcss-svg": "^2.1.0",
"prismjs": "^1.15.0",
"readable-stream": "^2.3.5",
"run-sequence": "^1.2.2",
"svgmin": "^0.1.0",
Expand Down
9 changes: 9 additions & 0 deletions tasks/build-docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ gulp.task('build-docs:copy-site-resources', function() {
.pipe(gulp.dest('dist/docs'));
});

gulp.task('build-docs:copy-prism-resources', function() {
return gulp.src([
'node_modules/prismjs/themes/prism.css',
'node_modules/prismjs/themes/prism-tomorrow.css'
])
.pipe(gulp.dest('dist/docs/css/vendor/'));
});


gulp.task('build-docs:copy-polyfill', function() {
return gulp.src([
Expand Down Expand Up @@ -76,6 +84,7 @@ gulp.task('build-docs',
'build-docs:topdoc',
gulp.parallel(
'build-docs:copy-site-resources',
'build-docs:copy-prism-resources',
'build-docs:copy-polyfill',
'build-docs:copy-spectrum-icons'
),
Expand Down
4 changes: 2 additions & 2 deletions tasks/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ function watch() {
'docs/**/*.yml',
'topdoc/lib/template.pug',
'topdoc/lib/index.js',
'../topdoc/resources/js/*.js'
'topdoc/resources/js/*.js'
], gulp.series('reload-docs'));

gulp.watch([
'../topdoc/resources/css/*.css'
'topdoc/resources/css/*.css'
], gulp.series('reload-docs-css'));

gulp.watch('icons/*.svg', gulp.series('reload-icons'));
Expand Down
4 changes: 2 additions & 2 deletions tasks/gh-pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ var package = JSON.parse(fs.readFileSync('./package.json'));
* Replace the redirect path to latest version
*/
gulp.task('gh-pages:prepare-docs', function () {
return gulp.src('../topdoc/resources/gh-pages.html')
return gulp.src('topdoc/resources/gh-pages.html')
.pipe(template({ version: package.version }))
.pipe(rename('index.html'))
.pipe(gulp.dest('./temp'));
});

gulp.task('gh-pages:prepare-icons', function () {
return gulp.src('../topdoc/resources/gh-pages-icons.html')
return gulp.src('topdoc/resources/gh-pages-icons.html')
.pipe(template({ version: package.version }))
.pipe(rename('index.html'))
.pipe(gulp.dest('./temp/icons/'));
Expand Down
10 changes: 10 additions & 0 deletions topdoc/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var pug = require('pug');
var path = require('path');
var markdown = require('markdown').markdown;
var fsExtra = require('fs-extra');
var Prism = require('prismjs');

const labelColors = {
'Deprecated': 'red',
Expand Down Expand Up @@ -46,6 +47,13 @@ function replaceExt(npath, ext) {
return path.join(path.dirname(npath), nFileName);
}

function processMarkup(markup) {
if (markup) {
return Prism.highlight(markup, Prism.languages.markup, 'markup');
}
return '';
}

/**
* Public: creates docs using topDocument data with a pug template.
*
Expand Down Expand Up @@ -120,6 +128,7 @@ function template(topDocument) {
// Add other data
component.id = dnaComponentId;
component.description = component.description || '';
component.highlightedMarkup = processMarkup(component.markup);

if (component.components) {
var extraComponentDescriptions = '';
Expand All @@ -128,6 +137,7 @@ function template(topDocument) {
if (typeof component.components[subComponentId] === 'string') {
// Shorthand
subComponent.markup = component.components[subComponentId];
subComponent.highlightedMarkup = processMarkup(subComponent.markup);
subComponent.id = subComponentId;
}
else {
Expand Down
7 changes: 3 additions & 4 deletions topdoc/lib/template.pug
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ html.spectrum--medium
title Spectrum CSS Documentation
meta(name="viewport", content="user-scalable=no,initial-scale = 1.0,maximum-scale = 1.0")

link(rel='stylesheet', type='text/css', href='css/vendor/github.css', data-rainbow)
link(rel='stylesheet', type='text/css', href='css/vendor/prism.css', data-prism)
link(rel='stylesheet', type='text/css', href='../spectrum-core.css', data-spectrum-core)
link(rel='stylesheet', type='text/css', href='', data-spectrum-core-diff)
link(rel='stylesheet', type='text/css', href='../spectrum-lightest.css')
Expand Down Expand Up @@ -121,7 +121,7 @@ html.spectrum--medium
if subComponent.markup.split('\n').length > 2
a.js-markup-toggle.cssdocs-example-markupToggle.spectrum-Link(href="#") Show Markup
pre
code(data-language="html")=subComponent.markup
code.language-markup!=subComponent.highlightedMarkup


else if component.markup
Expand All @@ -131,9 +131,8 @@ html.spectrum--medium
if component.markup.split('\n').length > 2
a.js-markup-toggle.cssdocs-example-markupToggle.spectrum-Link(href="#") Show Markup
pre
code(data-language="html")=component.markup
code.language-markup!=component.highlightedMarkup

div.spectrum-Underlay#spectrum-underlay

script(type="text/javascript", src='js/vendor/rainbow-custom.min.js')
script(type="text/javascript", src='js/vendor/typekit.js')
6 changes: 6 additions & 0 deletions topdoc/resources/css/docs.css
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ pre code {
white-space: pre-wrap;
}

code[class*="language-"], pre[class*="language-"] {
text-shadow: none;
font-size: 12px;
}

.cssdocs-example-markupToggle {
position: absolute;
z-index: 1;
Expand Down Expand Up @@ -194,6 +199,7 @@ pre code {
overflow-x: hidden;

-webkit-overflow-scrolling: touch;
will-change: transform;
}

.sdldocs-splitview {
Expand Down
1 change: 0 additions & 1 deletion topdoc/resources/css/vendor/blackboard.css

This file was deleted.

1 change: 0 additions & 1 deletion topdoc/resources/css/vendor/github.css

This file was deleted.

Loading

0 comments on commit 0312550

Please sign in to comment.