Wess: the Wedge preprocessor for CSS

Nao

  • Dadman with a boy
  • Posts: 16,082
Wess: the Wedge preprocessor for CSS
« on May 10th, 2011, 07:01 PM »Last edited on October 16th, 2012, 01:00 AM
Feature: Wess (or WESS, or WeCSS, as you like...)
Developer: Nao
Target: themers, modders
Status: 100% (believed to be complete; given its nature, however, new features are being added regularly as needed.)
Comment:

This is one of the features that make me glad I made them, even though it took me many months of work. For the record, back in January 2011, I read an article about Sass, a CSS pre-parser written in Ruby. I already had plans to write something in that style, but they were nowhere near as advanced as their implementation, so I took inspiration and wrote my own PHP version. As a result, it's about 20 times smaller than Sass, and much faster. It's also a bit less elegant (in that it doesn't optimize resulting rules), and stricter in its structure, but I consider this to be a good thing. Finally, Wess also deals with JavaScript and CSS compression, although the line between Class-CSS[1] and Subs-Cache[2] is becoming increasingly blurrier. (Is that proper English?)

Given that Wess is an extremely complete (and sometimes overwhelming) implementation, it deserves, and will eventually get, its own documentation in the near future.
In the meantime, here's an incomplete list of features:

- selector inheritance ('extends' keyword),
  - multiple inheritance (both from and to),
  - prevent single rules from being inherited by children ('final' keyword),
  - cancel inheritance ('unextends' keyword, useful for inherited skins),
  - delete a property entirely ('@remove' command),
  - reset a selector's earlier styles ('@reset' command, also useful for inherited skins),
  - declare virtual selectors that will disappear once they're mixed or inherited.
- nested selectors,
- normal or simplified syntax (no {}; etc.),
- color manipulation functions,
- math functions,
- mixins (supporting parameters),
- variables,
- @if/@else/@endif (test for a browser or environment, and execute CSS accordinly),
- @is (basically an inline @if),
- & shortcut (current selector),
- cross-browser gradients,
- prefix-free CSS3 styles (just the common ones),
- grouping of properties with identical values (e.g. height, line-height: 20px),
- RGBA emulation in IE,
- and inline graphics where supported (can be disabled on a per-file basis.)

The example below is taken straight from our current index.css, and it uses many of the aforementioned features... Try to figure out what does what!

.catbase virtual
   overflow: hidden
   border-radius: 5px
   padding: 5px 10px 5px
   margin-bottom: 4px
   border: 1px solid rgba(0,0,0, .15)
   font: 700 1.4em/20px $big_font
   img
      vertical-align: -3px

.cat extends .catbase
   background-color: #b3afa9
   color: white
   a
      color: white
      text-decoration: underline
      font-size: .92em
      text-shadow: none
      :hover
         color: #fc9
     .cat final
   background-color: #c3b9c3
   border-color: #fd9604
   border-width: 2px 0 0 0
   text-shadow: black 0 1px 2px
   .table_list &
      margin: -5px

.title extends .cat
   padding: 4px 8px
   border, margin: 0
   #sidebar &
      margin-top: 6px
   a
      color: #faf8f8
 1. The main Wess core...
 2. The list of functions that create the actual CSS and JS files and pass them through Wess or other functions.

Re: WeCSS: the Wedge CSS parser
« Reply #1, on May 11th, 2011, 01:35 AM »
Wow, I just learn to theme a little bit... And now I have to learn this? :P


Re: WeCSS: the Wedge CSS parser
« Reply #3, on May 11th, 2011, 09:07 AM »
Quote from DoctorMalboro on May 11th, 2011, 01:35 AM
Wow, I just learn to theme a little bit... And now I have to learn this? :P
Not at all. Nothing forces you to use the new features. Your 'old' CSS files for mods and themes are still going to be accepted by Wedge, obviously. I'm just providing a tool for authors who are annoyed with the CSS syntax and its lack of active features.

Re: WeCSS: the Wedge CSS parser
« Reply #4, on May 11th, 2011, 09:13 AM »
But who'd want to destroy their life on duplicating common CSS rules when you can use this new syntax with extend and all the neat stuff? I still want to live more than thirty years,  thanks.

It'd be nice, er no, awesome if CSS4 implemented at least some of those features.

Re: WeCSS: the Wedge CSS parser
« Reply #5, on May 11th, 2011, 12:10 PM »
Quote from Bloc on May 11th, 2011, 11:58 AM
While such a tool would be great to sort things out, i do wonder if its the way people use CSS that tends to make files big and cluttered. Too often they dress something with a unique style that could be just as well made into a common class. If they took the time to strip it down to bare bones, and THEN start looking at where things would be different, it would be better.Curve theme is a prime example of just adding template specific style after style..when theres clearly so much common items between pages. Evey little tweak gets a new style...
Actually, there are two schools in this, and it's important to understand that *none of them are wrong*. Ultimately, it's up to the themer's taste really.

There are those who think that each page should have its own ids, and style generic blocks accordingly for each page (I will call them "the school of semantics"), and those who think that templates should sort it out and generate many different generic blocks and use them directly in the templates (I will call them, "the school of objects"). Objects and semantics are both 'big' in general web development, but they can hardly be used together in CSS.

CSS frameworks started from objects (see OOCSS) -- they defined many, many minor blocks, like Lego cubes, and allowed designers to simply specify what they wanted in their templates, like "<div class="window1 cols2 lines3 line-height5">, things like that. Now that's the second school. It's obviously an interesting concept, but is better served with pre-parsing and a more specific div. So, if you inherit "<div class="this_place">" from window1, cols2, lines3 and line-height5, you get both the object abstraction, and the semantics of a proper name. It's the best of both worlds really. Of course, in order to use it at its best, you need to be very strict about your code.
It was pretty much impossible to rewrite the templates entirely, and it would have made it harder to target specific pages anyway, so I did my best to keep the old structure, and still build upon it with my pre-parser.

I think I've achieved my goals, but I can only tell when I see themers release CSS files using these techniques.
Quote
Personally I doubt I will be using it that much - having it the old cluttered way force me to be more efficient(and i haven't up to now, really, but with my latest I do try to do exactly that).
Up to you, really.
Just as long as you don't write CSS that should be mixed with WeCSS stylesheets, you can use the old style all you want. (Heck, you can even use nested selectors and a few others in the old-style format.)
Quote
Another thing is also that making a design - at least when everything isn't already drafted out - tends to be a nonlinear thing. You think of a certain look, and don't bother looking at existing styles, just throw in a new to get that *look* and move on in the creative process. When the time comes to clean up, its often too easy to just let it be."it works" lol.Been victim to that too.
I don't know, I'd tend to say that on the contrary, wecss is best used on clean slates.
Quote
Thats why i think this will appeal more to coders doing design - but not necessarily designers doing code. ;)
Possibly ;)
Re: WeCSS: the Wedge CSS parser
« Reply #6, on May 11th, 2011, 12:11 PM »
Quote from live627 on May 11th, 2011, 09:13 AM
But who'd want to destroy their life on duplicating common CSS rules when you can use this new syntax with extend and all the neat stuff?
Designers, apparently :P
Quote
It'd be nice, er no, awesome if CSS4 implemented at least some of those features.
Agreed. Even if it's not MY syntax :P I'll be perfectly happy if they reproduce the Sass style.

Re: WeCSS: the Wedge CSS parser
« Reply #7, on May 11th, 2011, 02:38 PM »
I will miss brackets... They made my understanding of CSS a little bit easier :(

Well, I've seen a couple of sass tuts, so I'll read them to understand WeCSS.

BTW: The source code will only be available in wedge?

Re: WeCSS: the Wedge CSS parser
« Reply #8, on May 12th, 2011, 01:42 AM »
Again, you don't have to give up on the CSS syntax. Most features (if not all, I haven't looked into it) will still be usable.

Yes, WeCSS is Wedge-only, in the sense that it will be available under the Wedge license.
In the future we may go BSD as well, in which case I will probably use the opportunity to set up custom repositories for WeCSS, Zoomedia and a few other components I've been writing and may be useful to software outside of Wedge.


Re: WeCSS: the Wedge CSS parser
« Reply #10, on May 12th, 2011, 02:24 AM »
As you wish. If the standard is flawed, it's up to developers to take things into their own hands. That you disagree that the standard is flawed is okay with me -- but remember that you'll still have to program in wecss if you want to edit the main stylesheet (or add a custom.css), since Wedge uses wecss consistently across the project.


Re: WeCSS: the Wedge CSS parser
« Reply #13, on May 12th, 2011, 11:37 AM »
In the end, what matters is that you can do it the way you like.
The only issue is if you're doing an actual add-type child styling, or just building upon index.css by doing a custom.css, things like that. The two styles aren't compatible. They were at some point, but then I started merging the different files before processing, because it saved a lot of CPU time. I'm not convinced there's a point in providing an alternative.
I guess those who really hate WeCSS can consider staying on SMF... It's not like it's a big deal :^^;:

Or they can write in regular CSS, and then convert to WeCSS once they're done. It's not hard to do -- I did it for all of SMF's css files after all. Replace with " {\n" with "\n", replace all ";\n" with "\"n, replace all "}\n" with "\n", and you're done -- as long as you keep the indentation correct.

Re: WeCSS: the Wedge CSS parser
« Reply #14, on May 26th, 2011, 07:53 PM »
Only one sentence: That's the way things CSS has to be!  :cool:

Should be part of CSS3.1 ...  :D

Re: WeCSS: the Wedge CSS parser
« Reply #15, on May 26th, 2011, 10:29 PM »
It never will and it's for the best. Just like jQuery for JS, we need a higher level library for CSS and that what wecss is aiming to be!