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

Add option to pass css file to the default template #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ module.exports = function(grunt) {
dss: {
docs: {
options: {
template: 'template/'
template: 'template/',
build_css: ['example/foo.css']
},
files: {
'docs/': 'example/**/*.{css,scss,sass,less,styl}'
}
}
},

//
//
jshint: {
all: [
'Gruntfile.js',
Expand Down
19 changes: 17 additions & 2 deletions tasks/dss.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ module.exports = function(grunt){
template: __dirname + '/../template/',
template_index: 'index.handlebars',
output_index: 'index.html',
include_empty_files: true
include_empty_files: true,
build_css: []
});

// Output options if --verbose cl option is passed
Expand All @@ -35,6 +36,19 @@ module.exports = function(grunt){
dss.parser(key, options.parsers[key]);
}

// Save build css
var build_css = [];
options.build_css.forEach(function(f) {
// Warn on and remove invalid build files (if nonull was set).
if(!grunt.file.exists(f)){
grunt.log.warn('Build file "' + f + '" not found.');
return false;
}
build_css.push({
file: f
});
});

// Build Documentation
this.files.forEach(function(f){

Expand Down Expand Up @@ -107,7 +121,8 @@ module.exports = function(grunt){
// Create HTML ouput
var html = handlebars.compile(grunt.file.read(template_filepath))({
project: grunt.file.readJSON('package.json'),
files: styleguide
files: styleguide,
build_css: build_css
});

var output_type = 'created', output = null;
Expand Down
41 changes: 29 additions & 12 deletions template/index.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,28 @@
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<title>{{project.name}} styleguide</title>
<title>{{project.name}} styleguide</title>
<link rel="stylesheet" href="assets/js/prettify/prettify.css?v=1" type="text/css" />
<link rel="stylesheet" href="assets/css/styles.css?v=1" type="text/css" />
<script src="assets/js/prettify/prettify.js?v=1"></script>
{{#build_css}}
<link rel="stylesheet" type="text/css" href="../{{file}}">
{{/build_css}}
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script type="text/javascript">
$(function() {
$('div.state > div.item').each(function() {
var el = $(this),
pseudoState = el.data('state');
// Replace special characters in a string
pseudoState = pseudoState.replace(/[&\/\\#,+()$~%.'":*?<>{}]/g,'');
el.children().addClass(pseudoState);
});
});
</script>
</head>
<body onload="prettyPrint()">

<header>
<h1>{{project.name}} styleguide</h1>
<p class="version">v.<strong>{{project.version}}</strong></p>
Expand All @@ -30,43 +45,45 @@

{{#files}}
<div class="file">

<h3 id="{{file}}">{{file}}</h3>

{{#blocks}}

<div class="block">

<div class="info">
<h4>{{name}}</h4>
{{#if description}}
<p class="description">{{description}}</p>
{{/if}}

{{#state}}
<p class="state"><span>{{name}}</span> - {{description}}</p>
{{/state}}
</div>

{{#if markup}}

<div class="example">
{{{markup.example}}}
</div>

{{#state}}
<div class="example state {{class}}">
<div class="example state">
<div class="name">{{name}}</div>
<div class="item" data-state="{{name}}">
{{{../markup.example}}}
</div>
</div>
{{/state}}

<pre class="prettyprint lang-html markup">
{{{markup.escaped}}}
</pre>

{{/if}}

</div>
{{/blocks}}

Expand Down