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

librarianowl

v0.2.0

Published

Simple toolkit to generates Less, Sass/Scss & Stylus libraries defined through YAML.

Downloads

6

Readme

node-librarianowl

Build Status Coverage Status Dependency Status NPM version

Simple toolkit to generates Less, Sass/Scss & Stylus libraries defined through YAML.

Getting Started

Install the module with: npm install librarianowl

librarianowl = require 'librarianowl'

# compile the library
librarianowl.library "src", "lib",
  helpers: "helpers.js"
  template: "template-lib.hbs"

# compile the documenation
librarianowl.documentation "src", "docs",
  helpers: "helpers.js"
  template: "template-docs.hbs"
  
# compile the examples
librarianowl.examples "src", "examples",
  helpers: "helpers.js"
  template: "template-examples.hbs"
  imports: (syntax) ->
    switch syntax
      when "sass" then return "@import '../../lib/#{syntax}/cssowl'"
      when "scss" then return "@import '../../lib/#{syntax}/cssowl';"
      when "less" then return "@import '../../lib/#{syntax}/cssowl';"
      when "styl" then return "@import '../../lib/#{syntax}/cssowl'"

Documentation

Librarianowl is based on the simple idea to write one YAML file per mixin with it's code in each syntax together with a shared documentation and example. Librarianowl will then generate each library with your custom Handlebars template or a default one.

The same can be done with the documentation. This too will be rendered with your custom Handlebars template or the default one. With this approach we try to keep it as simple as possible to make it easier to integrate the documentations into you own layout.

Namespaces

Librarianowl was built to work with the same namespace concept that has been used to generate cssowl. Thus you'll need to structure your YAML file in the same way like:

src
└── cssowl
    ├── _imports.yml
    ├── position
    │   ├── absolute-inside.yml
    │   ├── absolute-outside.yml
    │   └── absolute.yml
    └── sprite
        ├── _imports.yml
        ├── absolute-inside.yml
        ├── absolute-outside.yml
        ├── absolute.yml
        ├── after-absolute-inside.yml
        ├── after-absolute-outside.yml
        ├── after-absolute.yml
        ├── after-float.yml
        ├── after-inline.yml
        ├── after.yml
        ├── before-absolute-inside.yml
        ├── before-absolute-outside.yml
        ├── before-absolute.yml
        ├── before-float.yml
        ├── before-inline.yml
        ├── before.yml
        ├── display-block.yml
        ├── display-inline.yml
        ├── display.yml
        ├── float-left.yml
        ├── float-right.yml
        ├── replace-block.yml
        ├── replace-inline.yml
        └── replace.yml

Compiled as library this will look like:

lib
├── less
│   ├── cssowl
│   │   ├── position.less
│   │   └── sprite.less
│   └── cssowl.less
├── sass
│   ├── cssowl
│   │   ├── position.sass
│   │   └── sprite.sass
│   └── cssowl.sass
├── scss
│   ├── cssowl
│   │   ├── position.scss
│   │   └── sprite.scss
│   └── cssowl.scss
└── styl
    ├── cssowl
    │   ├── position.styl
    │   └── sprite.styl
    └── cssowl.styl

And compiled as documentation it'll look like:

docs
└── cssowl
    ├── position
    │   ├── absolute-inside.html
    │   ├── absolute-outside.html
    │   └── absolute.html
    └── sprite
        ├── absolute-inside.html
        ├── absolute-outside.html
        ├── absolute.html
        ├── after-absolute-inside.html
        ├── after-absolute-outside.html
        ├── after-absolute.html
        ├── after-float.html
        ├── after-inline.html
        ├── after.html
        ├── before-absolute-inside.html
        ├── before-absolute-outside.html
        ├── before-absolute.html
        ├── before-float.html
        ├── before-inline.html
        ├── before.html
        ├── display-block.html
        ├── display-inline.html
        ├── display.html
        ├── float-left.html
        ├── float-right.html
        ├── replace-block.html
        ├── replace-inline.html
        └── replace.html

YAML mixin definition

Taking the src/cssowl/sprite/display.yml file as an example a definition might look like this:

description: |
  Displays an element with it's *width*, *height*, *background-image* and *background-position*.
mixin:
  parameters:
    x: position of the element
    y: position of the element
    width: element width
    height: element height
    src: background image source
  less: |
    .cssowl-sprite-display(@x, @y, @width, @height, @src) {
      width: @width;
      height: @height;
      background-image: @src;
      background-position: @x @y;
      background-repeat: no-repeat;
    }
  sass: |
    @mixin cssowl-sprite-display($x, $y, $width, $height, $src)
      width: $width
      height: $height
      background-image: $src
      background-position: $x $y
      background-repeat: no-repeat
  scss: |
    @mixin cssowl-sprite-display($x, $y, $width, $height, $src) {
      width: $width;
      height: $height;
      background-image: $src;
      background-position: $x $y;
      background-repeat: no-repeat;
    }
  styl: |
    cssowl-sprite-display(x, y, width, height, src)
      width: width
      height: height
      background-image: src
      background-position: x y
      background-repeat: no-repeat
examples:
  sass: |
    .example-display
      +cssowl-sprite-display(-10px, -10px, 91px, 95px, url("sprite.png"));
  scss: |
    .example-display {
      @include cssowl-sprite-display(-10px, -10px, 91px, 95px, url("sprite.png"));
    }
  less: |
    .example-display {
      .cssowl-sprite-display(-10px, -10px, 91px, 95px, url("sprite.png"));
    }
  styl: |
    .example-display
      cssowl-sprite-display(-10px, -10px, 91px, 95px, url("sprite.png"))
  html: |
    .example-display

To import other files and to insure the import definitions are at the top of the file you can place a _imports.yml file into the directory that looks something like:

imports:
  less: |
    @import "cssowl/position";
    @import "cssowl/sprite";
  sass: |
    @import "cssowl/position"
    @import "cssowl/sprite"
  scss: |
    @import "cssowl/position";
    @import "cssowl/sprite";
  styl: |
    @import "cssowl/position"
    @import "cssowl/sprite"

Generating the library

Method:

###
@param {String} source Source directory
@param {String} target Target directory
@param {Object} options Optional options
###
library: (source, target, options={}) ->
 ...

Options

template

Type: String Default: librarianowl/templates/library.hbs

Handlebars template file to render the library file.

// {{{description}}}
{{#each mixin.parameters}}
// {{@key}}: {{{this}}}
{{/each}}
{{{mixin.syntax}}}
helpers

Type: Object String Default: {}

You can define you custom helpers that will be available with the Handlebars template rendering. It can be either a object containing each helper or a external file in which you define your helpers:

# Helpers as an object
librarianowl.library "src", "docs",
  helpers:
    "trim": (val) ->
      return val.trim()

# Helpers in a seperate file
librarianowl.library "src", "docs",
  helpers: "helpers.js"
filename

Type: Function Default: false

You can modify the target filename.

librarianowl.library "src", "docs",
  filename: (item, syntax) ->
      return "#{item.basename}.#{syntax}"

Generating the documentation

Method:

###
@param {String} source Source directory
@param {String} target Target directory
@param {Object} options Optional options
###
documentation: (source, target, options={}) ->
 ...

Options

template

Type: String Default: librarianowl/templates/documentation.hbs

Handlebars template file to render the documentation file.

<h2>{{mixinName}}</h2>

<p>{{{description}}}</p>

<ul class="nav nav-tabs">
  <li class="active">
    <a href="#example-{{{basename}}}-sass">Sass</a>
  </li>
  <li>
    <a href="#example-{{{basename}}}-scss">Scss</a>
  </li>
  <li>
    <a href="#example-{{{basename}}}-less">Less</a>
  </li>
  <li>
    <a href="#example-{{{basename}}}-styl">Stylus</a>
  </li>
  <li>
    <a href="#example-{{{basename}}}-html">Html</a>
  </li>
</ul>

<div class="tab-content">
  <code id="#example-{{{basename}}}-sass" class="tab-pane active">
    {{examples.sass}}
  </code>
  <code id="#example-{{{basename}}}-scss" class="tab-pane">
    {{examples.scss}}
  </code>
  <code id="#example-{{{basename}}}-less" class="tab-pane">
    {{examples.less}}
  </code>
  <code id="#example-{{{basename}}}-styl" class="tab-pane">
    {{examples.styl}}
  </code>
  <code id="#example-{{{basename}}}-html" class="tab-pane">
    {{examples.html}}
  </code>
</div>
helpers

Type: Object String Default: {}

You can define you custom helpers that will be available with the Handlebars template rendering. It can be either a object containing each helper or a external file in which you define your helpers:

# Helpers as an object
librarianowl.documentation "src", "docs",
  helpers:
    "trim": (val) ->
      return val.trim()

# Helpers in a seperate file
librarianowl.documentation "src", "docs",
  helpers: "helpers.js"
filename

Type: Function Default: false

You can modify the target filename.

librarianowl.documentation "src", "docs",
  filename: (item, syntax) ->
      return "#{item.basename}.#{syntax}"

Generating the examples

Method:

###
@param {String} source Source directory
@param {String} target Target directory
@param {Object} options Optional options
###
examples: (source, target, options={}) ->
 ...

Options

template

Type: String Default: librarianowl/templates/examples.hbs

Handlebars template file to render the documentation file.

{{{examples.syntax}}}
helpers

Type: Object String Default: {}

You can define you custom helpers that will be available with the Handlebars template rendering. It can be either a object containing each helper or a external file in which you define your helpers:

# Helpers as an object
librarianowl.examples "src", "examples",
  helpers:
    "trim": (val) ->
      return val.trim()

# Helpers in a seperate file
librarianowl.examples "src", "examples",
  helpers: "helpers.js"
filename

Type: Function Default: false

You can modify the target filename.

librarianowl.examples "src", "examples",
  filename: (item, syntax) ->
      return "#{item.basename}.#{syntax}"
imports

Type: Function Default: false

Return a string that should be prepended to the generated file.

librarianowl.examples "src", "examples",
  imports: (syntax) ->
    switch syntax
      when "sass" then return "@import 'path/to/file'"
      when "scss" then return "@import 'path/to/file';"
      when "less" then return "@import 'path/to/file';"
      when "styl" then return "@import 'path/to/file'"

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.

License

Copyright (c) 2013 Owl-Stars under the MIT license.