Skip to content

Commit

Permalink
Client side JavaScript for documentation pages
Browse files Browse the repository at this point in the history
Build dependencies with Ender.
Handle minification in script.
  • Loading branch information
jacobrask committed Jun 22, 2012
1 parent d472f36 commit 6df5ee6
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules/
resources/docs.js
shared/ender*
test-browser/tests.js
2 changes: 1 addition & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
src/
node_modules/
test/
test-browser/
examples/
13 changes: 6 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ all: build

build: resources/docs.js

resources/docs.js: src
@cp -r ./src/vendor/client/*.js ./lib/client/
@cat ./lib/client/zepto.min.js > docs.js.tmp
@cat ./lib/client/underscore-min.js >> docs.js.tmp
@cat ./lib/client/docs.js >> docs.js.tmp
@./node_modules/.bin/uglifyjs --overwrite docs.js.tmp
@mv docs.js.tmp ./resources/docs.js
shared/ender.js:
@ender build -o shared/ender.js domready bonzo qwery underscore

resources/docs.js: shared/docs.js shared/ender.js
@cat shared/ender.js > resources/docs.js
@cat shared/docs.js >> resources/docs.js

test:
@./node_modules/.bin/nodeunit test
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,4 @@ See the `examples` folder for more in-depth examples.

## Acknowledgements

A lot of the heavy lifting in StyleDocco is done by the excellent [Marked](https://github.com/chjj/marked) module by Christopher Jeffrey. The original [Docco](https://github.com/jashkenas/docco) by Jeremy Ashkenas and [Docco Husky](https://github.com/mbrevoort/docco-husky) by Mike Brevoort were also of great help to this project. [Knyle Style Sheets](https://github.com/kneath/kss), a similar project written in Ruby, has also been an inspiration to StyleDocco.
A lot of the heavy lifting in StyleDocco is done by the excellent [Marked](https://github.com/chjj/marked) module by Christopher Jeffrey. The original [Docco](https://github.com/jashkenas/docco) by Jeremy Ashkenas and [Knyle Style Sheets](https://github.com/kneath/kss) have also been sources of inspiration for StyleDocco.
4 changes: 2 additions & 2 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var jade = require('jade');
var marked = require('marked');
var mkdirp = require('mkdirp');
var path = require('path');
var uglify = require('uglify-js');

var styledocco = require('./styledocco');

Expand Down Expand Up @@ -72,7 +73,6 @@ var menuLinks = function(files, basePath) {
}, {});
};


var cli = function(options) {

// Config
Expand Down Expand Up @@ -124,7 +124,7 @@ var cli = function(options) {
sections: sections,
project: { name: options.name, menu: menu },
css: csso.justDoIt(styledoccoCss + css),
js: js
js: uglify(js)
});
};

Expand Down
30 changes: 30 additions & 0 deletions shared/docs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Scans your stylesheet for pseudo classes and adds a class with the same name.
// Thanks to Knyle Style Sheets for the idea.
$.domReady(function() {
addPseudoClasses();
});

var _ = require('underscore');

var add = function(a, b) { return a + b; };

var addPseudoClasses = function() {
// Compile regular expression.
var pseudos = ['link', 'visited', 'hover', 'active', 'focus', 'target', 'enabled', 'disabled', 'checked'];
var pseudoRe = new RegExp(":((" + pseudos.join(")|(") + "))", "gi");
var processedPseudoClasses = _.toArray(document.styleSheets).filter(function(ss) {
return !(ss.href != null);
}).map(function(ss) {
return _.toArray(ss.cssRules).filter(function(rule) {
// Keep only rules with pseudo classes.
return rule.selectorText && rule.selectorText.match(pseudoRe);
}).map(function(rule) {
// Replace : with . and encoded :
return rule.cssText.replace(pseudoRe, ".\\3A $1");
}).reduce(add);
}).reduce(add, '');
if (processedPseudoClasses.length) {
// Add a new style element with the processed pseudo class styles.
return $('head').append($('<style />').text(processedPseudoClasses));
}
};

0 comments on commit 6df5ee6

Please sign in to comment.