Skip to content

Commit 7467b83

Browse files
committed
Merge pull request #148 from anttisalo/pageTitleBinding
Page title rendered according to section
2 parents 19cd9ae + d37929c commit 7467b83

File tree

5 files changed

+34
-7
lines changed

5 files changed

+34
-7
lines changed

lib/app/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<link rel="stylesheet" type="text/css" href="{{{appRoot}}}/css/app.css">
88
<link rel="stylesheet" type="text/css" href="{{{appRoot}}}/styleguide.css">
99
<link rel="stylesheet" type="text/css" href="{{{appRoot}}}/styleguide_pseudo_styles.css">
10-
<title>{{title}}</title>
10+
<title ng-bind="$root.pageTitle"></title>
1111
{{{extraHead}}}
1212
{{#filesConfig}}
1313
<script type="text/javascript">

lib/app/js/app.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,16 @@ angular.module('sgApp', [
2121
.state('app.index.overview', {
2222
url: '/overview',
2323
templateUrl: 'overview.html',
24-
controller: function($rootScope) {
24+
controller: function($rootScope, Styleguide) {
2525
$rootScope.currentSection = 'overview';
26+
27+
$rootScope.$watch(function() {
28+
return Styleguide.config.data;
29+
}, function(newVal, oldVal) {
30+
if (newVal) {
31+
$rootScope.pageTitle = newVal.title;
32+
}
33+
});
2634
}
2735
})
2836
.state('app.index.section', {

lib/app/js/controllers/sections.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,30 @@ angular.module('sgApp')
1414
return !/([0-9]\.)/.test(section.reference);
1515
}
1616

17+
$rootScope.$watch(function() {
18+
return Styleguide.sections.data;
19+
}, function(newVal, oldVal) {
20+
parseStateHeading($scope.currentSection);
21+
});
22+
23+
$rootScope.$watch(function() {
24+
return Styleguide.config.data;
25+
}, function(newVal, oldVal) {
26+
parseStateHeading($scope.currentSection);
27+
});
28+
29+
function parseStateHeading(section) {
30+
if (section === 'all' && typeof Styleguide.config.data !== 'undefined') {
31+
$rootScope.pageTitle = 'All sections - ' + Styleguide.config.data.title;
32+
} else if (typeof Styleguide.sections.data !== 'undefined') {
33+
for (var i = 0; i < Styleguide.sections.data.length; i++) {
34+
if (Styleguide.sections.data[i].reference == section) {
35+
$rootScope.pageTitle = Styleguide.sections.data[i].header + ' - ' + Styleguide.config.data.title
36+
}
37+
};
38+
}
39+
}
40+
1741
// Check section level (main/sub/sub-sub/sub-sub-sub)
1842
$scope.getLevel = function(section) {
1943
if (/([0-9]\.[0-9]\.[0-9]\.)/.test(section.reference)) {

lib/app/views/main.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ <h1 class="sg">{{ config.data.title }}</h1>
88
</div>
99
</div>
1010
</header>
11-
1211
<div class="sg wrapper" ng-class="isNavCollapsed ? 'collapsed' : ''">
1312
<div class="sg side-nav-toggle"
1413
ng-click="isNavCollapsed = !isNavCollapsed">

test/structure.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,6 @@ describe('index.html', function() {
7272
expect(indexHtml).to.be.an('object');
7373
});
7474

75-
it('should contain correct title', function() {
76-
expect(indexHtml.contents.toString()).to.contain('<title>Test Styleguide</title>');
77-
});
78-
7975
it('should contain CSS style passed as parameter', function() {
8076
expect(indexHtml.contents.toString()).to.contain('<link rel="stylesheet" type="text/css" href="your/custom/style.css">');
8177
});

0 commit comments

Comments
 (0)