npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gulp-styleguide

v0.3.1

Published

gulp pipeline to generate a styleguide from DSS

Downloads

10

Readme

Gulp Styleguide NPM version Dependency Status Build Status

A gulp pipeline for building styleguide documentation from Documented Style Sheets (DSS) comments in your CSS/SCSS/LESS.

Usage

Put your CSS into a directory structure with an index for each directory e.g.

src/
    scss/
        index.scss
        base/
            index.scss
            headings.scss
        layout/
            index.scss
            grid.scss
        modules/
            index.scss
            toolbar.scss

Then in you gulpfile:

var gulp = require('gulp');
var styleguide = require('gulp-styleguide');
var options = {
    site: {
        title: 'Test Pattern Library'
    }
};

gulp.task('templates', styleguide.templates(options));
gulp.task('build', ['templates'], styleguide.build(options));

Then run gulp and a bunch of HTML files should appear in the dist/ directory.

File Structure

The structure of the HTML reflects the structure of your CSS. For that reason it's nice to separate your CSS into directories that reflect the purpose of the CSS.

The index is required to build a section index. The first comment block's @name will be used for the section name. It's a good place to put any introductory text for the section in the @description annotation.

By convention the index should only have minimal CSS and import the rest of the files for that section, but this is not required.

The first comment block's @name in non-index files will be used for the subsection name.

Examples

There is a full gulpfile example in example/. This includes SASS compiling and running a preview server with livereload.

Options

  • src.css - Path to your CSS files. Optional, defaults to 'src/**/*.{css,less,scss}'.
  • src.templates - Path to your Mustache templates. Optional, defaults to path to templates/ in this library.
  • dest.html - Path to output HTML to. Optional, defaults to dist/.
  • site - An object to contain the outputted website. This can contain any variables you want to make available to your templates. It will have an index property appended which contains the site tree, more on that below. Optional, defaults to { site: { title: 'Styleguide' } }.

Templating

Templates our written in Mustache. There are 2 required templates page/default.mustache and page/index.mustache. The default page is used for rendering the content from a single CSS file. The index page is used for each directory index. The packaged version will render all the files for a particular section.

You are free to override with your own templates, add layout and partials etc. provided you have the 2 required templates. See the templates/ directory for an example.

There are a number of preset variables available:

  • site.index - This contains a full content-tree of the entire styleguide. This is built with gulp-ssg - see the documentation for more info, but basically it allows you to do things like make navigation, render sub-pages in pages etc.
  • meta - Each file has a meta property that contains things like the url. Again see the gulp-ssg documentation for full details and information on how you can add your own properties. In addition to the standard properties you'll get meta.sectionName and meta.subsectioName.
  • dss - Each file has a dss property, see the [DSS][] documentation for more info about what that contains. Some additional DSS annotations are parsed as described below.

You can add any other variables you like to site by passing it with the options, just be careful not to override.

Custom DSS Parsers

These parsers are in addition to default @name, @description, @state and @markup:

  • @order {integer} - Set the files sort order, lower numbers will come first. This allows you to order sections and files (when combining several on one HTML page). Taken from first DSS block in file, others will be ignored.
  • @template {string} - Specify the template file to use to render this file. Taken from first DSS block in file, others will be ignored.
  • @partial {string} - Specify the partial template file to use to render this block. To use it in your template use {{#partial}}{{/partial}} (behind the scenes a lambda is created that will return the actual partial - this is how you can have variable partial names in Mustache).
  • @variable {name} - {description} - Document a variable. The name must match the name in the file without a $ prefix. The value will be extracted from the file and assigned to value. It won't be computed so things like $height: 5px*10 will have a literal value 5px*10.

Also the state is post-parsed to add HTML examples for each state. This is rendered with the state (using Mustache) so you can add class names etc. For example:

/**
 * @name Button
 * @state .primary - Primary button
 * @state .danger - Dangerous button
 * @markup
 * <button class="{{{escaped}}}">{{description}}</button>
 */

As well as block.markup each state will now have markup.example and markup.escaped added. Empty attributes will be stripped from the stateless example to avoid clutter.

Pseudo State

In order to make examples for pseudo state like :hover work there is a client-side JS file resources/js/pseudo-state.js which you should include in your built styleguide. This creates new rules for the escaped class name generated by DSS, like .pseudo-class-hover, by copying from the real pseudo rule.

What This Doesn't Do

The general philosophy is not to do any processing of your assets. It will only extract the DSS from your CSS (or SASS or LESS) and produce some HTML output using your templates.

  • Does not compile your SASS/LESS
  • Does not do any image, icon or font processing
  • Does not do any minification/uglifying

These tasks can be added to your own gulpfile.