Tigraine
Daniel Hoelbling talks about .NET

The fastest way to install dotless : nubular (nu)!

August 25th, 2010 . by Daniel Hölbling

Did you know that dependency management in the .NET open source space really sucks? For a long time have we been looking at Ruby Gems in envy of the ease of use and simplicity, spawning projects like Horn or  Bricks. And while some of these projects were promising, none really took off in a big way, so here comes another take at it: Some clever guys just talked to the RubyGem people about (ab-)using their existing infrastructure for .NET assemblies. And hey, they agreed to let us use their Gem system to distribute .NET assemblies just the way Ruby people can get Rails and all other Ruby projects.

And behold there it is: nubular (nu)

I won’t go too deep into what nu does and why it’s awesome, read Rob Reynold’s article and you’ll see the light pretty soon. Suffice it to say that nu is to assemblies what apt-get and gems is to Linux people. You just drop to the command line and tell nu you need assembly X, and if a package exists with that name it will automagically pull it down and with it all dependencies and install it to your /lib folder. Best of all, it also allows you to install binaries with it, a feature that turned out to be really cool for dotless.

Anyway, I promised you a really fast way to install dotless. Well, it can’t get any simpler than this, just drop to the command line and type (install instructions on nu are further down in this article):

nu install dotless

And now nu goes out to the gem server and just fetches dotless for you:

image

The installation just took 3 seconds, and we have the dotless.Core.dll now sitting neatly in our <currentdir>/lib/dotless folder alongside all other libraries we got through nu.

What this install also gives you is a shortcut to the dotless.Compiler.exe. Nu will install a dotless.bat in your C:\Ruby\bin (that should be in your PATH) that you can now use to compile .less files from anywhere:

image

That’s pretty cool I dare say. And now the best part: Updating dotless just got a lot easier too. Whenever we publish a new version to nu you can just hit

gem update dotless

Installing nu

So far I’ve shown you how to get dotless installed once you already run ruby gems + nubular, but for that all to work you need to install Ruby on your machine first.

Doing so is probably the simplest thing in the world right now, just hit http://rubyinstaller.org/ and you are almost set. You just need to install the nu gem afterwards and you are done installing (takes together under 2 minutes). (Note: Make sure to let the installer add Ruby to your PATH or the whole exercise is futile)

To install the nu gem just type:

gem install nu

It can’t get any simpler than this does it? Oh and btw: Ruby is completely xcopy deployable and will leave no traces behind on your machine. No services are being run and no bad things can happen to you, so there is really no excuse for a developer out there to no just go ahead and install it.

Oh, and after you’ve installed nu you can then go ahead and fetch a complete Fluent Nhibernate + Castle Windsor stack in a matter of seconds, disregarding all dependency issues since nu is handling that for you. And people are putting more stuff there by the minute: Rhino.Mocks, Fluent Nhibernate, Nhibernate, Castle Windsor, Castle DynProxy, Automapper.. etc etc.. Look at the full list and see for your self how much easier you life can become by a simple installation!


dotless Version 1.1 Released!

June 16th, 2010 . by Daniel Hölbling

logo

After a lot of work we finally released a new version of dotless. And this release is really sweet. We switched parsers from the troubled PEG parser we had to an all-new implementation of the less.js parser that gave us a ton of room for improvements and little tweaks.

Here’s a rundown of the most important features:

New Parser

New parser also means we finally have meaningful error messages and if there are syntax errors we tell you what line the error occured and what went wrong. So that’s a huge improvement for all the people who saw empty .css files trying to figure out what broke the compilation.

Parameter passing

One thing users have  been asking us for are parameters to be passed to the scripts. We finally found a good way to implement this and now it’s in.

If you use the HttpHandler you can simply pass parameters through the querystring. Let’s say you have a basecolor you want to pass to your .less file you simply call it from the site like this:

http://www.myserver.com/site.less?basecolor=#34679a

and the variable @basecolor will be set to #34679a for you in your script. This is especially handy if you are using the HSL functions where you can modify saturation, lightness etc.

If you are using the console compiler you can also leverage this new functionality through a very Ant like parameter syntax:

dotless.Compiler.exe test.less –Dbasecolor=%2334679a

Note: Parameters in querystrings have to be URL encoded or some browsers will act up.

Improved Caching

We also made sure that the cache works properly with parameters, so if two requests have the same parameters the cache will be used. If not, dotless will insert for every parameter/file combination one cache entry. Since parameters are by no means user-input values but usually limited to a set of values the designers specify this should still give you very good performance. Behind the scenes we are still using the ASP.NET cache infrastructure.

While at the topic of caching, we also improved cache invalidation. The old version did not watch all imported files for changes but only the main .less file. This has changed, you should now never have to think about disabling the cache during development.

The same change was also applied to the console compiler, if you start it with –watch the compiler will regenerate the CSS whenever any of the imported changes or the main file gets changed.

Runnable in medium trust

Well, nothing really exciting here, but you should now be able to run dotless in a shared hosting environment.

Other improvements

  1. Cleaner output
  2. better support for CSS3
  3. Many more..
    A big thanks goes to James Foster who did most of the heavy lifting involved with bringing you this new release. You can download the new version from our website at http://www.dotlesscss.com. Remember, dotless is open source and released under the Apache License, Version 2.0, the source can be easily found on GitHub.

Barcamp Vienna 2010

May 30th, 2010 . by Daniel Hölbling

I just booted my PC after 4 hours of drive through heavy rain and thunderstorms back from Vienna where I attended Barcamp. I have to say it was just fantastic! All Barcamps I attended before had a very diverse crowd, but usually lacking developers thus the social media enthusiasts usually dominated the attendees.

Barcamp Vienna was different, maybe it was the awesome location at Microsoft Austria headquarters or just the fact that it was in Vienna.. But I met more coders there in 2 days than in the last 2 yeas in Klagenfurt.

Coolest thing, I even met a Subsonic developer: Saintedlama! That was really awesome and funny when we met during breakfast randomly chatting about our stuff and I noted that I’ll be presenting dotless when he said: “Wow that’s you? I wanted to contact you for some time now about dotless. I’m working on Subsonic btw.. " (Imagine my jaw dropping right there.. ). He showed me some really cool demos of the simple repository they introduced in SubSonic 3 and it’s uses with MVC.. and I have to tell you: wow.. Using a ORM was really never so easy..

Anyway, I really had a great time either chatting up really interesting people or doing my two presentations.
On Saturday I talked about dotless while on Sunday I talked about Git. Both talks went great in my opinion, but if anyone was there and has additional feedback on my presentations I’d be glad to hear them. I uploaded both slide decks to http://www.docs.com and you can find them here:

image

dotless – CSS done right

image

Git

At any rate: Thanks to Max and Rolf for organizing this awesome event and to Microsoft for so generously hosting it!


.less repository has moved to it’s own GitHub account

March 4th, 2010 . by Daniel Hölbling

github Until now we stored the main source of the .less project in Chris Owen’s GitHub account. We now decided to create a dedicated GitHub user to host the project since Chris is no longer actively contributing and may or may not want to add changes that are not meant to be immediately committed into the mainline.

The new repository is at: http://github.com/dotless/dotless

We are still updating all references to the old project (website etc) but the move should be done fairly soon. If you are watching Chris’ repository make sure to also watch the new one as Chris’ repository may start lagging behind the mainline (depends on how often Chris will update his fork).

Oh, and btw: Thanks to the GitHub guys for providing this awesome service. Git + GitHub has simply revolutionized the way I write code and collaborate with people.


.less Compiler now supports –watch

March 3rd, 2010 . by Daniel Hölbling

It’s been on our feature list for some time and it’s been in the code for some time too. But after fixing a final bug today I guess we can tell the world about it.

The main idea behind –watch is to free you of the burden of having to configure anything but lets you just run the console-compiler once and it keeps refreshing the resulting .css files whenever a change occurs to the .less input file.

How to use? Well, simple. First grab the latest release from our website http://www.dotlesscss.com and then go to your favorite commandline and start the compiler with the –watch parameter:

dotless.Compiler.exe <filename> –watch

You will then get a nice console output telling you what is going on (and informing you of errors if any happen during compilation)

image


New stuff in .less

February 22nd, 2010 . by Daniel Hölbling

Do you remember that little project I am involved in? That .less thingy I always forget to write about? Well, it’s still around and we are going very strong. We are seeing a decent amount of activity on our mailing list and people throw code at me at various occasions for fixing different problems within the the project.

One of those persons is James Foster, a really nice guy from the UK with some mad programming skills who set out to make .less awesome. Well, he sort of did already, by contributing some major code changes to the .less parser that enabled him to port over some SASS functions to .less. Sadly he does not blog himself, so the honor is mine to report to the world what he did.

Color functions

Before going into details, the main idea is that you are now able to modify any component of a color separately. So far .less has only supported arithmetic operations on colors (like #abc000+ #000def => #abcdef) so if you e.g. want to darken a color while adding 10 points of green to it you where out of luck, making the feature not really all that useful. Well, thanks to James now we can!

Creating colors

.less understands that #FFFF is supposed to be treated as a color, so if you start working off web colors you can just use the hex notation and ignore the following functions. In case you are more the designer type settled in the RGB world and want to have lightness and alpha around, you will need functions to create the colors. And while at it James also added color literals so .less detects a @color: blue; instruction just like it would a @color:#0000FF one. Anyway, if you have your colors RGB or HSL you need to use the following functions to create them:

rgb(red, green, blue)
rgba(red, green, blue, alpha)
hsl(hue, saturation, lightness)
hsla(hue, saturation, lightness, alpha)

You might guess from the parameter names how they work. But to be thorough:

@mainColor: rgb(0, 0, 255); //Blue

Modifying colors

Now, once you hold on to a variable that contains a color you can do some pretty exciting stuff with the following color manipulation functions:

red(color, value)
green(color, value)
blue(color, value)
hue(color, value)
saturation(color, value)
lightness(color, value)
alpha(color, value)

the value can be positive or negative, for instance, to darken a color by 20% you can use “lightness(color, -20%)”.

You pass in a color and then the amount you want to change it. If you omit the change value part the method will return the appropriate component of the given color (meaning: red(@color) will return the red portion of that color, while red(@color, 10%) will increase the amount of red by 10%).

And while at it, James also added some convenience functions for good measure to make your day easier:

greyscale(color)
this is equivalent to saturation(color, -100%)

complement(color)
this is equivalent to hue(color, 180)

mix(color1, color2, weight)
mixes 2 colors together. The weight argument is optional and specifies the percentage of the first color to use compared to the second color. it also takes into account transparency – if a color is more transparent it has less effect on the resulting color.

You can get all of that functionality through the latest .less build from our website http://www.dotlesscss.com or just grab the code from GitHub. If you have any questions or suggestions feel free to participate through our mailing list.

And lastly, let’s give credit where credit is due: Thanks to James for the great work he put into .less. James himself stated that he based most of his work on stuff he saw on the Sass project, you can read about their color functions implementation here: Powerful Color Manipulation with Sass. The initial code for Sass was created by Chris Eppstein for the “compass-colors” project which has now been merged into the main Sass codebase. You can also see his pretty impressive demo here: http://chriseppstein.github.com/compass-colors/


dotless Presentation slides from Barcamp Klagenfurt

February 6th, 2010 . by Daniel Hölbling

I just finished my presentation about dotless at Barcamp Klagenfurt and promised to upload my presentation slides to Slideshare.

The feedback for the talk was quite good. Turned out better than I hoped. I just hope that the slides do make some sense without me talking alongside.


Presenting .less at the Barcamp Klagenfurt 2010

January 31st, 2010 . by Daniel Hölbling

Barcamp Klagenfurt 2010

Time goes by way faster than I’d like it to and the Barcamp Klagenfurt 2010 is coming up really fast. (6-7. February)

While usually I was quite hesitant to choose a topic due to the diversity of the attending crowd (unfortunately not really enough real technical topics represented there), this year I think I can bring something very interesting to the camp: .less.

The advantages are obvious, with a crowd of bloggers, artists and also technical people talking about something as ubiquitous as CSS, and ways to improve it, will surely resonate well, allowing me to be a bit technical without raising too many question marks above my audience’s heads like last year (where I talked about IoC and Windsor).

As for the talk itself, I plan on first going over general features of Less (since we are a port I can also point people over to the Ruby version if they are more comfortable with that than with .NET ), and then into a tiny bit of detail about how .less works internally.

Finally, I hope to see as many people as possible at Barcamp Klagenfurt! Thanks to the team for organizing this year after year!


.Less now supports files from the VirtualPathProvider!

January 6th, 2010 . by Daniel Hölbling

Ok, I’ve just spent almost the whole day refactoring the hell out of our .less codebase just to add one tiny change:

Allow users to not only load files present on the current file system, but also directly from in-memory strings and VirtualPaths (as requested on the list). The problem here being that not everyone wants to serve his .less files right from the server’s file system but sometimes people have pretty sophisticated virtualized storage systems in place that require them to use the VirtualPathProvider abstraction that was added to .NET 2.0.
You can read up on that in ScottGu’s blog or David Ebbo’s blog, but in a nutshell it’s just another way to open files besides using System.IO.File.Open(), letting you forget about all the nasty stuff of where the file is really located. 

To do so I had to allow uses to plug in different “Sources” for .less code, and so I also had to make a breaking change to the main ILessEngine interface. The Interface was taking a filename as parameter, but in light of our recent support emails on the development list I decided that has to go away in favor of a more open approach (mainly to allow users to simply throw in-memory strings at the engine).

Because I know this will break some code, all implementors of ILessEngine still offer the old string parameter as an overload that then defaults to the default FileSource.

Now, for changing the source provider:

If you want to use anything besides the default filesystem based FileSource provider, you now have the ability to plug in a type implementing ILessSource through the DotLessConfiguration (thus through web.config).
.Less comes with three sources built in: VirtualPathSource, FileSource (default).

FileSource by default just opens a file through System.IO.File, while VirtualPathSource will use the HostingEnvironment.VirtualPathProvider.GetFile() method to open a Stream and read the .less code from there.

To enable the VirtualPathSource in your web application you simply need to modify your web.config a bit:

<dotless minifyCss="false" cacheEnabled="true" source="dotless.Core.VirtualPathSource">
  
</dotless>

The important part is the source attribute as it has to reference a type name implementing ILessSource. So if you want to create your own less source you could simply create another implementation of ILessSource and reference it’s name in the .less config.

If you want to use .less directly from your code to transform something you can just new up a LessSourceObject (the very output we get from ILessSource) and throw your code in there like this:

ILessEngine lessEngine = new EngineFactory().GetEngine(new DotlessConfiguration());
var output = lessEngine.TransformToCss(new LessSourceObject() {Content = "my .less code here"});

As always you can get the latest code from GitHub, or the latest binary release through our TeamCity build server. You can read more about .less (pronounced dot-less) on the project’s website at http://www.dotlesscss.com.

And while at it, we’d appreciate it if you spread the word about .less :) .


Introducing: Tigraine.Logging

December 27th, 2009 . by Daniel Hölbling

Stop rolling your eyes, I know there are more logging infrastructure libraries out there than there are projects using them. And I won’t say this one is different, it’s not. It’s more or less a little experiment I did to get accustomed to VS2010 and R#5.
Also note that most of the code originated from me writing a logging architecture for a Java OSS project I’m involved with and I wanted to carry the idea over to .NET.

But: I believe it turned out to be quite nice while very very lightweight. So I thought I’d just go ahead and share it.

Usage

Tigraine.Logging has a ILogger interface that exposes the usual suspects:

image

You just instantiate the appropriate ILogger implementation and are set to go, it will write everything you pass to it.

What makes out most of the code though is the ability to render objects passed into the logger as parameters. This idea came from the Java codebase where there was code like this scattered all over the place:

@Override
public String toString() {
	String ret = this.getClass().getSimpleName();

	if (Config.logVerbosity >= Log.Verbosity.VERBOSE) {
		ret += "(" + this.hashCode() + ")";
	}

	if  (Config.logVerbosity >= Log.Verbosity.VERBOSE) {
			ret += " A={" + this.a + "}, B={" + this.b + "}";
	}

	return ret;
}

Now, I hate that sort of code. It’s just noise and it tends to get messy really soon. And so I started implementing my idea of ObjectRenderers (I know this term is already used by other logging frameworks, and the idea is not new either):

image

You add a renderer to the logger and whenever a object is passed in of the type, the renderer is invoked to transform the object to a string representation of your choosing. So instead of having to rely on .ToString() to give accurate results, you implement a class that takes care of writing all relevant information of your object down.

Here is a sample:

var consoleLogger = new ConsoleLogger(LogLevel.Debug);
consoleLogger.AddObjectRenderer<TestClass>(new TestClassRenderer());

consoleLogger.Error("Something went wrong with {0}", new TestClass());

The logging framework will call TestClassRenderer.Render to get a string representation of TestClass. This now also means you can have two different renderers, one verbose and one brief, and only hook up the one that’s right for you right now. The calling code does not need to be touched.

You can also define a renderer for a supertype and all subclasses will use that one if no more specific renderer is hooked up. If no renderer is found whatsoever .ToString() will get called.

And since implementing all renderers in their own classes would lead to a lot of code, there is a little helper class that should work for most of you by using some lambda syntax:

var compositeRenderer = new CompositeRenderer<TestClass>
    (p => p.Firstname + " " + p.Nickname + " " + p.Age);

Where to get

You may have already guessed, Tigraine.Logging can be found on GitHub and is open-source under the Apache License Version 2


« Previous Entries