1.0.0 • Published 8 years ago

gulp-css-tailor v1.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
8 years ago

✂ gulp-css-tailor

Gulp plugin that automatically generates the CSS from your HTML classes

Utility that turns the classes applied upon the DOM elements to CSS. So that you don't have to manually write the CSS for those minor UI enhancements like increasing the padding, adding a little margin, changing the font size, applying a border radius, pumping up the line-height a bit etc.

Usage

All you have to do is specify the CSS class on any DOM element, CSS will be generated and written to a CSS file of your liking or returned for any programmatical use.

All you have to do is specify any HTML class as follows

[formula][value][unit] # If you donot provide the unit, `px` will be used.

For example; mt25 translates to margin-top: 25px, fs14px to font-size: 14px; etc.

The list of supported formulae and examples are given below

Supported Formulae

Currently supported styles are as follows.

FormulaCSS PropertyExample Usage
ppaddingp10 will translate to padding: 10px
ptpadding-toppt20 will translate to padding-top: 20px;
pbpadding-bottompb10 will translate to padding-bottom: 10px;
prpadding-rightpr20 will translate to padding-right: 20px;
plpadding-leftpl23 will translate to padding-left: 23px;
mmarginm20 will translate to margin: 20px
mtmargin-topmt20 will translate to margin-top: 20px;
mbmargin-bottommb20 will translate to margin-bottom: 20px;
mlmargin-leftml50 will translate to margin-left: 50px;
mrmargin-rightmr30 will translate to margin-right: 30px;
wwidthw200 will translate to width: 200px
hheighth60 will translate to height: 60px;
brborder-radiusbr5 will translate to border-radius: 5px;
fsfont-sizefs15 will translate to font-size: 15px
fwfont-weightfw400 will translate to font-weight: 400px
lhline-heightlh20em will translate to line-height: 20em
ttopt6 will translate to top: 6px;
lleftl30 will translate to left: 30px
bbottomb20em will translate to bottom: 20em;
rrightr20em will translate to right: 20em;

Notes for Units

All the default CSS units are supported. You can specify it and relevant CSS unit will be used

  • Units including px, pt, em, p, vh, vw, vmin, ex, cm, in, mm, pc will translate to the same unit in CSS
  • If you don't provide any unit px will be used
  • If you need % specify it as p e.g. w50p will get translated to width: 50%
  • If no unit is needed, specify n e.g. fw600n will translate to font-weight: 600

Install

Install it using npm

$ npm install --save gulp-css-tailor

Create a Gulp task

Create a gulp task similar to the following

var tailor = require('gulp-css-tailor');

gulp.task('tailor', function () {

  // Process all the HTML files in a chose any files that you want
  gulp.src('templates/**/*.html')
    .pipe(tailor({
        filename: 'tailored.css',  // Name of the file that will be generated [default: 'tailored.css']
        minifyOutput: false,       // Whether to minify the generated CSS or not [default: false]
        tabSpacing: 4,             // Tab spacing when `minifyOutput` is disabled [default: 4]
        setImportant: false        // Will add the `!important` flag to all the CSS properties
    }))
    .pipe(gulp.dest('assets/css')); // Directory where CSS is to be generated

});

And run gulp tailor, it will find all the tailorable classes and generate the CSS at the required destination

Options

Arguments are optional by default, however, you can pass a variety of them to modify the generated CSS file.

var options = {
    filename: 'tailored.css',  // Name of the file that will be generated [default: 'tailored.css']
    minifyOutput: false,       // Whether to minify the generated CSS or not [default: false]
    tabSpacing: 4,             // Tab spacing when `minifyOutput` is disabled [default: 4]
    setImportant: false        // Will add the `!important` flag to all the CSS properties
};

For further usage examples, check the examples directory

Side Note

This plugin is based upon CSS Tailor. If you would like to use this functionality programmatically or use with some other task runner, make sure to check kamranahmedse/css-tailor

License

MIT © Kamran Ahmed