• Stars
    star
    698
  • Rank 62,278 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 8 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Indent-based CSS syntax for PostCSS

SugarSS

Indent-based CSS syntax for PostCSS.

a
  color: blue

.multiline,
.selector
  box-shadow: 1px 0 9px rgba(0, 0, 0, .4),
              1px 0 3px rgba(0, 0, 0, .6)

// Mobile
@media (max-width: 400px)
  .body
    padding: 0 10px

As any PostCSS custom syntax, SugarSS has source map, stylelint and postcss-sorting support out-of-box.

It was designed to be used with postcss-simple-vars and postcss-nested. But you can use it with any PostCSS plugins or use it without any PostCSS plugins. With postcss-mixins you can use @mixin syntax as in Sass.

Sponsored by Evil Martians

Syntax

SugarSS MIME-type is text/x-sugarss with .sss file extension.

Indent

We recommend 2 spaces indent. However, SugarSS autodetects indent and can be used with tabs or spaces.

But it is prohibited to mix spaces and tabs in SugarSS sources.

Multiline

SugarSS was designed to have intuitively multiline selectors and declaration values.

There are 3 rules for any types of nodes:

// 1. New line inside brackets will be ignored
@supports ( (display: flex) and
            (display: grid) )

// 2. Comma at the end of the line
@media (max-width: 400px),
       (max-height: 800px)

// 3. Backslash before new line
@media screen and \
       (min-width: 600px)

In a selector you can put a new line anywhere. Just keep same indent for every line of selector:

.parent >
.child
  color: black

In a declaration value you can put a new line anywhere. Just keep a bigger indent for the value:

.one
  background: linear-gradient(rgba(0, 0, 0, 0), black)
              linear-gradient(red, rgba(255, 0, 0, 0))

.two
  background:
    linear-gradient(rgba(0, 0, 0, 0), black)
    linear-gradient(red, rgba(255, 0, 0, 0))

Comments

SugarSS supports two types of comments:

/*
 Multiline comments
 */

// Inline comments

There is no โ€œsilentโ€ comment in SugarSS. Output CSS will contain all comments from .sss source. But you can use postcss-discard-comments for Sassโ€™s silent/loud comments behaviour.

Rule and Declarations

SugarSS separates selectors and declarations by :\s or :\n token.

So you must write a space after the property name: color: black is good, color:black is prohibited.

Other

SugarSS is just a syntax, it change the way how you write CSS, but do not add preprocessor features build-in.

Here are PostCSS plugins which could add you preprocessor features:

Text Editors

We are working on syntax highlight support in text editors.

Right now, you can set Sass or Stylus syntax highlight for .sss files.

Usage

SugarSS needs PostCSS compiler. Install postcss-loader for webpack, gulp-postcss for Gulp, postcss-cli for npm scripts. Parcel has build-in support for PostCSS.

Then install SugarSS: npm install --save-dev postcss sugarss if you use npm and yarn add --dev postcss sugarss if you use Yarn.

Then create .postcssrc file:

{
  "parser": "sugarss",
  "plugins": {
    "postcss-simple-vars": {}
  }
}

Imports

If you doesnโ€™t use Webpack or Parcel, you need some PostCSS plugin to process @import directives.

If you want @import, install postcss-import and add it to .postcssrc file:

{
  "parser": "sugarss",
  "plugins": {
+   "postcss-import": {},
    "postcss-simple-vars": {}
  }
}

Mixins

For mixins support, install postcss-mixins and add it to .postcssrc file:

{
  "parser": "sugarss",
  "plugins": {
+   "postcss-mixins": {
+     "mixinsDir": "./mixins"
+   },
    "postcss-simple-vars": {}
  }
}

Now you can define your mixins in mixins/ dir. For example create mixins/circle.sss with:

@define-mixin circle $size
  border-radius: 50%
  width: $size
  height: $size

Functions

To define custom functions you need to install postcss-functions and add it to .postcssrc file:

{
  "parser": "sugarss",
  "plugins": {
+   "postcss-functions": {
+     "glob": "./functions"
+   },
    "postcss-simple-vars": {}
  }
}

Then you can define functions in functions/ dir. For example, functions/foo.js will define foo() function in CSS:

module.exports = function (args) {
  return 'foo'
}

SugarSS to SugarSS

Sometimes we use PostCSS not to build CSS, but to fix source files. For example, to sort properties by postcss-sorting.

For this cases use the syntax option, instead of parser:

gulp.task('sort', function () {
    return gulp.src('src/**/*.sss')
        .pipe(postcss([sorting], { syntax: sugarss }))
        .pipe(gulp.dest('src'));
});

CSS to SugarSS

You can even compile existing CSS sources to SugarSS syntax. Just use stringifier option instead of parser:

postcss().process(css, { stringifier: sugarss }).then(function (result) {
    result.content // Converted SugarSS content
});

Thanks

Cute project logo was made by Maria Keller.

More Repositories

1

postcss

Transforming styles with JS plugins
TypeScript
27,948
star
2

autoprefixer

Parse CSS and add vendor prefixes to rules by Can I Use
JavaScript
21,460
star
3

postcss-import

PostCSS plugin to inline at-import rules content
JavaScript
1,352
star
4

postcss-nested

PostCSS plugin to unwrap nested rules like how Sass does it.
JavaScript
1,108
star
5

postcss-100vh-fix

PostCSS plugin to fix height/min-height: 100vh on iOS
JavaScript
911
star
6

postcss-cli

CLI for postcss
JavaScript
808
star
7

gulp-postcss

Pipe CSS through PostCSS processors with a single parse
JavaScript
771
star
8

postcss-js

PostCSS for React Inline Styles, Free Style and other CSS-in-JS
JavaScript
643
star
9

postcss-scss

SCSS parser for PostCSS.
JavaScript
635
star
10

postcss-load-config

Autoload Config for PostCSS
JavaScript
618
star
11

postcss-custom-properties

Use Custom Properties in CSS
JavaScript
598
star
12

postcss-bem-linter

A BEM linter for postcss
JavaScript
561
star
13

postcss-mixins

PostCSS plugin for mixins
JavaScript
446
star
14

postcss-simple-vars

PostCSS plugin for Sass-like variables
JavaScript
409
star
15

postcss-url

PostCSS plugin to rebase url(), inline or copy asset.
JavaScript
373
star
16

postcss-color-function

PostCSS plugin to transform W3C CSS color function to more compatible CSS
JavaScript
323
star
17

postcss-media-minmax

Writing simple and graceful Media Queries!
JavaScript
290
star
18

postcss-plugin-boilerplate

PostCSS Plugin Boilerplate
JavaScript
220
star
19

postcss-calc

PostCSS plugin to reduce calc()
JavaScript
208
star
20

postcss-selector-parser

A CSS selector parser, integrates with postcss but does not require it.
JavaScript
196
star
21

postcss-reporter

Log PostCSS messages in the console
JavaScript
154
star
22

postcss-use

Enable PostCSS plugins directly in your stylesheet.
JavaScript
148
star
23

postcss-dark-theme-class

PostCSS plugin to make dark/light theme switcher by copying styles from media query to special class
JavaScript
147
star
24

postcss-easings

PostCSS plugin to replace easing names to cubic-bezier()
JavaScript
144
star
25

postcss-focus

PostCSS plugin to add :focus selector to every :hover for keyboard accessibility
JavaScript
116
star
26

postcss-safe-parser

Fault tolerant CSS parser for PostCSS
JavaScript
115
star
27

benchmark

PostCSS benchmarks
JavaScript
114
star
28

postcss-devtools

Log execution time for each plugin in a PostCSS instance.
JavaScript
92
star
29

postcss.org

Official website for PostCSS
JavaScript
81
star
30

postcss-browser-reporter

Plugin to display warning messages right in your browser
JavaScript
75
star
31

postcss-color-rebeccapurple

PostCSS plugin to transform rebeccapurple color to rgb()
JavaScript
62
star
32

postcss-deno

Postcss for Deno
JavaScript
56
star
33

postcss-brand-colors

PostCSS plugin to insert branding colors of all the major companies
JavaScript
54
star
34

postcss-size

PostCSS plugin for size shortcut
JavaScript
52
star
35

postcss-will-change

PostCSS plugin to insert 3D hack before will-change property
JavaScript
51
star
36

postcss-color-rgba-fallback

PostCSS plugin to transform rgba() to hexadecimal.
JavaScript
50
star
37

postcss-selector-matches

PostCSS plugin to transform :matches() W3C CSS pseudo class to more compatible CSS (simpler selectors)
JavaScript
44
star
38

postcss-plugin-context

Limit a PostCSS processor to a local stylesheet context.
JavaScript
33
star
39

postcss-color-hex-alpha

Use 4 & 8 character hex color notation in CSS
JavaScript
28
star
40

postcss-color-gray

Use the gray() color function in CSS
JavaScript
27
star
41

postcss-font-variant

PostCSS plugin to transform W3C CSS font variant properties to more compatible CSS (font-feature-settings)
JavaScript
25
star
42

brand

PostCSS branding files
JavaScript
24
star
43

postcss-filter-plugins

Exclude/warn on duplicated PostCSS plugins.
JavaScript
23
star
44

postcss-parser-tests

Base tests for every PostCSS CSS parser
JavaScript
21
star
45

postcss-color-hwb

PostCSS plugin to transform W3C CSS hwb() function to more compatible CSS (rgb() or rgba()).
JavaScript
21
star
46

eslint-config-postcss

An ESLint shareable config for postcss and plugins
JavaScript
18
star
47

postcss-plugin-suggestion-box

Suggestion box for PostCSS plugins
14
star
48

postcss-relative-opacity

PostCSS plugin to add opacity to any colors with Relative Color Syntax
JavaScript
11
star
49

fly-postcss

UNMAINTAINED
10
star
50

postcss-fail-on-warn

PostCSS plugin throws a error on any warning from previous PostCSS plugins.
JavaScript
8
star
51

postcss-sharec-config

Best parctices and configs from PostCSS plugin
7
star
52

postcss-at-rule-parser

A modern CSS at rule parser in PostCSS.
TypeScript
5
star
53

postcss-color

DEPRECATED - PostCSS plugin to transform latest W3C CSS color module syntax to more compatible CSS
JavaScript
5
star
54

postcss-deno-import

postcss-import plugin for Deno
JavaScript
4
star