<?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>One Man's Walk in work &#187; markaby</title>
	<atom:link href="http://onemanswalk.com/work/tag/markaby/feed/" rel="self" type="application/rss+xml" />
	<link>http://onemanswalk.com/work</link>
	<description>jeremy lightsmith on agile, ruby, and consulting</description>
	<lastBuildDate>Wed, 04 May 2011 04:29:54 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Using Markaby w/ Rails 2.0.1</title>
		<link>http://onemanswalk.com/work/2007/12/13/using-markaby-w-rails-2-0-1/</link>
		<comments>http://onemanswalk.com/work/2007/12/13/using-markaby-w-rails-2-0-1/#comments</comments>
		<pubDate>Thu, 13 Dec 2007 19:07:00 +0000</pubDate>
		<dc:creator>jeremy</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[markaby]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[	Rails 2.0.1 is out, in general, it&#8217;s pretty nice.  Markaby doesn&#8217;t play too nice w/ it.  Markaby requires every named route to have a .to_s on the end of it.  Yuck.

	After migrating my 3rd project to rails 2.0.1, I got sick of adding .to_s to each named routes, and did some digging.

	Apparently, [...]]]></description>
			<content:encoded><![CDATA[	<p>Rails 2.0.1 is out, in general, it&#8217;s pretty nice.  Markaby doesn&#8217;t play too nice w/ it.  Markaby requires every named route to have a .to_s on the end of it.  Yuck.</p>

	<p>After migrating my 3rd project to rails 2.0.1, I got sick of adding .to_s to each named routes, and did some digging.</p>

	<p>Apparently, somehow a string coming from a named route is not <em>exactly</em> a string.  Sure</p>

	<p>
<div class="wp_syntax"><div class="code"><pre class="ruby">  apples_path<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9966CC; font-weight:bold;">class</span> == <span style="color:#CC0066; font-weight:bold;">String</span></pre></div></div>
</p>



	<p>but</p>

	<p>
<div class="wp_syntax"><div class="code"><pre class="ruby">  <span style="color:#CC0066; font-weight:bold;">String</span> === apples_path<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>
</p>



	<p>is <span class="caps">NOT</span> true.  I couldn&#8217;t quite track down why this was but it eventually leads to a</p>

<pre>
ActionView::TemplateError (undefined method `string_path' for #) on line #10 of messages/index.mab:

actionpack-2.0.1/lib/action_controller/polymorphic_routes.rb:27:in `send!'
actionpack-2.0.1/lib/action_controller/polymorphic_routes.rb:27:in `polymorphic_url'
actionpack-2.0.1/lib/action_controller/polymorphic_routes.rb:31:in `polymorphic_path'
actionpack-2.0.1/lib/action_view/helpers/url_helper.rb:79:in `url_for'
actionpack-2.0.1/lib/action_view/helpers/url_helper.rb:144:in `link_to'
...
</pre>

	<p>After an hour of trying in vain to find the source of the problem, I found a simple hack that fixes this.  Should have thought of this before, but add this code to your application_helper.rb</p>

	<p>
<div class="wp_syntax"><div class="code"><pre class="ruby">  <span style="color:#9966CC; font-weight:bold;">def</span> string_path<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0066; font-weight:bold;">string</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#CC0066; font-weight:bold;">string</span>
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>
</p>



	<p>If anyone else has a better solution, please pass it over!</p>
 ]]></content:encoded>
			<wfw:commentRss>http://onemanswalk.com/work/2007/12/13/using-markaby-w-rails-2-0-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Customizing Markaby &#8211; Language Level Refactorings</title>
		<link>http://onemanswalk.com/work/2007/09/26/customizing-markaby-language-level-refactorings/</link>
		<comments>http://onemanswalk.com/work/2007/09/26/customizing-markaby-language-level-refactorings/#comments</comments>
		<pubDate>Wed, 26 Sep 2007 23:14:00 +0000</pubDate>
		<dc:creator>jeremy</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[dsls]]></category>
		<category><![CDATA[markaby]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[	It&#8217;s very easy to call out to methods in markaby, but it&#8217;d be nice if you could actually customize the dsl as well.

	For example, on many of our pages we have a bottom row that has buttons that look a certain way.  So on every page, we have :

	
  table&#40;:width =&#62; &#34;100%&#34;&#41; do
 [...]]]></description>
			<content:encoded><![CDATA[	<p>It&#8217;s very easy to call out to methods in markaby, but it&#8217;d be nice if you could actually customize the dsl as well.</p>

	<p>For example, on many of our pages we have a bottom row that has buttons that look a certain way.  So on every page, we have :</p>

	<p>
<div class="wp_syntax"><div class="code"><pre class="ruby">  table<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:width</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;100%&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    tr <span style="color:#9966CC; font-weight:bold;">do</span>
      td.<span style="color:#9900CC;">left</span> <span style="color:#9966CC; font-weight:bold;">do</span>
        previous_button
        first_button
      <span style="color:#9966CC; font-weight:bold;">end</span>
      td.<span style="color:#9900CC;">center</span> <span style="color:#9966CC; font-weight:bold;">do</span>
        <span style="color:#CC0066; font-weight:bold;">print</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
      td.<span style="color:#9900CC;">right</span> <span style="color:#9966CC; font-weight:bold;">do</span>
        next_button
        last_button
      <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>
</p>



	<p>The code for the actual buttons changes, and after a few tries to extract the whole thing into a single method, we gave up.  Our efforts had made it harder to read, not easier.  There was always just a little too much variance, and it didn&#8217;t feel right.</p>

	<p>What we really wanted to write was :</p>

	<p>
<div class="wp_syntax"><div class="code"><pre class="ruby">  last_row <span style="color:#9966CC; font-weight:bold;">do</span>
    column <span style="color:#9966CC; font-weight:bold;">do</span>
      previous_button
      first_button
    <span style="color:#9966CC; font-weight:bold;">end</span>
    column <span style="color:#9966CC; font-weight:bold;">do</span>
      <span style="color:#CC0066; font-weight:bold;">print</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
    column <span style="color:#9966CC; font-weight:bold;">do</span>
      next_button
      last_button
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>
</p>



	<p>This lets the buttons that change all stay in the view, and gets rid of the skeleton and positional stuff that doesn&#8217;t change.  Furthermore, it&#8217;s <span class="caps">DRY</span> and puts all that positional logic in one place instead of scattered across 20 views.</p>

	<p>How to do this?</p>

	<p>I wrote a test (in RSpec) that looks something like :</p>

	<p>
<div class="wp_syntax"><div class="code"><pre class="ruby">describe ApplicationHelper <span style="color:#9966CC; font-weight:bold;">do</span>
  it <span style="color:#996600;">&quot;should generate a table from a buttons method&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    last_row<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:columns</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">2</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
      column <span style="color:#9966CC; font-weight:bold;">do</span>
        <span style="color:#996600;">&quot;foo&quot;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
      column <span style="color:#9966CC; font-weight:bold;">do</span>
        <span style="color:#996600;">&quot;bar&quot;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>.<span style="color:#9900CC;">should</span> == <span style="color:#996600;">'&lt;table width=&quot;100%&quot;&gt;&lt;tr&gt;'</span> <span style="color:#006600; font-weight:bold;">+</span>
                    <span style="color:#996600;">'&lt;td class=&quot;left&quot;&gt;foo&lt;/td&gt;'</span> <span style="color:#006600; font-weight:bold;">+</span> 
                    <span style="color:#996600;">'&lt;td class=&quot;right&quot;&gt;bar&lt;/td&gt;'</span> <span style="color:#006600; font-weight:bold;">+</span>
                  <span style="color:#996600;">'&lt;/tr&gt;&lt;/table&gt;'</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>
</p>



	<p>After a bunch of fiddling and poking around, I finally made the test (and a couple others) pass with this code in my ApplicationHelper :</p>

	<p>
<div class="wp_syntax"><div class="code"><pre class="ruby"><span style="color:#9966CC; font-weight:bold;">def</span> last_row<span style="color:#006600; font-weight:bold;">&#40;</span>options, <span style="color:#006600; font-weight:bold;">&amp;</span>block<span style="color:#006600; font-weight:bold;">&#41;</span>
  markaby <span style="color:#9966CC; font-weight:bold;">do</span>
    table<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:width</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;100%&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
      tr <span style="color:#9966CC; font-weight:bold;">do</span>
        LastRowContext.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">self</span>, options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:columns</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.
                                  <span style="color:#9900CC;">instance_eval</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&amp;</span>block<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> LastRowContext
  <span style="color:#9966CC; font-weight:bold;">def</span> initialize<span style="color:#006600; font-weight:bold;">&#40;</span>markaby, columns<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0066ff; font-weight:bold;">@markaby</span>, <span style="color:#0066ff; font-weight:bold;">@column_count</span>, <span style="color:#0066ff; font-weight:bold;">@column_index</span> = 
                            markaby, columns, <span style="color:#006666;">0</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> column<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&amp;</span>block<span style="color:#006600; font-weight:bold;">&#41;</span>
    alignment = <span style="color:#9966CC; font-weight:bold;">case</span> <span style="color:#0066ff; font-weight:bold;">@column_index</span> <span style="color:#006600; font-weight:bold;">+</span>= <span style="color:#006666;">1</span>
    <span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#006666;">1</span> : <span style="color:#ff3333; font-weight:bold;">:left</span>
    <span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#0066ff; font-weight:bold;">@column_count</span> : <span style="color:#ff3333; font-weight:bold;">:right</span>
    <span style="color:#9966CC; font-weight:bold;">else</span> <span style="color:#ff3333; font-weight:bold;">:center</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    <span style="color:#0066ff; font-weight:bold;">@markaby</span>.<span style="color:#9900CC;">instance_eval</span> <span style="color:#9966CC; font-weight:bold;">do</span>
      td<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:class</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> alignment, <span style="color:#006600; font-weight:bold;">&amp;</span>block<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>
</p>



	<p>I&#8217;m sure this could get cleaned up more; this was the work of less than an hour.  In particular, if you did this often, you could extract a common MarkabyContext superclass that had some convenience methods.  The point is, this is really easy to do, and we shouldn&#8217;t be scared to try &#8220;Language level refactorings&#8221; like this.</p>



 ]]></content:encoded>
			<wfw:commentRss>http://onemanswalk.com/work/2007/09/26/customizing-markaby-language-level-refactorings/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

