- Have a syntax that looks almost like CSS
- Be able to re-use code (something CSS should really have anyways)
- Through variables
- Through inheritance (even to the extent that you could package a set of classes in a jar and include that jar in any application)
- For numeric values be able to perform calculations.
Handling Numeric valuesI'll start off with something simple, adding units to numeric values. I looked into Groovy Categories but they seemed to be pretty limited for what I wanted and decided to add methods to the Number class using the ExpandoMetaClass.
The NumericValue classThis will be treated as a Number, the basic operators have been overloaded and it implements Comparable. The toString() method will generate CSS text.
The Unit class will be used in conjunction with Number and NumericValue
Adding methods to the Number classNow we need to add methods to the Number class in a Bootstrap so that when you use something like 1.px a NumericValue object is created with a value of 1 and unit of px.
TestingUsing easyb we can write a scenario that tests the NumericValue class. First we will add the methods to the Number's metaClass by calling the Bootstrap then create a NumericValue of 1px and verifying that the toString() method returns the expected value.
Ive uploaded the experiment to Google Code and the sources are available at Source.
Next I'll work on a coplete CSS Declaration and Rule