Git Product home page Git Product logo

dss's Introduction

DSS

NPM

DSS, Documented Style Sheets is a comment guide and parser for CSS, LESS, STYLUS, SASS and SCSS code. This project does static file analysis and parsing to generate an object to be used for generating styleguides.

Table of Contents

Parsing a File

In most cases, you will want to include the DSS parser in a build step that will generate documentation files automatically (or you just want to play around with this returned Object for other means); Either way, we officially support a Grunt Plugin and a Gulp Plugin.

Examples

Example Comment Block Format
//
// @name Button
// @description Your standard form button.
// 
// @state :hover - Highlights when hovering.
// @state :disabled - Dims the button when disabled.
// @state .primary - Indicates button is the primary action.
// @state .smaller - A smaller button
// 
// @markup
//   <button>This is a button</button>
// 
Example Usage
// Requirements
var fs = require( 'fs' );
var dss = require( 'dss' );

// Get file contents
var fileContents = fs.readFileSync( 'styles.css' );

// Run the DSS Parser on the file contents
dss.parse( fileContents, {}, function ( parsedObject ) {

  // Output the parsed document
  console.log( parsedObject );

});
Example Output
{
  "name": "Button",
  "description": "Your standard form button.",
  "state": [
    { 
      "name": ":hover",
      "escaped": "pseudo-class-hover",
      "description": "Highlights when hovering."
    },
    {
      "name": ":disabled",
      "escaped": "pseudo-class-disabled",
      "description": "Dims the button when disabled."
    },
    {
      "name": ".primary",
      "escaped": "primary",
      "description": "Indicates button is the primary action."
    },
    {
      "name": ".smaller",
      "escaped": "smaller",
      "description": "A smaller button"
    }
  ],
  "markup": {
    "example": "<button>This is a button</button>",
    "escaped": "&lt;button&gt;This is a button&lt;/button&gt;"
  }
}

dss.detector( callback )

This method defines the way in which points of interest (ie. variables) are found in lines of text and then, later, parsed. DSS dogfoods this API and the default implementation is shown below.

Default Detector:
// Describe default detection pattern
// Note: the current line, as a string, is passed to this function
dss.detector( function( line ) {
  
  if ( typeof line !== 'string' ) {
    return false;
  }
  var reference = line.split( "\n\n" ).pop();
  return !!reference.match( /.*@/ );

});

dss.parser( name, callback )

DSS, by default, includes 4 parsers for the name, description, state and markup of a comment block. You can add to, or override, these defaults by registering a new parser. These defaults also follow a pattern which uses the @ decorator to identify them. You can modify this behaivour providing a different callback function to dss.detector().

dss.parser expects the name of the variable you're looking for and a callback function to manipulate the contents. Whatever is returned by that callback function is what is used in generate JSON.

Callback this:
  • this.file: The current file
  • this.name: The name of the parser
  • this.options: The options that were passed to dss.parse() initially
  • this.line:
    • this.line.contents: The content associated with this variable
    • this.line.from: The line number where this variable was found
    • this.line.to: The line number where this variable's contents ended
  • this.block:
    • this.block.contents: The content associated with this variable's comment block
    • this.block.from: The line number where this variable's comment block starts
    • this.block.to: The line number where this variable's comment block ends
Custom Parser Examples:
// Matches @version
dss.parser( 'version', function () {

  // Just returns the lines contents
  return this.line.contents;

});
dss.parser( 'link', function () {

  // Replace link with HTML wrapped version
  var exp = /(b(https?|ftp|file)://[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|])/ig;
  this.line.contents.replace(exp, "<a href='$1'>$1</a>");
  return line;
   
});

Other Projects

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.