<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" version="2.0">

<channel>
	<title>Andrew Peters' Blog</title>
	
	<link>http://andrewpeters.net</link>
	<description>C# &amp; .NET Development, NHaml, PowerShell Gadget, Inflector.NET...</description>
	<pubDate>Tue, 03 Mar 2009 07:12:41 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/andrewpeters/feedburner" type="application/rss+xml" /><item>
		<title>LogicNP are Dodgy</title>
		<link>http://andrewpeters.net/2009/03/03/logicnp-are-dodgy/</link>
		<comments>http://andrewpeters.net/2009/03/03/logicnp-are-dodgy/#comments</comments>
		<pubDate>Tue, 03 Mar 2009 07:12:41 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
		
		<category><![CDATA[Software Ethics]]></category>

		<guid isPermaLink="false">http://andrewpeters.net/?p=196</guid>
		<description><![CDATA[Spread the word: If you buy controls from LogicNP and use them to make cool things then they will rip off your idea.
Case in point. Mindscape created the awesome, free VS File Explorer.
Lo and behold, what appears on the LogicNP site sometime later: The not free, and much less awesome &#8220;VS Explorer&#8220;!
Boycott LogicNP!
As usual, the [...]]]></description>
			<content:encoded><![CDATA[<p>Spread the word: If you buy controls from LogicNP and use them to make cool things then they will rip off your idea.</p>
<p>Case in point. Mindscape created the awesome, free <a href="http://www.mindscape.co.nz/products/vsfileexplorer/">VS File Explorer</a>.</p>
<p>Lo and behold, what appears on the LogicNP site sometime later: The not free, and much less awesome &#8220;<a href="http://www.ssware.com/vsexplorer/vsexplorer.htm">VS Explorer</a>&#8220;!</p>
<p>Boycott LogicNP!</p>
<p>As usual, the opinions expressed are mine and not that of my employer or of Mindscape.</p>
]]></content:encoded>
			<wfw:commentRss>http://andrewpeters.net/2009/03/03/logicnp-are-dodgy/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Getting Started with NHaml</title>
		<link>http://andrewpeters.net/2009/01/16/getting-started-with-nhaml/</link>
		<comments>http://andrewpeters.net/2009/01/16/getting-started-with-nhaml/#comments</comments>
		<pubDate>Fri, 16 Jan 2009 19:56:26 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
		
		<category><![CDATA[NHaml]]></category>

		<guid isPermaLink="false">http://andrewpeters.net/?p=193</guid>
		<description><![CDATA[Brian Hartstock has put up a great tutorial on how to get started with NHaml.
Thanks Brian!
]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.brianhartsock.com">Brian Hartstock</a> has put up a great <a href="http://blog.brianhartsock.com/2009/01/15/using-nhaml-from-source/">tutorial</a> on how to get started with NHaml.</p>
<p>Thanks Brian!</p>
]]></content:encoded>
			<wfw:commentRss>http://andrewpeters.net/2009/01/16/getting-started-with-nhaml/feed/</wfw:commentRss>
		</item>
		<item>
		<title>In-process ASP.NET MVC Web Form View Rendering</title>
		<link>http://andrewpeters.net/2008/11/19/in-process-aspnet-mvc-web-form-view-rendering/</link>
		<comments>http://andrewpeters.net/2008/11/19/in-process-aspnet-mvc-web-form-view-rendering/#comments</comments>
		<pubDate>Thu, 20 Nov 2008 00:18:32 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
		
		<category><![CDATA[ASP.NET MVC]]></category>

		<guid isPermaLink="false">http://andrewpeters.net/?p=183</guid>
		<description><![CDATA[Sometimes it&#8217;s useful to be able to render a view in-process, for example, from within a unit test if you would like to validate the rendered XHTML. View engines like NHaml make this easy because they aren&#8217;t tightly coupled to the System.Web.* ASP.NET runtime. Web Forms, however, is another story. You cannot simply new up [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes it&#8217;s useful to be able to render a view in-process, for example, from within a unit test if you would like to validate the rendered XHTML. View engines like <a href="http://code.google.com/p/nhaml/">NHaml</a> make this easy because they aren&#8217;t tightly coupled to the System.Web.* ASP.NET runtime. Web Forms, however, is another story. You cannot simply new up a WebFormViewEngine, nestle it in some moqs and start rendering away merrily. You will quickly run into various exceptions because the ASP.NET runtime has not been properly initialized.</p>
<p>All is not lost however. Here&#8217;s how you can easily render Web Forms views using the ASP.NET Hosting API:</p>
<p>First, create an Application Host class. Inherit MarshalByRefObject because this will run ASP.NET in a separate App Domain. Add a method, ProcessRequest, that will request a view through the runtime.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp"><span style="color: #000066; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">sealed</span> <span style="color: #000066; font-weight: bold;">class</span> TestApplicationHost : MarshalByRefObject
<span style="color: #000000;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> ProcessRequest<span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">string</span> page, <span style="color: #000066; font-weight: bold;">string</span> query, TextWriter output<span style="color: #000000;">&#41;</span>
  <span style="color: #000000;">&#123;</span>
    var simpleWorkerRequest 
      = <span style="color: #000066; font-weight: bold;">new</span> SimpleWorkerRequest<span style="color: #000000;">&#40;</span>page, query, output<span style="color: #000000;">&#41;</span>;
&nbsp;
    HttpRuntime.<span style="color: #800080;">ProcessRequest</span><span style="color: #000000;">&#40;</span>simpleWorkerRequest<span style="color: #000000;">&#41;</span>;
  <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Second, create your host which points to an ASP.NET app and render a view.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp"><span style="color: #000066; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">sealed</span> <span style="color: #000066; font-weight: bold;">class</span> Program
<span style="color: #000000;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> Main<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
  <span style="color: #000000;">&#123;</span>
    var applicationHost = <span style="color: #000000;">&#40;</span>TestApplicationHost<span style="color: #000000;">&#41;</span>
      ApplicationHost.<span style="color: #800080;">CreateApplicationHost</span><span style="color: #000000;">&#40;</span>
        <span style="color: #000066; font-weight: bold;">typeof</span><span style="color: #000000;">&#40;</span>TestApplicationHost<span style="color: #000000;">&#41;</span>,
        <span style="color: #A31515;">&quot;/&quot;</span>, 
        <span style="color: #A31515;">@"C:\Dev\MyMvcApplication&quot;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
    <span style="color: #000066; font-weight: bold;">using</span> <span style="color: #000000;">&#40;</span>var output = <span style="color: #000066; font-weight: bold;">new</span> StringWriter<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
      applicationHost.<span style="color: #800080;">ProcessRequest</span><span style="color: #000000;">&#40;</span><span style="color: #A31515;">&quot;Account/Login&quot;</span>, <span style="color: #000066; font-weight: bold;">null</span>, output<span style="color: #000000;">&#41;</span>;
&nbsp;
      Console.<span style="color: #800080;">WriteLine</span><span style="color: #000000;">&#40;</span>output<span style="color: #000000;">&#41;</span>;
    <span style="color: #000000;">&#125;</span>
&nbsp;
    Console.<span style="color: #800080;">ReadKey</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
  <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Surprisingly easy actually.</p>
<p><a href="http://www.dotnetkicks.com/kick/?url=http://andrewpeters.net/2008/11/19/in-process-aspnet-mvc-web-form-view-rendering/"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://andrewpeters.net/2008/11/19/in-process-aspnet-mvc-web-form-view-rendering/&amp;bgcolor=993300&amp;cbgcolor=CCCCCC" border="0" alt="kick it on DotNetKicks.com" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://andrewpeters.net/2008/11/19/in-process-aspnet-mvc-web-form-view-rendering/feed/</wfw:commentRss>
		</item>
		<item>
		<title>By Popular Demand</title>
		<link>http://andrewpeters.net/2008/11/17/by-popular-demand/</link>
		<comments>http://andrewpeters.net/2008/11/17/by-popular-demand/#comments</comments>
		<pubDate>Tue, 18 Nov 2008 01:06:28 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
		
		<category><![CDATA[NHaml]]></category>

		<guid isPermaLink="false">http://andrewpeters.net/?p=180</guid>
		<description><![CDATA[The trunk  version of NHaml now lets you use tabs or a variable indent size for indentation.
Now, no more arguing! You may go about your business.
P.S. 2 spaces is the best
]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://code.google.com/p/nhaml/source/checkout">trunk </a> version of NHaml now lets you use tabs or a variable indent size for indentation.</p>
<p>Now, no more arguing! You may go about your business.</p>
<p>P.S. 2 spaces is the best</p>
]]></content:encoded>
			<wfw:commentRss>http://andrewpeters.net/2008/11/17/by-popular-demand/feed/</wfw:commentRss>
		</item>
		<item>
		<title>NHaml 2.0 Beta</title>
		<link>http://andrewpeters.net/2008/11/17/nhaml-20-beta/</link>
		<comments>http://andrewpeters.net/2008/11/17/nhaml-20-beta/#comments</comments>
		<pubDate>Mon, 17 Nov 2008 06:39:39 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
		
		<category><![CDATA[NHaml]]></category>

		<guid isPermaLink="false">http://andrewpeters.net/?p=173</guid>
		<description><![CDATA[Simone rightly pointed out that requiring NHaml users to pull the source from SVN was just downright lazy. So I finally got around to putting together an actual release: 2.0 Beta. 
With 2.0 we&#8217;ve made some substantial changes and improvements and also greatly simplified the API. Here&#8217;s a sneak peak of what&#8217;s coming:

The biggest change [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://codeclimber.net.nz/">Simone</a> rightly pointed out that requiring NHaml users to pull the source from SVN was just downright lazy. So I finally got around to putting together an actual release: <a href="http://nhaml.googlecode.com/files/nhaml-2.0-beta.zip">2.0 Beta</a>. </p>
<p>With 2.0 we&#8217;ve made some substantial changes and improvements and also greatly simplified the API. Here&#8217;s a sneak peak of what&#8217;s coming:</p>
<ul>
<li>The biggest change by far has been the introduction of pluggable back-end compilers. NHaml templates can now be authored in one of four languages: C# 2, C# 3, Boo and IronRuby.</li>
<li>We have greatly simplified our ASP.NET MVC View Engine which now inherits from the framework provided VirtualPathProviderViewEngine.</li>
<li>NHaml 2.0 implements the <a href="http://haml.hamptoncatlin.com/docs/rdoc/classes/Haml.html">Haml rules</a> for convenient handling of HTML encoding.</li>
<li>We made some major API usability improvements for stand-alone template rendering.</li>
</ul>
<p>We still have a bunch of stuff on our backlog, some of which we&#8217;ll try and squeeze into 2.0 RTM - Hopefully sometime within the next month.</p>
<p>Enjoy and death to angle brackets!</p>
]]></content:encoded>
			<wfw:commentRss>http://andrewpeters.net/2008/11/17/nhaml-20-beta/feed/</wfw:commentRss>
		</item>
		<item>
		<title>NHaml Discussion Group</title>
		<link>http://andrewpeters.net/2008/09/18/nhaml-discussion-group/</link>
		<comments>http://andrewpeters.net/2008/09/18/nhaml-discussion-group/#comments</comments>
		<pubDate>Fri, 19 Sep 2008 01:58:27 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
		
		<category><![CDATA[NHaml]]></category>

		<guid isPermaLink="false">http://andrewpeters.net/?p=169</guid>
		<description><![CDATA[Using NHaml? Then head on over to nhaml-users.
Thanks to James Avery for setting it up.
]]></description>
			<content:encoded><![CDATA[<p>Using NHaml? Then head on over to <a href="http://groups.google.com/group/nhaml-users">nhaml-users</a>.</p>
<p>Thanks to <a href="http://infozerk.com/averyBlog/">James Avery</a> for setting it up.</p>
]]></content:encoded>
			<wfw:commentRss>http://andrewpeters.net/2008/09/18/nhaml-discussion-group/feed/</wfw:commentRss>
		</item>
		<item>
		<title>NHaml 1.3 Released</title>
		<link>http://andrewpeters.net/2008/09/05/nhaml-13-released/</link>
		<comments>http://andrewpeters.net/2008/09/05/nhaml-13-released/#comments</comments>
		<pubDate>Fri, 05 Sep 2008 07:42:49 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
		
		<category><![CDATA[NHaml]]></category>

		<guid isPermaLink="false">http://andrewpeters.net/?p=166</guid>
		<description><![CDATA[Updated to support ASP.NET MVC Preview 5.
As always, get it here.
]]></description>
			<content:encoded><![CDATA[<p>Updated to support ASP.NET MVC Preview 5.</p>
<p>As always, get it <a href="http://code.google.com/p/nhaml/source/checkout">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://andrewpeters.net/2008/09/05/nhaml-13-released/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Joining Microsoft</title>
		<link>http://andrewpeters.net/2008/09/02/joining-microsoft/</link>
		<comments>http://andrewpeters.net/2008/09/02/joining-microsoft/#comments</comments>
		<pubDate>Tue, 02 Sep 2008 11:57:32 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
		
		<category><![CDATA[Microsoft]]></category>

		<guid isPermaLink="false">http://andrewpeters.net/?p=158</guid>
		<description><![CDATA[I&#8217;m very excited to announce that, starting November, I&#8217;ll be working as a dev within the SQL Server DP group - specifically on the Entity Framework. 
The position is based in Redmond but I missed the H1B this year and so we&#8217;re heading up to the new development center in Vancouver. By all accounts, Vancouver [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m very excited to announce that, starting November, I&#8217;ll be working as a dev within the SQL Server DP group - specifically on the <a href="http://en.wikipedia.org/wiki/ADO.NET_Entity_Framework">Entity Framework</a>. </p>
<p>The position is based in Redmond but I missed the H1B this year and so we&#8217;re heading up to the <a href="http://blogs.msdn.com/jobsblog/archive/2007/11/29/roadtrip-microsoft-canada-development-center.aspx">new development center in Vancouver</a>. By all accounts, Vancouver is a great place to live and my wife and I are looking forward to the change of scene - We both ski too and are stoked about having one of the <a href="http://www.whistlerblackcomb.com/">world&#8217;s premier ski areas</a> right on our doorstep :-)</p>
<p>The decision to leave <a href="http://mindscape.co.nz">Mindscape</a>, the company I co-founded was, of course, not taken lightly. I&#8217;m highly proud of what I helped create there - especially LightSpeed (my baby originally). I will particularly miss the variety of discussion that occurs in a small, developer-led shop like Mindscape. In my opinion, starting a company is a truly worthwhile experience because it forces you to consider all those things other than the code - You quickly learn that it&#8217;s those things that matter more.</p>
<p>That said, working for a company like Microsoft gives you the opportunity to touch many, many people&#8217;s lives&#8230;and, hopefully, make them just a little bit better.</p>
]]></content:encoded>
			<wfw:commentRss>http://andrewpeters.net/2008/09/02/joining-microsoft/feed/</wfw:commentRss>
		</item>
		<item>
		<title>NHaml: Block Methods and RESTful Helpers</title>
		<link>http://andrewpeters.net/2008/08/21/nhaml-block-methods-and-restful-helpers/</link>
		<comments>http://andrewpeters.net/2008/08/21/nhaml-block-methods-and-restful-helpers/#comments</comments>
		<pubDate>Thu, 21 Aug 2008 12:14:35 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
		
		<category><![CDATA[NHaml]]></category>

		<guid isPermaLink="false">http://andrewpeters.net/?p=127</guid>
		<description><![CDATA[New in the trunk are a couple of cool features worth mentioning:
Block Methods
Block Methods are helper methods that accept a block of NHaml markup as a final argument.
An example (albeit contrived) to demonstrate:

- Html.Tag&#40;&#34;div&#34;&#41; &#40;&#41; =&#62;
  Some regular NHaml markup here...

which results in:

&#60;div&#62;
  Some regular NHaml markup here...
&#60;/div&#62;

And the Tag method looks like [...]]]></description>
			<content:encoded><![CDATA[<p>New in the <a href="http://code.google.com/p/nhaml/source/checkout">trunk</a> are a couple of cool features worth mentioning:</p>
<h4>Block Methods</h4>
<p>Block Methods are helper methods that accept a block of NHaml markup as a final argument.</p>
<p>An example (albeit contrived) to demonstrate:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp">- Html.<span style="color: #800080;">Tag</span><span style="color: #000000;">&#40;</span><span style="color: #A31515;">&quot;div&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> =&gt;
  Some regular NHaml markup here...</pre></div></div>

<p>which results in:</p>

<div class="wp_syntax"><div class="code"><pre class="xml"><span style="color: #000000;"><span style="color: #A31515;">&lt;div<span style="color: #A31515;">&gt;</span></span></span>
  Some regular NHaml markup here...
<span style="color: #000000;"><span style="color: #A31515;">&lt;/div<span style="color: #A31515;">&gt;</span></span></span></pre></div></div>

<p>And the <em>Tag</em> method looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp"><span style="color: #000066; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> Tag<span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">string</span> name, Action yield<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
  _output.<span style="color: #800080;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #A31515;">&quot;&lt;&quot;</span> + name + <span style="color: #A31515;">&quot;&gt;&quot;</span><span style="color: #000000;">&#41;</span>;
  yield<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
  _output.<span style="color: #800080;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #A31515;">&quot;&lt;/&quot;</span> + name + <span style="color: #A31515;">&quot;&gt;&quot;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>As we can see, NHaml wraps up the nested block markup into a lambda (or anonymous method if targeting C# 2.0) and passes a delegate to the block as the last argument of the helper method. Invoking the delegate causes the markup within the block to be rendered. Notice too, we can write directly to the output stream: <em>_output</em> is an instance of NHaml&#8217;s <em>IOutputWriter</em> which is passed to our helper class when it&#8217;s instantiated. It has the following methods:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp"><span style="color: #000066; font-weight: bold;">void</span> WriteLine<span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">string</span> value<span style="color: #000000;">&#41;</span>;
<span style="color: #000066; font-weight: bold;">void</span> Write<span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">string</span> value<span style="color: #000000;">&#41;</span>;
<span style="color: #000066; font-weight: bold;">void</span> Indent<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #000066; font-weight: bold;">void</span> Outdent<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;</pre></div></div>

<p>Output written using these methods will be correctly indented and we can also further control the indent level if we need to write nested output.</p>
<p>Worth mentioning is that we can also pass arguments to a block:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp">- Html.<span style="color: #800080;">Tag</span><span style="color: #000000;">&#40;</span><span style="color: #A31515;">&quot;div&quot;</span>, <span style="color: #FF0000;">21</span>, <span style="color: #FF0000;">21</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#40;</span>i, j<span style="color: #000000;">&#41;</span> =&gt;
  = <span style="color: #A31515;">&quot;N was: &quot;</span> + <span style="color: #000000;">&#40;</span>i + j<span style="color: #000000;">&#41;</span></pre></div></div>

<p>which yields:</p>

<div class="wp_syntax"><div class="code"><pre class="xml"><span style="color: #000000;"><span style="color: #A31515;">&lt;div<span style="color: #A31515;">&gt;</span></span></span>
  N was: 42
<span style="color: #000000;"><span style="color: #A31515;">&lt;/div<span style="color: #A31515;">&gt;</span></span></span></pre></div></div>

<p>And our helper method:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp"><span style="color: #000066; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> Tag&lt;T1, T2&gt;<span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">string</span> name, T1 t1, T2 t2, Action&lt;T1, T2&gt; yield<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
  _output.<span style="color: #800080;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #A31515;">&quot;&lt;&quot;</span> + name + <span style="color: #A31515;">&quot;&gt;&quot;</span><span style="color: #000000;">&#41;</span>;
  yield<span style="color: #000000;">&#40;</span>t1, t2<span style="color: #000000;">&#41;</span>;
  _output.<span style="color: #800080;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #A31515;">&quot;&lt;/&quot;</span> + name + <span style="color: #A31515;">&quot;&gt;&quot;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span></pre></div></div>

<h4>RESTful Helpers</h4>
<p>Using a Block Method we can create a nice Rails-style helper that encapsulates building a form for a single model:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp">- var product = <span style="color: #000066; font-weight: bold;">new</span> Product <span style="color: #000000;">&#123;</span> ProductName=<span style="color: #A31515;">&quot;Soap on a Rope&quot;</span> <span style="color: #000000;">&#125;</span>
- Html.<span style="color: #800080;">Form</span><span style="color: #000000;">&#40;</span>product<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#40;</span>f<span style="color: #000000;">&#41;</span> =&gt;
  = f.<span style="color: #800080;">Label</span><span style="color: #000000;">&#40;</span>p =&gt; p.<span style="color: #800080;">ProductName</span><span style="color: #000000;">&#41;</span>
  = f.<span style="color: #800080;">TextField</span><span style="color: #000000;">&#40;</span>p =&gt; p.<span style="color: #800080;">ProductName</span><span style="color: #000000;">&#41;</span>
  %br
  = f.<span style="color: #800080;">Label</span><span style="color: #000000;">&#40;</span>p =&gt; p.<span style="color: #800080;">UnitPrice</span><span style="color: #000000;">&#41;</span>
  = f.<span style="color: #800080;">TextField</span><span style="color: #000000;">&#40;</span>p =&gt; p.<span style="color: #800080;">UnitPrice</span><span style="color: #000000;">&#41;</span>
  %p
    = Html.<span style="color: #800080;">SubmitButton</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></pre></div></div>

<p>Results in:</p>

<div class="wp_syntax"><div class="code"><pre class="xml"><span style="color: #000000;"><span style="color: #A31515;">&lt;form</span> <span style="color: #FF0000;">action</span>=<span style="color: #0000FF;">&quot;/products.mvc/create&quot;</span> <span style="color: #FF0000;">method</span>=<span style="color: #0000FF;">&quot;post&quot;</span><span style="color: #A31515;">&gt;</span></span>
  <span style="color: #000000;"><span style="color: #A31515;">&lt;label</span> <span style="color: #FF0000;">for</span>=<span style="color: #0000FF;">&quot;Product.ProductName&quot;</span><span style="color: #A31515;">&gt;</span></span>Product Name<span style="color: #000000;"><span style="color: #A31515;">&lt;/label<span style="color: #A31515;">&gt;</span></span></span>
  <span style="color: #000000;"><span style="color: #A31515;">&lt;input</span> <span style="color: #FF0000;">type</span>=<span style="color: #0000FF;">&quot;text&quot;</span> <span style="color: #FF0000;">name</span>=<span style="color: #0000FF;">&quot;Product.ProductName&quot;</span> <span style="color: #FF0000;">id</span>=<span style="color: #0000FF;">&quot;Product.ProductName&quot;</span> <span style="color: #FF0000;">value</span>=<span style="color: #0000FF;">&quot;&quot;</span> <span style="color: #A31515;">/&gt;</span></span>
  <span style="color: #000000;"><span style="color: #A31515;">&lt;br</span> <span style="color: #A31515;">/&gt;</span></span>
  <span style="color: #000000;"><span style="color: #A31515;">&lt;label</span> <span style="color: #FF0000;">for</span>=<span style="color: #0000FF;">&quot;Product.UnitPrice&quot;</span><span style="color: #A31515;">&gt;</span></span>Unit Price<span style="color: #000000;"><span style="color: #A31515;">&lt;/label<span style="color: #A31515;">&gt;</span></span></span>
  <span style="color: #000000;"><span style="color: #A31515;">&lt;input</span> <span style="color: #FF0000;">type</span>=<span style="color: #0000FF;">&quot;text&quot;</span> <span style="color: #FF0000;">name</span>=<span style="color: #0000FF;">&quot;Product.UnitPrice&quot;</span> <span style="color: #FF0000;">id</span>=<span style="color: #0000FF;">&quot;Product.UnitPrice&quot;</span> <span style="color: #FF0000;">value</span>=<span style="color: #0000FF;">&quot;&quot;</span> <span style="color: #A31515;">/&gt;</span></span>
  <span style="color: #000000;"><span style="color: #A31515;">&lt;p<span style="color: #A31515;">&gt;</span></span></span>
    <span style="color: #000000;"><span style="color: #A31515;">&lt;input</span> <span style="color: #FF0000;">type</span>=<span style="color: #0000FF;">&quot;submit&quot;</span> <span style="color: #A31515;">/&gt;</span></span>
  <span style="color: #000000;"><span style="color: #A31515;">&lt;/p<span style="color: #A31515;">&gt;</span></span></span>
<span style="color: #000000;"><span style="color: #A31515;">&lt;/form<span style="color: #A31515;">&gt;</span></span></span></pre></div></div>

<p>A couple of things to note here:</p>
<ol>
<li>Our <em>Form</em> method takes a model object and uses the conventions of REST to generate the target action. To make this work our model needs to implement a small interface: <em>IModel</em>:

<div class="wp_syntax"><div class="code"><pre class="csharp"><span style="color: #000066; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">interface</span> IModel
<span style="color: #000000;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">int</span> Id <span style="color: #000000;">&#123;</span> get; <span style="color: #000000;">&#125;</span>
  <span style="color: #000066; font-weight: bold;">bool</span> IsNew <span style="color: #000000;">&#123;</span> get; <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

</li>
<li>Happily, we can bind our model attributes in a strongly typed fashion using Expressions.</li>
</ol>
<p>Here&#8217;s what our <em>Form</em> method looks like:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp"><span style="color: #000066; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">virtual</span> <span style="color: #000066; font-weight: bold;">void</span> Form&lt;TModel&gt;<span style="color: #000000;">&#40;</span>TModel model, Action&lt;FormBuilder&lt;TModel&gt;&gt; yield<span style="color: #000000;">&#41;</span>
  where TModel : IModel
<span style="color: #000000;">&#123;</span>
  <span style="color: #008000;">// this should be pluggable</span>
  var formBuilder = <span style="color: #000066; font-weight: bold;">new</span> FormBuilder&lt;TModel&gt;<span style="color: #000000;">&#40;</span>model, <span style="color: #000066; font-weight: bold;">this</span>, _outputWriter<span style="color: #000000;">&#41;</span>;
&nbsp;
  formBuilder.<span style="color: #800080;">OpenTag</span><span style="color: #000000;">&#40;</span>FormMethod.<span style="color: #800080;">Post</span>, <span style="color: #000066; font-weight: bold;">new</span> RouteValueDictionary<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
  yield<span style="color: #000000;">&#40;</span>formBuilder<span style="color: #000000;">&#41;</span>;
  formBuilder.<span style="color: #800080;">CloseTag</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span></pre></div></div>

<h4>RESTful Link Helpers</h4>
<p>Finally, we can apply RESTful conventions to link helpers too. Here are a few examples of some NHaml ActionLink helpers that work using REST conventions.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp">= Html.<span style="color: #800080;">ActionLink</span>&lt;CategoriesController&gt;<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">// /categories</span>
= Html.<span style="color: #800080;">ActionLink</span>&lt;CategoriesController&gt;<span style="color: #000000;">&#40;</span>RestfulAction.<span style="color: #000066; font-weight: bold;">New</span>, <span style="color: #A31515;">&quot;Add Category&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">// /categories/new</span>
= Html.<span style="color: #800080;">ActionLink</span><span style="color: #000000;">&#40;</span>category<span style="color: #000000;">&#41;</span>  <span style="color: #008000;">// /categories/show/42</span>
= Html.<span style="color: #800080;">ActionLink</span><span style="color: #000000;">&#40;</span>category, RestfulAction.<span style="color: #800080;">Edit</span>, <span style="color: #A31515;">&quot;Edit Category&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">// /categories/edit/42</span>
= Html.<span style="color: #800080;">ActionLink</span><span style="color: #000000;">&#40;</span>category, RestfulAction.<span style="color: #800080;">Destroy</span>, <span style="color: #A31515;">&quot;Delete Category&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">// /categories/destroy/42</span></pre></div></div>

<p>Thoughts/comments appreciated.</p>
<p><a href="http://www.dotnetkicks.com/kick/?url=http://andrewpeters.net/2008/08/21/nhaml-block-methods-and-restful-helpers/"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://andrewpeters.net/2008/08/21/nhaml-block-methods-and-restful-helpers/&amp;bgcolor=993300&amp;cbgcolor=CCCCCC" border="0" alt="kick it on DotNetKicks.com" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://andrewpeters.net/2008/08/21/nhaml-block-methods-and-restful-helpers/feed/</wfw:commentRss>
		</item>
		<item>
		<title>VS File Explorer</title>
		<link>http://andrewpeters.net/2008/08/13/vs-file-explorer/</link>
		<comments>http://andrewpeters.net/2008/08/13/vs-file-explorer/#comments</comments>
		<pubDate>Thu, 14 Aug 2008 01:25:40 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
		
		<category><![CDATA[VS File Explorer]]></category>

		<guid isPermaLink="false">http://andrewpeters.net/?p=121</guid>
		<description><![CDATA[
We at Mindscape just released a cool, free VS add-in: the Visual Studio File Explorer. It&#8217;s basically Windows Explorer inside Visual Studio 2008 so you can perform file system tasks without needing to context switch. It&#8217;s also shell enabled so extensions like TortoiseSVN work too.
Download it here
]]></description>
			<content:encoded><![CDATA[<p><a href="http://andrewpeters.net/wp-content/uploads/2008/08/dump21.png"><img src="http://andrewpeters.net/wp-content/uploads/2008/08/dump21-300x214.png" alt="" title="VS File Explorer" width="300" height="214" class="alignnone size-medium wp-image-122" /></a></p>
<p>We at <a href="http://www.mindscape.co.nz">Mindscape</a> just released a cool, free VS add-in: the Visual Studio File Explorer. It&#8217;s basically Windows Explorer inside Visual Studio 2008 so you can perform file system tasks without needing to context switch. It&#8217;s also shell enabled so extensions like TortoiseSVN work too.</p>
<p><a href="http://www.mindscape.co.nz/products/VSFileExplorer/download.aspx">Download it here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://andrewpeters.net/2008/08/13/vs-file-explorer/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
