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

bembem

v0.0.4

Published

mixins for writing BEM-style code

Downloads

11

Readme

BEM! BEM!

Install

BemBem

npm install bembem --save-dev


Usage

In order to use absolute include paths with Gulp.js you must add the bembem path into both sass (includePaths) and pug (basedir) options:

webpack 2

webpack.config.js

const bembem = require('bembem');

module.exports = {
    entry: './app.js',
    output: {
        filename: './dist/app.bundle.js',
    },
    devtool: 'source-map',
    module: {
        rules: [
            {
                test: /\.scss$/,
                use: [{
                    loader: "style-loader" // creates style nodes from JS strings
                }, {
                    loader: "css-loader" // translates CSS into CommonJS
                }, {
                    loader: "sass-loader", // compiles Sass to CSS
                    options: {
                        includePaths: [bembem.includePaths]
                    }
                }]
            },
            {
                test: /\.pug$/,
                loader: 'pug-loader',
                options: {
                    root: bembem.includePaths
                }
            }
        ]
    }
}

Gulp.js

gulpfile.js

const bembem = require('bembem');

// styles
gulp.task('styles', () => {
    gulp.src('./src/**/*.scss')
        .pipe($.sass({
            includePaths: ['./src', bembem.includePaths] // for absolute includes
        }).on('error', $.sass.logError))
        .pipe(gulp.dest(pathDist));
});

// views
gulp.task('views', () => {
    gulp.src(['!./src/**/_*.pug', './src/**/*.pug'])
        .pipe($.pug({
            basedir: bembem.includePaths // for absolute includes
        }))
        .pipe(gulp.dest(pathDist));
});

Then include mixins into your Sass styles and Pug views:

component.styles.scss

@import "bembem"; // include bembem mixins
// Prefix will be add in ANY class name. This is NOT required
@include prefix("item") {
    @include block("menu") {
        float: left;
        // This modifier only works for the Block "menu"
        @include modifier("right") {
            float: right;
        }
        // The elements are included inside of a Block to have a context
        @include element("item") {
            float: left;
        }
        @include element("button") {
            display: block;
            padding: 10px;
            color: black;
            &:hover {
                background-color: black;
                color: white;
            }
            // This is a modifier of the element "button"
            @include modifier("active") {
                background-color: red;
            }
        }
    }
}

component.view.pug

include /bembem // include bembem mixins

- var $prefix = 'item-'

+bem_scope({prefix: $prefix})
	+block.UL.menu
		+element.LI.item
			+element.A.button(href="#", title="") Button 1
		+element.LI.item
			+element.A.button._active(href="#", title="") Button 2
		+element.LI.item
			+element.A.button(href="#", title="") Button 3

Resources

  • BEM: https://en.bem.info/methodology/key-concepts/
  • Jade: http://jade-lang.com/
  • Sass: http://sass-lang.com/
  • Bemto: https://github.com/kizu/bemto

Credits