<?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>chris moos&#039;s blog &#187; w3</title>
	<atom:link href="http://chrismoos.com/tag/w3/feed/" rel="self" type="application/rss+xml" />
	<link>http://chrismoos.com</link>
	<description>developer by day, developer by night</description>
	<lastBuildDate>Wed, 11 Aug 2010 15:41:00 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Pylons (X)HTML Validator&#160;Middleware</title>
		<link>http://chrismoos.com/2008/01/29/pylons-xhtml-validator-middleware/</link>
		<comments>http://chrismoos.com/2008/01/29/pylons-xhtml-validator-middleware/#comments</comments>
		<pubDate>Tue, 29 Jan 2008 20:29:20 +0000</pubDate>
		<dc:creator>Chris Moos</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[middleware]]></category>
		<category><![CDATA[pylons]]></category>
		<category><![CDATA[validator]]></category>
		<category><![CDATA[w3]]></category>
		<category><![CDATA[xhtml]]></category>

		<guid isPermaLink="false">http://chrismoos.com/2008/01/29/pylons-xhtml-validator-middleware/</guid>
		<description><![CDATA[This middleware will use the W3 Validator Service to check if your page is valid HTML. It will only check each URI once so that it doesn&#8217;t slow down your site by validating every page load. It does this by placing the result of each URI into a memory cache(using Beaker). You can then call [...]]]></description>
			<content:encoded><![CDATA[<p>This middleware will use the W3 Validator Service to check if your page is valid HTML. It will only check each URI once so that it doesn&#8217;t slow down your site by validating every page load. It does this by placing the result of each URI into a memory cache(using Beaker). You can then call <strong>cache_is_valid_xhtml()</strong> in your template to determine if the current page is valid.</p>
<p><em>Note</em>: The first time your page loads it will not display if the page is valid or not(It is validated AFTER the first response).</p>
<p>Download Link: <a href="http://www.tech9computers.com/W3ValidatorMiddleware-0.1-py2.5.egg">http://www.tech9computers.com/W3ValidatorMiddleware-0.1-py2.5.egg</a></p>
<p>Source Download(gzipped): <a href="http://www.tech9computers.com/w3validator.tar.gz">http://www.tech9computers.com/w3validator.tar.gz</a></p>
<p><strong>Install</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>www.tech9computers.com<span style="color: #000000; font-weight: bold;">/</span>W3ValidatorMiddleware-<span style="color: #000000;">0.1</span>-py2.5.egg
<span style="color: #c20cb9; font-weight: bold;">sudo</span> easy_install W3ValidatorMiddleware-<span style="color: #000000;">0.1</span>-py2.5.egg</pre></div></div>

<p><strong>Configuration</strong></p>
<p><em>config/middleware.py</em></p>
<p>At the top of your middleware.py import the following</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> w3validator <span style="color: #ff7700;font-weight:bold;">import</span> ValidatorMiddleware</pre></td></tr></table></div>

<p>Then right below <strong>CUSTOM MIDDLEWARE HERE<br />
</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="python" style="font-family:monospace;">    <span style="color: #808080; font-style: italic;"># CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares)</span>
    app = ValidatorMiddleware<span style="color: black;">&#40;</span>app<span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p><em>lib/helpers.py</em></p>
<p>At the top you need to import cache_is_valid_xhtml()</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> w3validator <span style="color: #ff7700;font-weight:bold;">import</span> cache_is_valid_xhtml</pre></td></tr></table></div>

<p>I then created the following method that I call from my templates to return a string saying if the page is valid or not.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">def</span> xhtml_str<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    valid = cache_is_valid_xhtml<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">if</span> valid == <span style="color: #008000;">True</span>:
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">'&lt;em&gt;Valid&lt;/em&gt; XHTML 1.0'</span>
    <span style="color: #ff7700;font-weight:bold;">elif</span> valid == <span style="color: #008000;">False</span>:
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">'&lt;em&gt;NOT&lt;/em&gt; Valid XHTML 1.0'</span>
    <span style="color: #ff7700;font-weight:bold;">else</span>:
        <span style="color: #808080; font-style: italic;"># hasn't been validated yet</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">'XHTML 1.0'</span></pre></div></div>

<p><strong>Template Configuration</strong></p>
<p>If you have a base template, you might want to the footer of every page to display if it is valid (X)HTML or not.</p>
<p><em>Mako</em></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;html<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;h1<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>My XHTML Site<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/h1<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;footer&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        ${h.xhtml_str()}
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/html<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>That&#8217;s all you need to do to add validation support to your site. You can check the middleware out in action on my site at <a href="http://blackberrytracker.com">http://blackberrytracker.com</a>. Scroll to the bottom of the page to see where I have the validation result.</p>
]]></content:encoded>
			<wfw:commentRss>http://chrismoos.com/2008/01/29/pylons-xhtml-validator-middleware/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
