add trimLeftIndent to all makeExample and makeTabs calls

This commit is contained in:
Jay Traband 2015-09-11 01:10:48 -07:00
parent cb136b1028
commit bd2d915248
15 changed files with 49 additions and 90 deletions

View File

@ -1,7 +1,6 @@
//- Mixins and associated functions
mixin makeExample(path, fileName, title, stylePatterns)
- var language = attributes.language || getExtn(fileName);
- var format = attributes.format || "linenums";
- var extPath = getPathToFrags() + path + "/";
@ -26,6 +25,7 @@ mixin makeTabs(path, fileNames, tabNames, stylePatterns)
code-pane(language="#{language}" name="#{tabName}" format="#{format}")
!= getFrag(extPath + fileName + ".md", sps)
- var getFrag = function(fileName, stylePatterns) {
- var frag = partial(fileName);
- if (frag == null) {

View File

@ -34,14 +34,15 @@ module.exports = function regionExtractor() {
}
});
docs.forEach(function(doc) {
var content;
var fragLines, content;
if (doc.endIx) {
content = lines.slice(doc.startIx + 1, doc.endIx).join('\n');
fragLines = lines.slice(doc.startIx + 1, doc.endIx);
} else {
content = lines.slice(doc.startIx + 1).join('\n');
fragLines = lines.slice(doc.startIx + 1);
}
fragLines = trimLeftIndent(fragLines);
content = fragLines.join('\n');
// eliminate all #docregion lines
content = content.replace(nullLinePattern, '');
if (content.substr(-3) === nullLine) {
@ -54,6 +55,31 @@ module.exports = function regionExtractor() {
};
function trimLeftIndent(lines) {
var minIx = 100;
var ok = lines.every(function(line) {
// var ix = line.search(/\S/);
var ix = line.search(/[^ ]/);
if (ix === 0) return false;
if (ix === -1) return true;
if (ix > 0) {
minIx = Math.min(minIx, ix);
}
return true;
});
if ( (!ok) || minIx === 100) return lines;
var result = lines.map(function(line) {
if (line.length > minIx) {
return line.substr(minIx);
} else {
// this can happen if line is all blanks and shorter than mixIx
return line;
}
});
return result;
}
function isCommentLine(line, commentPrefixes) {
return commentPrefixes.some(function(prefix) {
return line.trim().indexOf(prefix) == 0;

View File

@ -1,5 +1,5 @@
```
.Class({
constructor: function () { }
});
.Class({
constructor: function () { }
});
```

View File

@ -1,5 +1,5 @@
```
.Component({
selector: 'my-app'
})
.Component({
selector: 'my-app'
})
```

View File

@ -1,5 +1,5 @@
```
.View({
template: '<h1 id="output">My First Angular 2 App</h1>'
})
.View({
template: '<h1 id="output">My First Angular 2 App</h1>'
})
```

View File

@ -1,3 +0,0 @@
```
angular2_1.bootstrap(AppComponent);
```

View File

@ -1,16 +0,0 @@
```
var AppComponent = (function () {
function AppComponent() {
}
AppComponent = __decorate([
angular2_1.Component({
selector: 'my-app'
}),
angular2_1.View({
template: '<h1 id="output">My First Angular 2 App</h1>'
}),
__metadata('design:paramtypes', [])
], AppComponent);
return AppComponent;
})();
```

View File

@ -1,3 +0,0 @@
```
var angular2_1 = require('angular2/angular2');
```

View File

@ -1,18 +0,0 @@
```
var angular2_1 = require('angular2/angular2');
var AppComponent = (function () {
function AppComponent() {
}
AppComponent = __decorate([
angular2_1.Component({
selector: 'my-app'
}),
angular2_1.View({
template: '<h1 id="output">My First Angular 2 App</h1>'
}),
__metadata('design:paramtypes', [])
], AppComponent);
return AppComponent;
})();
```

View File

@ -1,3 +0,0 @@
```
angular2_1.bootstrap(AppComponent);
```

View File

@ -1,3 +0,0 @@
```
var angular2_1 = require('angular2/angular2');
```

View File

@ -1,21 +0,0 @@
```
var angular2_1 = require('angular2/angular2');
var AppComponent = (function () {
function AppComponent() {
this.name = 'Alice';
}
AppComponent = __decorate([
angular2_1.Component({
selector: 'app'
}),
angular2_1.View({
template: '<h1 id="output">Hello {{ name }}</h1>'
}),
__metadata('design:paramtypes', [])
], AppComponent);
return AppComponent;
})();
exports.AppComponent = AppComponent;
angular2_1.bootstrap(AppComponent);
//# sourceMappingURL=app.js.map
```

View File

@ -1,5 +1,5 @@
```
.Class({
constructor: function () { }
});
.Class({
constructor: function () { }
});
```

View File

@ -1,5 +1,5 @@
```
.Component({
selector: 'my-app'
})
.Component({
selector: 'my-app'
})
```

View File

@ -1,5 +1,5 @@
```
.View({
template: '<h1 id="output">My First Angular 2 App</h1>'
})
.View({
template: '<h1 id="output">My First Angular 2 App</h1>'
})
```