mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-16 23:30:23 +00:00
proper trimming of leading whitespace; url restriction to angular.*
This commit is contained in:
parent
324694a58b
commit
a7e8a503fd
3 changed files with 55 additions and 8 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue