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

metalsmith-atomizer

v1.2.1

Published

Metalsmith plugin for Atomizer

Downloads

11

Readme

metalsmith-atomizer

Metalsmith plugin to use Atomizer to build your Atomic CSS.

npm version Build Status Dependencies Dev Dependencies codecov.io

Installation

npm can do this for you.

npm install --save metalsmith-atomizer

Usage

Include this like you would include any other plugin. First, a CLI example that also shows the default options. You don't need to specify any options unless you want to change their values.

{
    "plugins": {
        "metalsmith-atomizer": {
            "acssConfig": {},
            "addRules": {},
            "bufferEncoding": "utf8",
            "destination": "atomic.css",
            "destinationMode": "0644",
            "forget": false,
            "match": "**/*.{html,htm}",
            "matchOptions": {},
            "setOptions": {}
        }
    }
}

And this is a JavaScript example that also includes a brief explanation of the options.

// Load this, just like other plugins.
var atomizer = require("metalsmith-atomizer");

// Then in your list of plugins you use it.
.use(atomizer())

// Alternately, you can specify options.  The values shown here are
// the defaults.  Dig into atomizer's src/atomizer.js to understand
// all of these options in depth.
.use(atomizer({
    // Atomic CSS config passed to Atomizer.  Use this to assign custom
    // values, breakpoints, etc.  It also can be used to force some
    // classes to always be generated.
    acssConfig: {},

    // Another undocumented feature of Atomizer to create custom ACSS
    // "functions".  Calls .addRules() with this configuration.
    addRules: {},

    // When converting file buffers to strings for Atomizer and strings
    // into buffers, which encoding should be used?
    bufferEncoding: "utf8",

    // Name of the generated file.
    destination: "atomic.css",

    // File permissions of the generated CSS file.
    destinationMode: "0644",

    // Set to true if the list of detected CSS rules should be forgotten.
    // Remembering these rules helps the plugin work with
    // metalsmith-watch and similar plugins.
    forget: false,

    // Pattern of files to match
    match: "**/*.{html,htm}",

    // Options for matching files.  See metalsmith-plugin-kit.
    matchOptions: {},

    // Custom CSS generation options to pass to Atomizer's .getCSS()
    // function.  It allows changing things like rtl and namespace.
    setOptions: {}
})

This uses metalsmith-plugin-kit to match files. The .matchOptions object can be filled with options to control how the matching works.

This plugin also can display the classes found by each processed file. Enable debugging by setting the DEBUG environment variable when running your build.

DEBUG=metalsmith-atomizer metalsmith

metalsmith-atomizer remembers the detected CSS rules between runs. This makes it work far better with metalsmith-watch and other plugins that perform the same sort of action. If you add and remove CSS classes, the plugin keeps track of what file added what Atomic CSS rules and updates the result accordingly. This allows for incremental or partial builds of your project. If this is undesirable, set forget to true.

API

metalsmith-atomizer

Metalsmith Atomizer constructs Atomic CSS from HTML markup in your Metalsmith build process.

See

Example

var atomizer = require("metalsmith-atomizer");

// Make the Metalsmith instance and add this plugin as middleware.
metalsmith.use(atomizer({
    // options go here
}));

module.exports(options) ⇒ function

Factory to build middleware for Metalsmith.

Kind: Exported function
Params

  • options Object

module.exports~combineClasses(classesByFile) ⇒ Array.<string>

Builds an array of every mentioned class name inside the classesByFile object.

Kind: inner method of module.exports
Params

  • classesByFile Object.<string, string>

module.exports~options : Object

Options supported by the middleware factory.

Kind: inner typedef of module.exports
See

Properties

  • acssConfig Object - Atomic CSS configuration.
  • addRules false | Object - Additional Atomic CSS rules.
  • bufferEncoding string - Used when parsing file contents.
  • destination string - File to generate.
  • destinationMode string - Permissions for the generated file.
  • forget boolean - If true, previous Atomic rules are forgotten. Must be false when using this plugin with caching or limited builds (eg. metalsmith-watch).
  • match module:metalsmith-plugin-kit~matchList - Files to match. Defaults to *.htm and *.html.
  • matchOptions module:metalsmith-plugin-kit~matchOptions - Options controlling matching behavior.
  • setOptions Object - Used for generating Atomic CSS and can control rtl and namespace.

Development

This uses Jasmine, Istanbul and ESLint for tests.

# Install all of the dependencies
npm install

# Run the tests
npm run test

This plugin is licensed under the MIT License with an additional non-advertising clause. See the full license text for information.