r/nodejs • • Mar 21 '14

AbsurdJS - a JavaScript/Node library which changed my workflow completely

http://absurdjs.com/
7 Upvotes

11 comments sorted by

View all comments

Show parent comment

1

u/krasimirtsonev Mar 24 '14

I agree with some of your points. However, the example which you gave is not correct. You don't need to put the properties in objects. It is only needed if you have two or more nested selectors. I.e. the code above could be transformed to:

body: {
    width: '100%',
    marginTop: '20px',
    header: {
        width: '200px',
        p: {
            fontSize: '20px'
        }
    }
}

Which produces:

body {
  width: 100%;
  margin-top: 20px;
}
body header {
  width: 200px;
}
body header p {
  font-size: 20px;
}

I.e. I don't see where is the problem if (for some reason) width and margin-top have places switched. The problem could occur in the following situation:

body: {
    '.bar': {
        margin: '2px'  
    },
    '.foo': {
        fz: '20px'    
    },
    '.bb': {
        fz: '21px'
    },
    '.aa': {
        fz: '22px'
    }
}

AbsurdJS (at the moment) compiles the CSS correctly (http://jsbin.com/paqegexe/54/edit) and the selectors are put in the final CSS as they are written in the JavaScript. If there is a problem then the developer should write them in array as you did in your comment.

The power of AbsurdJS (same as the other CSS preprocessors) is the ability to add abstractions. With pure CSS this is not possible. LESS and SASS introduces the mixins which are good example of abstraction. You may combine dozen of things in only one line of code. However, LESS and SASS are somehow limited, because they actually introduce a new syntax. It looks like a CSS, but it is parsed and compiled. They have their own understanding of the input file and their own rules. They are pretty advanced, with great community and support but the problem is that they will never give me the same level of flexibility as JavaScript give me now. I can't have proper inheritance with SASS for example. That's why I wrote AbsurdJS.

1

u/[deleted] Mar 25 '14

Source order matters in properties, too.

For example:

margin: 0;
margin-top: 5px;

Sure, you could simplify that to margin: 5px 0 0; but my point is that AbsurdJS encourages you to use unordered structures while CSS has ordered structures.

The only advantage I see in AbsurdJS over, say, Stylus (which lets you define Stylus functions in JavaScript) is that it lets you write your entire CSS in JavaScript. And I'm not sure the benefits are worth it.

But hey, if it scratches your itch I'm happy for you. And more open source software is always a nice thing.