From b467a50bc75b7f4c0d9bcee521387eda460337bf Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 15 Nov 2010 12:15:27 -0800 Subject: generate keyword for searches; improved layout of doc --- docs/collect.js | 31 ++++++- docs/docs-data.js | 2 +- docs/docs.css | 127 +++++++++++++++++++++++++++++ docs/docs.js | 37 +++++++-- docs/index.html | 205 ++++++----------------------------------------- docs/spec/collectSpec.js | 8 ++ src/Injector.js | 5 +- 7 files changed, 225 insertions(+), 190 deletions(-) create mode 100644 docs/docs.css diff --git a/docs/collect.js b/docs/collect.js index 29d2a33f..4e845f5b 100644 --- a/docs/collect.js +++ b/docs/collect.js @@ -9,6 +9,8 @@ var fs = require('fs'), var documentation = { pages:[] }; +var keywordPages = []; + var SRC_DIR = "docs/"; var OUTPUT_DIR = "build/docs/"; @@ -22,7 +24,11 @@ var work = callback.chain(function () { findNgDoc(file, work.waitMany(function(doc) { parseNgDoc(doc); if (doc.ngdoc) { - delete doc.raw.text; + keywordPages.push({ + name:doc.name, + keywords:keywords(doc.raw.text) + } + ); documentation.pages.push(doc); console.log('Found:', doc.ngdoc + ':' + doc.shortName); mergeTemplate( @@ -35,11 +41,12 @@ var work = callback.chain(function () { }).onError(function(err){ console.log('ERROR:', err.stack || err); }).onDone(function(){ - documentation.pages.sort(function(a,b){ return a.name == b.name ? 0:(a.name < b.name ? -1 : 1);}); - mergeTemplate('docs-data.js', 'docs-data.js', {JSON:JSON.stringify(documentation)}, callback.chain()); + keywordPages.sort(function(a,b){ return a.name == b.name ? 0:(a.name < b.name ? -1 : 1);}); + mergeTemplate('docs-data.js', 'docs-data.js', {JSON:JSON.stringify(keywordPages)}, callback.chain()); mergeTemplate('docs-scenario.js', 'docs-scenario.js', documentation, callback.chain()); copy('docs-scenario.html', callback.chain()); copy('index.html', callback.chain()); + copy('docs.css', callback.chain()); mergeTemplate('docs.js', 'docs.js', documentation, callback.chain()); mergeTemplate('doc_widgets.css', 'doc_widgets.css', documentation, callback.chain()); mergeTemplate('doc_widgets.js', 'doc_widgets.js', documentation, callback.chain()); @@ -48,6 +55,24 @@ var work = callback.chain(function () { if (!this.testmode) work(); //////////////////// +function keywords(text){ + var keywords = {}; + var words = []; + var tokens = text.toLowerCase().split(/[,\.\`\'\"\s]+/mg); + tokens.forEach(function(key){ + var match = key.match(/^(([a-z]|ng\:)[\w\_\-]{2,})/); + if (match){ + key = match[1]; + if (!keywords[key]) { + keywords[key] = true; + words.push(key); + } + } + }); + words.sort(); + return words.join(' '); +} + function noop(){} function mkdirPath(path, callback) { var parts = path.split(/\//); diff --git a/docs/docs-data.js b/docs/docs-data.js index 27b3fab5..62feb2e9 100644 --- a/docs/docs-data.js +++ b/docs/docs-data.js @@ -1 +1 @@ -NG_DOC={{{JSON}}}; \ No newline at end of file +NG_PAGES={{{JSON}}}; \ No newline at end of file diff --git a/docs/docs.css b/docs/docs.css new file mode 100644 index 00000000..25a8ffea --- /dev/null +++ b/docs/docs.css @@ -0,0 +1,127 @@ +body { + font-family: Arial, sans-serif; + font-size: 14px; + margin: 0; + padding: 0; +} + +#page { + display: table-row; +} + +#sidebar, +#section { + display: table-cell; +} + +a { + color: blue; +} + +.nav-section { + margin-left: 1em; + margin-top: 0.5em; +} + +.section-title { + float: right; +} + +#header { + background-color: #F2C200; + border-bottom: 1px solid #957800; +} + +#header h1 { + font-weight: normal; + font-size: 30px; + line-height: 30px; + margin: 0; + padding: 10px 10px; + height: 30px; +} + +#header .angular { + font-family: Courier New, monospace; + font-weight: bold; +} + +#header h1 a { + color: black; + text-decoration: none; +} + +#header h1 a:hover { + text-decoration: underline; +} + +#section { + padding: 1em; +} + +#section h1 { + font-family: monospace; + margin-top: 0; + padding-bottom: 5px; + border-bottom: 1px solid #CCC; +} + +#sidebar { + padding: 10px; + background-color: #EEE; + border-right: 1px solid #DDD; +} + +#sidebar a { + text-decoration: none; +} + +#sidebar a:hover { + text-decoration: underline; +} + +#sidebar input { + width: 175px; + margin-bottom: 1em; +} + +#sidebar ul { + list-style-type: none; + /*TODO(esprehn): Can we just reset globally and not break examples?*/ + margin: 0; + padding: 0; +} + +#sidebar ul li { +} + +#sidebar ul li a { + display: block; + padding: 2px 2px 2px 4px; +} + +#sidebar ul li.selected a { + background-color: #DDD; + border-radius: 5px; + -moz-border-radius: 5px; + border: 1px solid #CCC; + padding: 1px 1px 1px 3px; +} + +#sidebar ul li.level-0 { + margin-left: 0em; + font-weight: bold; + font-size: 1.2em; +} + +#sidebar ul li.level-1 { + margin-left: 1em; + margin-top: 5px; + font-size: 1.1em; + font-weight: bold; +} + +#sidebar ul li.level-2 { + margin-left: 2em; + font-family: monospace; +} diff --git a/docs/docs.js b/docs/docs.js index 6f5c5034..96fba9cc 100644 --- a/docs/docs.js +++ b/docs/docs.js @@ -1,7 +1,34 @@ -function DocController($resource, $location){ - this.docs = $resource('documentation.json').get(); - this.getPartialDoc = function(){ - return encodeURIComponent($location.hashPath) + '.html'; +SyntaxHighlighter['defaults'].toolbar = false; + +DocsController.$inject = ['$location', '$browser']; +function DocsController($location, $browser) { + this.pages = NG_PAGES; + window.$root = this.$root; + + this.getUrl = function(page){ + return '#!' + encodeURIComponent(page.name); }; + + this.getCurrentPartial = function(){ + return './' + this.getTitle() + '.html'; + }; + + this.getTitle = function(){ + var hashPath = $location.hashPath || '!angular'; + if (hashPath.match(/^!angular/)) { + this.partialTitle = hashPath.substring(1); + } + return this.partialTitle; + }; + + this.getClass = function(page) { + var depth = page.name.split(/\./).length - 1; + return 'level-' + depth + + (page.name == this.getTitle() ? ' selected' : ''); + }; + } -DocController.$inject=['$resource', '$location']; \ No newline at end of file + +angular.filter('short', function(name){ + return (name||'').split(/\./).pop(); +}); \ No newline at end of file diff --git a/docs/index.html b/docs/index.html index 75513db7..31630474 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1,179 +1,24 @@
-