aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMisko Hevery2010-11-09 11:22:52 -0800
committerIgor Minar2010-11-09 22:27:37 -0800
commita7e8a503fd088f5b01e8b14de61dfc60c1f13451 (patch)
tree7fc39b1a96762ed2d41e3ad9cef8441bb0394844
parent324694a58b6d0ed33e05b511be4767573d9187dd (diff)
downloadangular.js-a7e8a503fd088f5b01e8b14de61dfc60c1f13451.tar.bz2
proper trimming of leading whitespace; url restriction to angular.*
-rw-r--r--docs/collect.js39
-rw-r--r--docs/index.html14
-rw-r--r--docs/spec/collectSpec.js10
3 files changed, 55 insertions, 8 deletions
diff --git a/docs/collect.js b/docs/collect.js
index acfdf008..2d43669a 100644
--- a/docs/collect.js
+++ b/docs/collect.js
@@ -13,6 +13,7 @@ var documentation = {
var SRC_DIR = "docs/";
var OUTPUT_DIR = "build/docs/";
+var NEW_LINE = /\n\r?/;
var work = callback.chain(function () {
console.log('Parsing Angular Reference Documentation');
@@ -80,8 +81,35 @@ function mergeTemplate(template, output, doc, callback){
}
-function trim(string) {
- return string.replace(/^[\s\n\r]+/g, '').replace(/[\s\n\r]+$/g, '');
+function trim(text) {
+ var MAX = 9999;
+ var empty = RegExp.prototype.test.bind(/^\s*$/);
+ var lines = text.split('\n');
+ var minIndent = MAX;
+ lines.forEach(function(line){
+ minIndent = Math.min(minIndent, indent(line));
+ });
+ for ( var i = 0; i < lines.length; i++) {
+ lines[i] = lines[i].substring(minIndent);
+ }
+ // remove leading lines
+ while (empty(lines[0])) {
+ lines.shift();
+ }
+ // remove trailing
+ while (empty(lines[lines.length - 1])) {
+ lines.pop();
+ }
+ return lines.join('\n');
+
+ function indent(line) {
+ for(var i = 0; i < line.length; i++) {
+ if (line.charAt(i) != ' ') {
+ return i;
+ }
+ }
+ return MAX;
+ }
}
function unknownTag(doc, name) {
@@ -123,7 +151,8 @@ var TAG = {
exampleDescription: markdownTag,
name: function(doc, name, value) {
doc.name = value;
- doc.shortName = value.split(/\./).pop();
+ var match = value.match(/^angular[\.\#](([^\.]+)\.(.*)|(.*))/);
+ doc.shortName = match[3] || match[4];
},
param: function(doc, name, value){
doc.param = doc.param || [];
@@ -153,7 +182,7 @@ function parseNgDoc(doc){
var atName;
var atText;
var match;
- doc.raw.text.split(/\n/).forEach(function(line, lineNumber){
+ doc.raw.text.split(NEW_LINE).forEach(function(line, lineNumber){
if (match = line.match(/^\s*@(\w+)(\s+(.*))?/)) {
// we found @name ...
// if we have existing name
@@ -178,7 +207,7 @@ function parseNgDoc(doc){
function findNgDoc(file, callback) {
fs.readFile(file, callback.waitFor(function(err, content){
- var lines = content.toString().split(/\n\r?/);
+ var lines = content.toString().split(NEW_LINE);
var doc;
var match;
var inDoc = false;
diff --git a/docs/index.html b/docs/index.html
index 07eac809..3495f6c8 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -12,14 +12,22 @@
<link rel="stylesheet" href="http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css" type="text/css" media="screen" />
<script type="text/javascript">
SyntaxHighlighter['defaults'].toolbar = false;
-
- function DocsController() {
+
+ DocsController.$inject = ['$location']
+ function DocsController($location) {
this.docs = NG_DOC;
window.$root = this.$root;
this.getUrl = function(page){
return '#' + encodeURIComponent(page.name);
}
+
+ this.getCurrentPartial = function(){
+ if ($location.hashPath.match(/^angular\./)) {
+ this.partialUrl = './' + $location.hashPath + '.html';
+ }
+ return this.partialUrl;
+ }
}
</script>
</head>
@@ -34,7 +42,7 @@
</div>
</div>
</td>
- <td valign="top"><ng:include src=" './' + $location.hashPath + '.html' "></ng:include></td>
+ <td valign="top"><ng:include src=" getCurrentPartial() "></ng:include></td>
</tr>
</table>
</body>
diff --git a/docs/spec/collectSpec.js b/docs/spec/collectSpec.js
index 371438f5..fbc6c489 100644
--- a/docs/spec/collectSpec.js
+++ b/docs/spec/collectSpec.js
@@ -58,6 +58,16 @@ describe('collect', function(){
});
+ describe('trim', function(){
+ var trim = collect.trim;
+ it('should remove leading/trailing space', function(){
+ expect(trim(' \nabc\n ')).toEqual('abc');
+ });
+
+ it('should remove leading space on every line', function(){
+ expect(trim('\n 1\n 2\n 3\n')).toEqual('1\n 2\n 3');
+ });
+ });
});