<?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>SquaredRoot &#187; CssHandler</title>
	<atom:link href="http://www.squaredroot.com/tag/csshandler/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.squaredroot.com</link>
	<description>.Net Development in DC</description>
	<lastBuildDate>Sun, 16 Aug 2009 01:30:15 +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>CssHandler: CSS + Variables</title>
		<link>http://www.squaredroot.com/2007/11/16/csshandler-first-release/</link>
		<comments>http://www.squaredroot.com/2007/11/16/csshandler-first-release/#comments</comments>
		<pubDate>Fri, 16 Nov 2007 16:54:00 +0000</pubDate>
		<dc:creator>Troy Goode</dc:creator>
				<category><![CDATA[Tools]]></category>
		<category><![CDATA[CodePlex]]></category>
		<category><![CDATA[CssHandler]]></category>
		<category><![CDATA[open source]]></category>

		<guid isPermaLink="false">/post/2007/11/16/CssHandler-First-Release.aspx</guid>
		<description><![CDATA[It&#8217;s been more than three and a half years since Rory Blyth said &#8220;screw standards — let&#8217;s add variable support to CSS right this minute.&#8221; In retrospect, adding variables to CSS seems obvious; everyone is asking about it. There have even been one or two other .Net solutions developed, though Rory&#8217;s solution has remained my [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been more than three and a half years since <a href="http://www.neopoleon.com">Rory Blyth</a> said &#8220;<a href="http://www.neopoleon.com/home/blogs/neo/archive/2004/03/06/8705.aspx">screw standards — let&#8217;s add variable support to CSS right this minute</a>.&#8221; In retrospect, adding variables to CSS seems obvious; <a href="http://www.google.com/search?q=css+variables">everyone is asking about it</a>. There have even been <a href="http://www.codeproject.com/useritems/CSSVariables.asp">one</a> or <a href="http://aspnetresources.com/articles/variables_in_css.aspx">two</a> other .Net solutions developed, though Rory&#8217;s solution has remained my favorite. With CSS2 barely working and <a href="http://www.w3.org/Style/CSS/current-work">CSS3 not addressing the issue</a>, those of us who are tired of repeating ourselves throughout our CSS files have no choice but to take matters into our own hands.</p>
<p>With that in mind I set out to update Rory&#8217;s code. Not that there was anything wrong with it in the first place, of course (this is where I try to tactfully avoid being drawn as a jerkasaurus in one of Rory&#8217;s comics), but Rory did whip the code up for a <a href="http://www.padnug.org/">PADNUG</a> meeting and that <em>was</em> about 3.5 million years ago (give or take many orders of magnitude). It was time to bring the CssHandler into 2007! Conveniently right before 2008.</p>
<p>Lo and behold, someone else had beat me to it. <a href="http://codingpatterns.blogspot.com/">Gabe Moothart</a> had already <a href="http://www.codeplex.com/CssHandler/">uploaded the CssHandler to CodePlex</a>, and even improved upon it. While Rory&#8217;s code originally only allowed variable declarations &amp; references and stripped comments, Gabe&#8217;s version also resolved application-relative paths (e.g.: &#8220;~/blah/blah.gif&#8221;) into browser friendly paths. I had further goals in mind though, and Gabe was kind enough to add me onto the project.</p>
<p>With my updates complete, I am now proud to present&#8230;</p>
<h2>CssHandler 1.0</h2>
<p><em>Features</em>:</p>
<ul>
<li>Define variables for later reference.</li>
<li>Resolve application relative paths.</li>
<li>Only link to one CSS file from your HTML page. Let the CssHandler combine additional CSS files at runtime to limit HTTP connections and share variable definitions across files.</li>
<li>All comments are stripped before render.</li>
<li>Most white-space is stripped before render.</li>
<li>HttpHandler can be mapped to *.css or can be referenced as CssHandler.axd and passed a CSS file in the query string.</li>
</ul>
<p><em>Bugs fixed</em>:</p>
<ul>
<li>The @define{&#8230;} block is no longer sent down to the client.</li>
<li>Similarly named variables no longer present a problem.</li>
</ul>
<p><em>Example</em>:</p>
<p>The HTML references &#8220;styles.css&#8221;, which looks like:</p>
<p><a href="/image.axd?picture=WindowsLiveWriter/CssHandlerCSSVariablesLove_A91A/CssHandler_stylecss_2.jpg"><img style="border-width: 0px" src="/image.axd?picture=WindowsLiveWriter/CssHandlerCSSVariablesLove_A91A/CssHandler_stylecss_thumb.jpg" border="0" alt="CssHandler_stylecss" width="458" height="332" /></a></p>
<p>As seen above, &#8220;styles.css&#8221; references &#8220;styles2.css&#8221; via the @import statement, which looks like:</p>
<p><a href="/image.axd?picture=WindowsLiveWriter/CssHandlerCSSVariablesLove_A91A/CssHandler_style2css_2.jpg"><img style="border-width: 0px" src="/image.axd?picture=WindowsLiveWriter/CssHandlerCSSVariablesLove_A91A/CssHandler_style2css_thumb.jpg" border="0" alt="CssHandler_style2css" width="459" height="55" /></a></p>
<p>The CssHandler then:</p>
<ol>
<li>Intercepts the browser&#8217;s request for &#8220;styles.css&#8221;.</li>
<li>Resolves the two URLs that are using application relative paths.</li>
<li>Replaces the @import directive with the text from &#8220;styles2.css&#8221;.</li>
<li>Strips all comments from the CSS.</li>
<li>Replaces all referenced variables with their defined values.</li>
<li>Compresses most of the CSS&#8217;s white-space.</li>
<li>Renders the following to the browser:</li>
</ol>
<p><a href="/image.axd?picture=WindowsLiveWriter/CssHandlerCSSVariablesLove_A91A/CssHandler_rendered_2.jpg"><img style="border-width: 0px" src="/image.axd?picture=WindowsLiveWriter/CssHandlerCSSVariablesLove_A91A/CssHandler_rendered_thumb.jpg" border="0" alt="CssHandler_rendered" width="461" height="40" /></a></p>
<p>I hope you find it as useful as I have. Many thanks to Rory Blyth and Gabe Moothart. Hopefully CSS4 will add variables and we&#8217;ll never have to use this again!</p>
<p><a href="http://www.codeplex.com/CssHandler/">Visit the project&#8217;s CodePlex site to download</a>.</p>
<p><strong>Update (Dec. 2, 2007):</strong> Rory has posted and <a href="http://www.neopoleon.com/home/blogs/neo/archive/2007/11/23/28201.aspx">given his blessing</a>, so to speak. Thanks Rory! </p>
<div style="text-align: center;"><a href="http://www.dotnetkicks.com/kick/?url=http://www.squaredroot.com/2007/11/16/csshandler-first-release/" style="border:0; position: relative; top: -2px;"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://www.squaredroot.com/2007/11/16/csshandler-first-release/" style="border:0;" alt="Kick It on DotNetKicks.com" /></a><a href="http://dotnetshoutout.com/Submit?url=http://www.squaredroot.com/2007/11/16/csshandler-first-release/" style="border: 0;"><img src="http://dotnetshoutout.com/image.axd?url=http://www.squaredroot.com/2007/11/16/csshandler-first-release/" style="border:0px" alt="Shout It on DotNetShoutOuts.com" /></a></div>]]></content:encoded>
			<wfw:commentRss>http://www.squaredroot.com/2007/11/16/csshandler-first-release/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>
