<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>John On Web Stuff &#187; ruby</title>
	<atom:link href="http://blog.geekyjohn.com/tag/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.geekyjohn.com</link>
	<description>My take on web things. Sometimes witty. Sharing of stuff.</description>
	<lastBuildDate>Tue, 06 Apr 2010 11:26:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Write less with Less to make more CSS</title>
		<link>http://blog.geekyjohn.com/2009/07/write-less-with-less-to-make-more-css/</link>
		<comments>http://blog.geekyjohn.com/2009/07/write-less-with-less-to-make-more-css/#comments</comments>
		<pubDate>Sun, 05 Jul 2009 02:55:25 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://blog.geekyjohn.com/?p=191</guid>
		<description><![CDATA[Less is a CSS pre-processor that I came across recently and there seems to be quite the buzz going around about it. Including some discussion about what is good about it, what really sucks about it, and so on.

After seeing some of the drawbacks, and the advantages of using Less, I've decided that it should be put through it's paces and I'll be trying to use it in a project in the near future so I can see if it will be a benefit.]]></description>
			<content:encoded><![CDATA[<p><a title="Less CSS" href="http://http://lesscss.org/" target="_blank">Less</a> is a <abbr title="Cascading Style Sheets">CSS</abbr> pre-processor that I came across a short while ago and there is quite a bit of buzz going around about it, including <a title="Write better CSS with Less - Sitepoint.com" href="http://www.sitepoint.com/blogs/2009/06/30/write-better-css-with-less/" target="_blank">some discussion at Sitepoint</a> about what is good about it, what really sucks about it, and so on.</p>

<p>After seeing some of the drawbacks, and the advantages of using Less, I&#8217;ve decided that it should be put through it&#8217;s paces and I&#8217;ll be trying to use it in a project in the near future so I can see if it will be a benefit.</p>

<h3>A quick breakdown of what Less is</h3>

<p>Less adds variables, mixins, operations and nested rules to CSS. This will enable us to treat our CSS a bit more like a programming language rather than a style descriptor language.</p>

<p><span id="more-191"></span></p>

<h3>Compiling</h3>

<p>You write Less in to a <code>.less</code> file and use the Less compiler to turn it into a <code>.css</code> file.</p>

<p>Worried about having to compile all the time? With the Less compiler, simply set the &#8216;watch&#8217; option on the command line and it will keep tabs of your <code>.less</code> file and compile it whenever there are changes.</p>

<p>To do a quick compile:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$  lessc styles.less my_styles.css</pre></div></div>


<p>You can leave the name of the css file off, if you do, Less will use the same filename as the <code>.less</code> file, with a <code>.css</code> extention of course.
To watch a file:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$  lessc styles.less <span style="color: #660033;">--watch</span></pre></div></div>


<h3>Variables</h3>

<p>Variables in CSS are an <strong><em>fantastic</em></strong> concept, I can&#8217;t believe that they weren&#8217;t part of the CSS spec in the first place! For example, by being able to define a colour or width in a variable, you can save yourself a lot of time and hassle. Seriously, who wants to remember that the brand colour for your current client is #0062fc?
Consider the following CSS that you would normally write:</p>


<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">p <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#0062fc</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
h2 <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#0062fc</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span></pre></div></div>


<p>You would write this in Less as follows:</p>


<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #a1a100;">@brand_colour: #0062fc;</span>
p <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #a1a100;">@brand_colour; }</span>
h2 <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #a1a100;">@brand_colour; }</span></pre></div></div>


<p>This is of course a very simple example, I&#8217;m sure that if you think about the implications of this, that you&#8217;ll see how powerful having variables in a language like CSS really is.</p>

<h3>Mixins</h3>

<p>Mixins are essentially rules that are included in other rules.
Instead of doubling up on writing the same bit of code for several items, you include the code that is generic in the other class. Think of it a very simplified extending of classes in OO languages.</p>


<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.bordered</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#000</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.box</span> <span style="color: #00AA00;">&#123;</span>
  .bordered<span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">200px</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">200px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>


<h3>Nested rules</h3>

<p>You can also nest rules with Less, meaning that you&#8217;ll have to write less code and you can write code that is cleaner to read.
For example:</p>


<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#sidebar</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#000</span><span style="color: #00AA00;">;</span>
  p <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#00c</span><span style="color: #00AA00;">;</span>
  <span style="color: #00AA00;">&#125;</span>
  q <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">font-style</span><span style="color: #00AA00;">:</span><span style="color: #993333;">italic</span><span style="color: #00AA00;">;</span>
  <span style="color: #00AA00;">&#125;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>


<p>This would be compiled to:</p>


<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#sidebar</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#000</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#sidebar</span> p <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#00c</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#sidebar</span> q <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">font-style</span><span style="color: #00AA00;">:</span><span style="color: #993333;">italic</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span></pre></div></div>


<h3>Operations</h3>

<p>You can perform all sorts of operations on numbers, colours, pixel values. This will allow you quickly do things like set something to the same width as the main wrapper minus an arbitrary amount.</p>


<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #a1a100;">@main_page_width: 800px;</span>
<span style="color: #a1a100;">@sidebar_width: 200px;</span>
&nbsp;
<span style="color: #cc00cc;">#content</span> <span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #a1a100;">@main_page_width - @sidebar_width;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>


<p>As you can see Less can be very helpful in writing CSS, rather, writing less CSS to achieve more, quicker. Since you don&#8217;t have to spend a lot of time learning the syntax of the language, you can get right on with coding!</p>

<p>Make sure you check out the <a title="Less CSS" href="http://http://lesscss.org/" target="_blank">Less website</a> for more information.</p>

<p>Less runs on Ruby, and has to be installed as a Ruby gem. I have had a play around with this on my Macbook, I have yet to give it a whirl on my Windows machine to see how easy this is to use on that platform. You don&#8217;t need to build your website using Ruby, or Ruby on Rails, you only need to have Ruby installed on the computer that your are using to build your site.</p>

<p>I have also seen 2 other CSS pre-processors, <a href="http://code.google.com/p/dtcss/" target="_blank">dtCSS</a> and <a href="http://www.shauninman.com/archive/2008/05/30/check_out_css_cacheer" target="_blank">CSS Cacheer</a>. Both are PHP based, and might be worth a look if Less isn&#8217;t what you&#8217;re after.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.geekyjohn.com/2009/07/write-less-with-less-to-make-more-css/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
