<?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>Tim Babych’s thoughts &#187; django</title>
	<atom:link href="http://blog.clear.com.ua/category/django/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.clear.com.ua</link>
	<description>Thoughts on web, things and so on</description>
	<lastBuildDate>Tue, 22 Nov 2011 14:14:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>CleverCSS</title>
		<link>http://blog.clear.com.ua/2009/09/clevercss/</link>
		<comments>http://blog.clear.com.ua/2009/09/clevercss/#comments</comments>
		<pubDate>Mon, 21 Sep 2009 13:37:47 +0000</pubDate>
		<dc:creator>tim</dc:creator>
				<category><![CDATA[django]]></category>
		<category><![CDATA[CSS]]></category>

		<guid isPermaLink="false">http://blog.clear.com.ua/?p=68</guid>
		<description><![CDATA[Never, ever I will write plain old CSS, nesting rules over and over and renaming all the stack when the root element has to be changed. Imagine this monstrosity .featured_retailers { border: 2px solid #FFC77B; margin-bottom:10px; width: 626px; position: relative; &#8230; <a href="http://blog.clear.com.ua/2009/09/clevercss/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Never, ever I will write plain old CSS, 
nesting rules over and over and renaming all the stack 
when the root element has to be changed.</p>

<p>Imagine this monstrosity</p>

<div>
<pre class="brush: css;">
.featured_retailers {
    border: 2px solid #FFC77B;
    margin-bottom:10px;
    width: 626px;
    position: relative;
    }
    .featured_retailers table { width: 626px; }
        .featured_retailers td {
            padding: 0;        
            border-top: 2px solid #FFC77B;
            }
        .featured_retailers td table {
            width: 440px;
            }
            .featured_retailers td table td {
                border: 0;
                padding: 1px 5px;
                }
    .featured_retailers p {
        font-weight:bold;
        color: #333;
        position: absolute;
        top: -30px;
        right: 0;
        }
        .featured_retailers p img {
             vertical-align:middle 
             }
</pre>
</div>

<p>turning into</p>

<div>
<pre class="brush: css;">
$bgcolor=#FFC77B
.featured_retailers:
    border: 2px solid $bgcolor
    margin-bottom:10px 
    width: 626px
    position: relative
    table: width: 626px 
        td:
            padding: 0        
            border-top: 2px solid $bgcolor
            table:
                width: 440px
                td:
                    border: 0
                    padding: 1px 5px
                
    p:
        font-weight:bold
        color: #333
        position: absolute
        top: -30px
        right: 0
        img:
             vertical-align:middle 
</pre>
</div>

<p>That magic is done by <strong><a href="http://sandbox.pocoo.org/clevercss/">cleverCSS</a></strong>.
It is written by maniacs (they added variable and 
expression support but went a bit too far: who would ever want to calculate sqrt of length?)
but it gets the job done.</p>

<p>Original authors seem to have abandoned it, but it is supported by community.
I added my two cents too:</p>

<ul>
<li>its calculation feature was not aware of negative numbers, trying to calculate the sum 
, so <em>margin: -2px -2px</em> was transformed into <em>margin:-4px</em></li>
<li>its support for /* multiline comments */ was not working, unless they were on the same line</li>
</ul>

<p>And for integration of CleverCSS into your Django site there is <a href="http://github.com/dziegler/django-css">django-css</a> project. 
It is a CSS and JS compressor, but the compression is not what you would be after. 
The point is that django-css compiles CSS with external compilers,
and caches the output in a clever way.</p>

<p>There were few things that could be improved there:</p>

<ol>
<li>It was relying on binary commands, 
while using Pythonic compiler in Python would be more logical.</li>
<li>It was leaving compiled files not only in cache, but in my source tree, 
near the originals.</li>
</ol>

<p>Also, I often use inline STYLE blocks for specific templates. 
Why have the hassle of separating them into files? The only reason can be that
if page-specific CSS is large, the browser constantly redownloads it, and it is not nice.</p>

<p>So I added that feature to django-css too, 
and now it is almost perfect tool for complex Django CSSing.
You can have extended CSS files compiled and cached, no matter where it is, 
in LINKS or in STYLE blocks.</p>

<p>All you have to do is surround your STYLE or LINK with {% compress css %} tag.</p>

<div><pre class="brush: css">
{% compress css %}
&lt;style type="ccss"&gt;
h1:
    color:red
&lt;style&gt;
{% compress css %}
</pre>
</div>

<p>Forked Repos:</p>

<ul>
<li><a href="http://github.com/tymofij/clevercss">CleverCSS</a></li>
<li><a href="http://wiki.github.com/tymofij/django-css">Django-CSS</a></li>
</ul>

<p>PS: Github is a very nice collaborative tool, it is fun to work with. I just like BitBucket more <img src='http://blog.clear.com.ua/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.clear.com.ua/2009/09/clevercss/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

