Code Monkey home page Code Monkey logo

postcss-prepend-selector's Introduction

Up-to-date alternative https://github.com/RadValentin/postcss-prefix-selector

PostCSS Prepend Selector Build Status

PostCSS plugin Prepend selector for each rule.

.foo {
    /* Input example */
}

.foo, .bar {
    /* Input example */
}
.selector .foo {
  /* Output example */
}

.selector .foo, .selector .bar {
  /* Output example */
}

Usage

postcss([ require('postcss-prepend-selector')( { selector: '.selector ' } ) ])

See PostCSS docs for examples for your environment.

postcss-prepend-selector's People

Contributors

krodelabestiole avatar ledniy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

postcss-prepend-selector's Issues

Feature Suggestion: "Exclude" option

Hello. Thank you for the very useful plugin. In my case, however, I needed the ability to exclude certain selectors from receiving the prefix. I modified the code a bit and added an exclude option, which should be an array of RegExp's against which to test the selectors, before prepending anything:

...

var selectorExcluded = function (regexp) {
  return regexp.test(selector)
}

if (selector.startsWith(opts.selector.trim()) || opts.exclude.some(selectorExcluded)) {
  return selector
}

return opts.selector + selector

...

which could be used like:

require('postcss-prepend-selector')({ selector: '.my-stuff ', exclude: [/#content-wrapper/] })

It seems to be working, so I thought I'd share the idea in case you're interested in incorporating into the plugin.

Prepend selector for multiple selectors

Hi, thanks for this project, I was playing with it today and I think that is useful. However there are an issue related to the multiple selectors. For example:

.a , .b, .c{
}

The output is:

#prepend .a , .b, .c{
}

I took a look to the code and seems to be related to this line:

rule.selector = opts.selector + rule.selector;

We could validate this kind of selectors, Actually I don't know if postcss has an API to make this validation easier. Unfurtunately I don't have time to find the better solution. I'm sorry

Best Regards, Dariel

postcss-prepend-selector will prepend a selector to numerical values with decimal

postcss-prepend-selector will prepend a selector to numerical values with decimal in keyframes

here is an exemple :

@keyframes fill-unfill-rotate {
  12.5% {
    -webkit-transform: rotate(135deg);
            transform: rotate(135deg);
  }
  25% {
    -webkit-transform: rotate(270deg);
            transform: rotate(270deg);
  }
}

prependSelector({selector:'.admin '}) will return :

@keyframes fill-unfill-rotate {
  .admin 12.5% {
    -webkit-transform: rotate(135deg);
            transform: rotate(135deg);
  }
  25% {
    -webkit-transform: rotate(270deg);
            transform: rotate(270deg);
  }
}

and CSS rules are broken

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.