Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature option show markup section #1039

Merged
merged 4 commits into from
Nov 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,11 @@ These HTML elements are injected inside the style guide `head` tag.

Enables side navigation. When this option parameter is enabled, style guide will switch to side navbar.

<a name="option-showMarkupSection"></a>
**showMarkupSection** (boolean, optional, default: true)

Show/hide Markup section.

<a name="option-beforeBody"></a>
**beforeBody** (array or string, optional)

Expand All @@ -222,6 +227,11 @@ These HTML elements are injected inside the style guide `<body>` tag, before any

These HTML elements are injected inside the style guide `<body>` tag, after any other content.

<a name="option-afterSections"></a>
**afterSections** (array or string, optional)

These HTML elements are injected inside the style guide `.sg-body` section, after any other content.

<a name="option-commonClass"></a>
**commonClass** (string or array of strings, optional)

Expand Down
1 change: 1 addition & 0 deletions gulpfile.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ gulp.task('dev:generate', () => {
.pipe(styleguide.generate({
title: 'SC5 Styleguide',
sideNav: false,
showMarkupSection: true,
server: true,
rootPath: outputPath,
overviewPath: 'README.md',
Expand Down
21 changes: 14 additions & 7 deletions lib/app/js/controllers/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,25 @@
angular.module('sgApp')
.controller('MainCtrl', function($scope, $location, $state, Styleguide, Variables, localStorageService, Socket) {

$scope.isNavCollapsed = false;
$scope.markupSection = {isVisible: true};
$scope.designerTool = {isVisible: false};

localStorageService.bind($scope, 'markupSection', {isVisible: true});
localStorageService.bind($scope, 'designerTool', {isVisible: false});

// Bind scope variables to service updates
$scope.sections = Styleguide.sections;
$scope.config = Styleguide.config;
$scope.status = Styleguide.status;
$scope.variables = Variables.variables;
$scope.toggleMenu = true;
$scope.toggleMenu = false;
$scope.isNavCollapsed = false;
$scope.markupSection = {isVisible: ''};

$scope.$watch('config.data', function() {
if ($scope.config.data) {
$scope.markupSection = {isVisible: $scope.config.data.showMarkupSection};
localStorageService.bind($scope, 'markupSection', {isVisible: $scope.config.data.showMarkupSection});
}
});

$scope.designerTool = {isVisible: false};
localStorageService.bind($scope, 'designerTool', {isVisible: false});

$scope.toggleSideNav = function(toggleMenu) {
$scope.toggleMenu = !toggleMenu;
Expand Down Expand Up @@ -54,6 +60,7 @@ angular.module('sgApp')
return;
}
});

return result;
};

Expand Down
66 changes: 34 additions & 32 deletions lib/app/views/sections.html
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
<article
sg-section
ng-repeat="section in sections.data | filter: filterSections | filter: search">
</article>
<div class="sg sg-section-links" ng-repeat="section in sections.data | filter: filterMainSections()" ng-if="isMainSection(section) && isActive(section)">
<a class="sg sg-section-link"
ng-class="{ 'active': (currentSection === section.reference), 'sub-active': (currentSection.indexOf(section.reference + '.') === 0) }"
ng-click="clearSearch()"
ui-sref="app.index.section({section: section.reference})">
</a>
<ul class="sg sg-subsection-links">
<li class="sg sg-section-list-item" ng-repeat="subsection in sections.data | filter: filterSubsections(section)">
<a class="sg sg-section-link"
ng-class="currentSection === subsection.reference ? 'active' : ''"
ng-click="clearSearch()"
ui-sref="app.index.section({section: subsection.reference})">
<span class="sg-ref">{{ subsection.reference }}</span> <span ng-bind-html="subsection.header | unsafe"></span>
<ul class="sg sg-nav-subsubsection sg-subsubsection-links">
<li class="sg sg-section-list-item" ng-repeat="subsubsection in sections.data | filter: filterSubsections(subsection)">
<a class="sg sg-section-link"
ng-class="currentSection === subsubsection.reference ? 'active' : ''"
ng-click="clearSearch()"
ui-sref="app.index.section({section: subsubsection.reference})">
<span class="sg-ref">{{ subsubsection.reference }}</span> <span ng-bind-html="subsubsection.header | unsafe"></span>
</a>
</li>
</ul>
</a>
</li>
</ul>
</div>
<section class="sg sg-after-sections" ng-bind-html="config.data.afterSections | unsafe"></section>
<section class="sg sg-sections">
<article
sg-section
ng-repeat="section in sections.data | filter: filterSections | filter: search">
</article>
<section class="sg sg-section-links" ng-repeat="section in sections.data | filter: filterMainSections()" ng-if="isMainSection(section) && isActive(section)">
<a class="sg sg-section-link"
ng-class="{ 'active': (currentSection === section.reference), 'sub-active': (currentSection.indexOf(section.reference + '.') === 0) }"
ng-click="clearSearch()"
ui-sref="app.index.section({section: section.reference})">
</a>
<ul class="sg sg-subsection-links">
<li class="sg sg-section-list-item" ng-repeat="subsection in sections.data | filter: filterSubsections(section)">
<a class="sg sg-section-link"
ng-class="currentSection === subsection.reference ? 'active' : ''"
ng-click="clearSearch()"
ui-sref="app.index.section({section: subsection.reference})">
<span class="sg-ref">{{ subsection.reference }}</span> <span ng-bind-html="subsection.header | unsafe"></span>
<ul class="sg sg-nav-subsubsection sg-subsubsection-links">
<li class="sg sg-section-list-item" ng-repeat="subsubsection in sections.data | filter: filterSubsections(subsection)">
<a class="sg sg-section-link"
ng-class="currentSection === subsubsection.reference ? 'active' : ''"
ng-click="clearSearch()"
ui-sref="app.index.section({section: subsubsection.reference})">
<span class="sg-ref">{{ subsubsection.reference }}</span> <span ng-bind-html="subsubsection.header | unsafe"></span>
</a>
</li>
</ul>
</a>
</li>
</ul>
</section>
</section>
<section class="sg sg-after-sections" ng-bind-html="config.data.afterSections | unsafe"></section>
3 changes: 2 additions & 1 deletion lib/modules/cli/argv.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ module.exports = function(argLib) {
.describe('beforeBody', 'These HTML elements are injected inside the style guide body tag, before any other content')
.describe('afterBody', 'These HTML elements are injected inside the style guide body tag, after any other content')
.describe('afterSections', 'These HTML elements are injected after the sections, after all the section content')
.describe('sideNav', 'This bool use to switch navigation to side nav')
.describe('sideNav', 'This bool option is used to switch navigation to side nav')
.describe('showMarkupSection', 'This bool option is for hiding markup section. By default markup is visible.')
.describe('commonClass', 'The provided classes are added to all preview blocks in the generated style guide')
.describe('appRoot', 'Define the appRoot parameter if you are hosting the style guide from a directory other than the root directory of the HTTP server')
.describe('styleVariables', 'Specify the files to parse variable definitions from (defaults to all files/glob pattern passed to kssSource')
Expand Down
1 change: 1 addition & 0 deletions lib/modules/cli/styleguide-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module.exports = function(argv) {
afterBody: argv.afterBody,
afterSections: argv.afterSections,
sideNav: argv.sideNav,
showMarkupSection: argv.showMarkupSection,
commonClass: argv.commonClass,
appRoot: argv.appRoot,
styleVariables: argv.styleVariables,
Expand Down
1 change: 1 addition & 0 deletions lib/modules/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ function sanitizeOptions(opt) {
afterSections: (typeof opt.afterSections === 'object') ? opt.afterSections.join('\n') : opt.afterSections,
additionalNgDependencies: opt.additionalNgDependencies || false,
sideNav: opt.sideNav || false,
showMarkupSection: opt.showMarkupSection || false,
disableEncapsulation: opt.disableEncapsulation || false,
disableHtml5Mode: opt.disableHtml5Mode || (typeof opt.disableHtml5Mode === 'undefined' && !opt.server) || false,
appRoot: opt.appRoot || '',
Expand Down
5 changes: 3 additions & 2 deletions lib/styleguide.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ function replaceSectionReferences(json) {
}

function copyUsedOptionsToJsonConfig(opt, json) {
var used = ['appRoot', 'extraHead', 'beforeBody', 'afterBody', 'commonClass', 'title', 'disableEncapsulation', 'disableHtml5Mode', 'readOnly', 'sideNav', 'afterSections', 'additionalNgDependencies'];
var used = ['appRoot', 'extraHead', 'beforeBody', 'afterBody', 'commonClass', 'title', 'disableEncapsulation', 'disableHtml5Mode', 'readOnly', 'sideNav', 'afterSections', 'showMarkupSection', 'additionalNgDependencies'];
json.config = {};
used.forEach(function(prop) {
json.config[prop] = _.cloneDeep(opt[prop]);
Expand All @@ -158,7 +158,7 @@ function copyUsedOptionsToJsonConfig(opt, json) {
}

function copyUsedOptionsToInlineJsonConfig(opt, json) {
var used = ['title', 'disableEncapsulation', 'disableHtml5Mode', 'sideNav', 'afterSections', 'additionalNgDependencies'];
var used = ['title', 'disableEncapsulation', 'disableHtml5Mode', 'sideNav', 'afterSections', 'showMarkupSection', 'additionalNgDependencies'];
json.config = {};
used.forEach(function(prop) {
json.config[prop] = _.cloneDeep(opt[prop]);
Expand Down Expand Up @@ -391,6 +391,7 @@ module.exports.generate = function(options) {
afterSections: opt.afterSections,
afterBody: opt.afterBody,
sideNav: opt.sideNav,
showMarkupSection: opt.showMarkupSection,
styleguideConfig: JSON.stringify(copyUsedOptionsToInlineJsonConfig(opt, {}).config),
appRoot: opt.appRoot,
socketIo: opt.server,
Expand Down
5 changes: 3 additions & 2 deletions test/angular/unit/controllers/main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ describe('Controller: MainCtrl', function() {
},
config: {
data: {
title: 'Page Title'
title: 'Page Title',
showMarkupSection: true
}
}
};
Expand Down Expand Up @@ -74,7 +75,7 @@ describe('Controller: MainCtrl', function() {
});

it('should have markup shown by default', function() {
expect(scope.markupSection.isVisible).to.eql(true);
expect(scope.markupSection.isVisible).to.eql(styleguideData.config.data.showMarkupSection);
});

describe('toggle sideNav', function() {
Expand Down