Monday, January 25, 2010

Groovy DSL for CSS (Part 2)

Now that we can assign units to numerical values (Part 1) I'll see if I can start putting things together for CSS declarations and rules.

CSS Declarations

In CSS declarations are the statements where you define properties and assign a value to them.

CSS Declaration Examples

These declaration statements are contained within a Rule block which has one or more identifiers. a.k.a. class names, ids, and element names.

CSS Rule Block Example

The Declaration class

The Declaration class is pretty basic it has a name and value. The toString() method will return the CSS declaration name:value.toString();

The Rule class

The rule class is a bit trickier so far I haven't found a way to get around defining getters and setters for all the possible declarations which may not actually be that bad except for having to write them.

The Rule is backed by a Map which stores the declaration name as the key to a declaration. The toString() method returns the CSS for the entire rule.

I have also added a method to the String's metaClass in the Bootstrap.

Now a Rule object can be created off of any String and it actually almost looks familiar.

Testing Declaration and Rule

Ive uploaded the experiment to Google Code and the sources are available at Source.

Sunday, January 24, 2010

Groovy DSL for CSS (Part 1)

I decided to experiment with writing a DSL for CSS in Groovy. There are some other DSLs out there like SASS but I think the syntax is almost worse than writing normal CSS and it definitely doesn't look similar to CSS. So the main goals are going to be:
  • 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 values

I'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 class

This 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 class

Now 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.


Using 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

Tuesday, January 19, 2010

Sonar Not Running?

You've got Hudson or another CI system setup for your project and your trying to track code quality with Sonar but you start getting build failures and Sonar isn't running.

The Problem
By default maven will fail a build if there are test failures. When Sonar tries to execute sensors like FindBugs that analyze at the bytecode level it will fail before decorating and saving the results. 

Setting maven.test.failure.ignore=true will allow Sonar to run even if there are test failures which actually works out nice since that is something you want to trend anyways.

Sunday, January 17, 2010

RoboTruck now has Wifi

Finally a couple warmish days to get the Wifi and SSH setup in Moblin.
If only TightVNC server

  1. Didn't have a (non configurable) dependency for fonts
  2. Linux applications QUIT USING SYSTEM DEPENDENCIES! Package the app AS AN APPLICATION!
  3. Why does VNC need to know where fonts are installed anyways? Shouldn't X server handle that?
Maybe yum and apt will go away and we'll get to use something decent like Maven

Anyways a couple of pics of the truck.