<?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>GravityBlast &#187; Development</title>
	<atom:link href="http://gravityblast.com/category/development/feed/" rel="self" type="application/rss+xml" />
	<link>http://gravityblast.com</link>
	<description>...coding blast beat!</description>
	<lastBuildDate>Thu, 08 Apr 2010 08:12:49 +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>Don&#8217;t abuse NSLog in your iPhone game</title>
		<link>http://gravityblast.com/2010/04/08/dont-abuse-nslog-in-your-iphone-game/</link>
		<comments>http://gravityblast.com/2010/04/08/dont-abuse-nslog-in-your-iphone-game/#comments</comments>
		<pubDate>Thu, 08 Apr 2010 08:12:49 +0000</pubDate>
		<dc:creator>Andrea Franz</dc:creator>
				<category><![CDATA[Cocos2d]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://gravityblast.com/?p=403</guid>
		<description><![CDATA[I&#8217;m working on a simple game for iPhone based on cocos2d. Yesterday I installed it on my old iPhone3G and it was veeeeeeeery slow. After a lot of refactoring I found a NSLog call inside my game loop. It basically logged all the collision detection of the player with all the tiles in the map. [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m working on a simple game for iPhone based on <a href="http://www.cocos2d-iphone.org/" title="Cocos2d">cocos2d</a>. Yesterday I installed it on my old iPhone3G and it was veeeeeeeery slow. After a lot of refactoring I found a NSLog call inside my game loop. It basically logged all the collision detection of the player with all the tiles in the map. After removing that it&#8217;s even faster then before. So, if you want to log something, do it, but remember to remove all these logging calls later.</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>share</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://buzz.yahoo.com/submit?submitUrl=http://gravityblast.com/2010/04/08/dont-abuse-nslog-in-your-iphone-game/&amp;submitHeadline=Don%26%238217%3Bt+abuse+NSLog+in+your+iPhone+game&amp;submitSummary=" rel="nofollow" title="Add to&nbsp;Buzz"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/buzz.png" title="Add to&nbsp;Buzz" alt="Add to&nbsp;Buzz" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://gravityblast.com/2010/04/08/dont-abuse-nslog-in-your-iphone-game/&amp;title=Don%26%238217%3Bt+abuse+NSLog+in+your+iPhone+game" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://gravityblast.com/2010/04/08/dont-abuse-nslog-in-your-iphone-game/&amp;title=Don%26%238217%3Bt+abuse+NSLog+in+your+iPhone+game" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.dzone.com/links/add.html?description=Don%26%238217%3Bt+abuse+NSLog+in+your+iPhone+game&amp;url=http://gravityblast.com/2010/04/08/dont-abuse-nslog-in-your-iphone-game/&amp;title=Don%26%238217%3Bt+abuse+NSLog+in+your+iPhone+game" rel="nofollow" title="Add to&nbsp;DZone"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/dzone.png" title="Add to&nbsp;DZone" alt="Add to&nbsp;DZone" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://gravityblast.com/2010/04/08/dont-abuse-nslog-in-your-iphone-game/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://gravityblast.com/2010/04/08/dont-abuse-nslog-in-your-iphone-game/&amp;title=Don%26%238217%3Bt+abuse+NSLog+in+your+iPhone+game" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http://gravityblast.com/2010/04/08/dont-abuse-nslog-in-your-iphone-game/&amp;T=Don%26%238217%3Bt+abuse+NSLog+in+your+iPhone+game" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://gravityblast.com/2010/04/08/dont-abuse-nslog-in-your-iphone-game/&amp;title=Don%26%238217%3Bt+abuse+NSLog+in+your+iPhone+game" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://slashdot.org/bookmark.pl?url=http://gravityblast.com/2010/04/08/dont-abuse-nslog-in-your-iphone-game/&amp;title=Don%26%238217%3Bt+abuse+NSLog+in+your+iPhone+game" rel="nofollow" title="Add to&nbsp;Slashdot"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/slashdot.png" title="Add to&nbsp;Slashdot" alt="Add to&nbsp;Slashdot" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://gravityblast.com/2010/04/08/dont-abuse-nslog-in-your-iphone-game/&amp;title=Don%26%238217%3Bt+abuse+NSLog+in+your+iPhone+game" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://gravityblast.com/2010/04/08/dont-abuse-nslog-in-your-iphone-game/" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://tipd.com/submit.php?url=http://gravityblast.com/2010/04/08/dont-abuse-nslog-in-your-iphone-game/" rel="nofollow" title="Add to&nbsp;Tip'd"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/tipd.png" title="Add to&nbsp;Tip'd" alt="Add to&nbsp;Tip'd" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Don%26%238217%3Bt+abuse+NSLog+in+your+iPhone+game+@+http://gravityblast.com/2010/04/08/dont-abuse-nslog-in-your-iphone-game/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://gravityblast.com/2010/04/08/dont-abuse-nslog-in-your-iphone-game/&amp;t=Don%26%238217%3Bt+abuse+NSLog+in+your+iPhone+game" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://gravityblast.com/2010/04/08/dont-abuse-nslog-in-your-iphone-game/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Using CouchDB from Air applications with CouchDB Flex</title>
		<link>http://gravityblast.com/2009/11/03/using-couchdb-from-air-applications-with-couchdb-flex/</link>
		<comments>http://gravityblast.com/2009/11/03/using-couchdb-from-air-applications-with-couchdb-flex/#comments</comments>
		<pubDate>Tue, 03 Nov 2009 14:31:37 +0000</pubDate>
		<dc:creator>Andrea Franz</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[Couchdb]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://gravityblast.com/?p=379</guid>
		<description><![CDATA[In the last weeks I played a lot with CouchDB and I love it. I always used it from ruby but yesterday I tried to use it with flex. I started a new Actionscript project called CouchDB Flex, you can browse the source from github. The implementation is inspired by couchrest, but it&#8217;s asynchronous because [...]]]></description>
			<content:encoded><![CDATA[<p>In the last weeks I played a lot with <a href="http://couchdb.apache.org/" title="CouchDB">CouchDB</a> and I love it. I always used it from ruby but yesterday I tried to use it with flex. I started a new Actionscript project called <a href="http://github.com/pilu/couchdb-flex" title="CouchDB Flex">CouchDB Flex</a>, you can browse the source from <a href="http://github.com/pilu/couchdb-flex" title="CouchDB Flex on Github">github</a>. The implementation is inspired by <a href="http://github.com/jchris/couchrest">couchrest</a>, but it&#8217;s asynchronous because I use <a href="http://livedocs.adobe.com/flex/3/langref/flash/net/URLLoader.html" title="URLLoaer">URLLoader</a> internally. Since the flash player  doesn&#8217;t support the PUT and DELETE HTTP methods, you must create an AIR project if you want to try the library.  You can find a compiled swc <a href="http://github.com/pilu/couchdb-flex/downloads">here</a>, put it in your libs folder and you are ready to go. Here a small example, but it&#8217;s still in development, and a lot of functionality are not implemented yet.</p>
<p><strong>CouchdbFlexExample.mxml:</strong> the main mxml file, it&#8217;s just a window with a textarea that will display the data loaded from CouchDB.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span>xml <span style="color: #004993;">version</span>=<span style="color: #990000;">&quot;1.0&quot;</span> encoding=<span style="color: #990000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;</span>c<span style="color: #000000; font-weight: bold;">:</span>App xmlns<span style="color: #000000; font-weight: bold;">:</span>fx=<span style="color: #990000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span> xmlns<span style="color: #000000; font-weight: bold;">:</span>s=<span style="color: #990000;">&quot;library://ns.adobe.com/flex/spark&quot;</span> xmlns<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">c</span>=<span style="color: #990000;">&quot;com.gravityblast.couchdbflexexample.*&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
  <span style="color: #000000; font-weight: bold;">&lt;</span>s<span style="color: #000000; font-weight: bold;">:</span>TextArea id=<span style="color: #990000;">&quot;textarea&quot;</span> <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;100%&quot;</span> <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;100%&quot;</span> <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;{log}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span>			
<span style="color: #000000; font-weight: bold;">&lt;/</span><span style="color: #004993;">c</span><span style="color: #000000; font-weight: bold;">:</span>App<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p><strong>com/gravityblast/couchdbflexexample/Contact.as:</strong> the model I&#8217;ll save on CouchDB. By default the model has a name and an email, but I can add more properties since it&#8217;s a dynamic class.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> com.gravityblast.couchdbflexexample
<span style="color: #000000;">&#123;</span>
  <span style="color: #0033ff; font-weight: bold;">import</span> com.gravityblast.couchdb.Document;
&nbsp;
  <span style="color: #0033ff; font-weight: bold;">public</span> dynamic <span style="color: #9900cc; font-weight: bold;">class</span> Contact extends Document
  <span style="color: #000000;">&#123;</span>		
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">name</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span>;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> email<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span>;
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Contact<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
      <span style="color: #0033ff; font-weight: bold;">super</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>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p><strong>com/gravityblast/couchdbflexexample/App.as:</strong> the main application, where I create a new Contact Document, and I load all the contacts using a view created with the Design and View classes.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> com.gravityblast.couchdbflexexample
<span style="color: #000000;">&#123;</span>
  <span style="color: #0033ff; font-weight: bold;">import</span> com.gravityblast.couchdb.CouchDb;
  <span style="color: #0033ff; font-weight: bold;">import</span> com.gravityblast.couchdb.Database;
  <span style="color: #0033ff; font-weight: bold;">import</span> com.gravityblast.couchdb.Design;
  <span style="color: #0033ff; font-weight: bold;">import</span> com.gravityblast.couchdb.View;
  <span style="color: #0033ff; font-weight: bold;">import</span> com.gravityblast.couchdb.events.CouchRestEvent;
  <span style="color: #0033ff; font-weight: bold;">import</span> com.gravityblast.couchdb.events.DocumentEvent;
  <span style="color: #0033ff; font-weight: bold;">import</span> com.gravityblast.couchdb.events.ViewEvent;
&nbsp;
  <span style="color: #0033ff; font-weight: bold;">import</span> mx.events.FlexEvent;
&nbsp;
  <span style="color: #0033ff; font-weight: bold;">import</span> spark.components.TextArea;
  <span style="color: #0033ff; font-weight: bold;">import</span> spark.components.WindowedApplication;
&nbsp;
  <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> App extends WindowedApplication
  <span style="color: #000000;">&#123;</span>		
    <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> couchdb<span style="color: #000000; font-weight: bold;">:</span>CouchDb;
    <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> database<span style="color: #000000; font-weight: bold;">:</span>Database;
&nbsp;
    <span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span>
    <span style="color: #0033ff; font-weight: bold;">public</span> 	<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">log</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span>;
    <span style="color: #0033ff; font-weight: bold;">public</span> 	<span style="color: #6699cc; font-weight: bold;">var</span> textarea<span style="color: #000000; font-weight: bold;">:</span>TextArea;
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> App<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>			
      <span style="color: #0033ff; font-weight: bold;">this</span>.couchdb = <span style="color: #0033ff; font-weight: bold;">new</span> CouchDb<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
      <span style="color: #0033ff; font-weight: bold;">this</span>.database = <span style="color: #0033ff; font-weight: bold;">this</span>.couchdb.database<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;couchdb-flex-example&quot;</span><span style="color: #000000;">&#41;</span>;
      <span style="color: #0033ff; font-weight: bold;">this</span>.<span style="color: #004993;">log</span> = <span style="color: #990000;">&quot;&quot;</span>;
      <span style="color: #0033ff; font-weight: bold;">this</span>.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span>FlexEvent.CREATION_COMPLETE, <span style="color: #0033ff; font-weight: bold;">this</span>.creationCompleteHandler<span style="color: #000000;">&#41;</span>;
      <span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> creationCompleteHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000000; font-weight: bold;">:</span>FlexEvent<span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
    <span style="color: #000000;">&#123;</span>			
      <span style="color: #0033ff; font-weight: bold;">this</span>.database.create<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span>.databaseCreateHandler<span style="color: #000000;">&#41;</span>;	
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> databaseCreateHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000000; font-weight: bold;">:</span>CouchRestEvent<span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
    <span style="color: #000000;">&#123;</span>
      <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>event.<span style="color: #004993;">data</span><span style="color: #000000;">&#41;</span>;
      <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>event.json.ok <span style="color: #000000; font-weight: bold;">||</span> event.json.<span style="color: #004993;">error</span>.<span style="color: #004993;">toString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> == <span style="color: #990000;">&quot;file_exists&quot;</span><span style="color: #000000;">&#41;</span>
      <span style="color: #000000;">&#123;</span>
        <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">map</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;function(doc) {if (doc['couchdb-flex-type'] == 'com.gravityblast.couchdbflexexample::Contact') emit(null, doc);}&quot;</span>;
        <span style="color: #6699cc; font-weight: bold;">var</span> view<span style="color: #000000; font-weight: bold;">:</span>View = <span style="color: #0033ff; font-weight: bold;">new</span> View<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;all&quot;</span>, <span style="color: #004993;">map</span><span style="color: #000000;">&#41;</span>;
        <span style="color: #6699cc; font-weight: bold;">var</span> design<span style="color: #000000; font-weight: bold;">:</span>Design = <span style="color: #0033ff; font-weight: bold;">new</span> Design<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;contacts&quot;</span><span style="color: #000000;">&#41;</span>;
        design.addView<span style="color: #000000;">&#40;</span>view<span style="color: #000000;">&#41;</span>;
        design.<span style="color: #004993;">save</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span>.designSaveHandler<span style="color: #000000;">&#41;</span>;	
      <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> designSaveHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000000; font-weight: bold;">:</span>DocumentEvent<span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
    <span style="color: #000000;">&#123;</span>
      <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>event.<span style="color: #004993;">data</span><span style="color: #000000;">&#41;</span>;									
      <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>event.json.ok <span style="color: #000000; font-weight: bold;">||</span> event.json.<span style="color: #004993;">error</span> == <span style="color: #990000;">&quot;conflict&quot;</span><span style="color: #000000;">&#41;</span>			
        <span style="color: #0033ff; font-weight: bold;">this</span>.createContacts<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
      <span style="color: #0033ff; font-weight: bold;">else</span>
        <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Error saving design document: &quot;</span> <span style="color: #000000; font-weight: bold;">+</span> event.<span style="color: #004993;">data</span><span style="color: #000000;">&#41;</span>			
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> createContacts<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
    <span style="color: #000000;">&#123;</span>
      <span style="color: #6699cc; font-weight: bold;">var</span> contact<span style="color: #000000; font-weight: bold;">:</span>Contact = <span style="color: #0033ff; font-weight: bold;">new</span> Contact<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
      contact.<span style="color: #004993;">name</span>    = <span style="color: #990000;">&quot;jack&quot;</span>;
      contact.email   = <span style="color: #990000;">&quot;jack@example.com&quot;</span>;
      contact.address = <span style="color: #990000;">&quot;Jack Street&quot;</span>;
      contact.<span style="color: #004993;">save</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span>.contactSaveHandler<span style="color: #000000;">&#41;</span>;			
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> contactSaveHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000000; font-weight: bold;">:</span>DocumentEvent<span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
    <span style="color: #000000;">&#123;</span>			
      <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>event.<span style="color: #004993;">data</span><span style="color: #000000;">&#41;</span>;
      <span style="color: #6699cc; font-weight: bold;">var</span> contact<span style="color: #000000; font-weight: bold;">:</span>Contact = event.document <span style="color: #0033ff; font-weight: bold;">as</span> Contact;
      contact.address = <span style="color: #990000;">&quot;Jack Street updated at &quot;</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Date</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>.<span style="color: #004993;">toString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
      contact.<span style="color: #004993;">save</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span>.contactUpdateHandler<span style="color: #000000;">&#41;</span>;			
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> contactUpdateHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000000; font-weight: bold;">:</span>DocumentEvent<span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
    <span style="color: #000000;">&#123;</span>			
      <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>event.<span style="color: #004993;">data</span><span style="color: #000000;">&#41;</span>;
      View.<span style="color: #004993;">load</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;contacts&quot;</span>, <span style="color: #990000;">&quot;all&quot;</span>, <span style="color: #000000;">&#123;</span><span style="color: #000000;">&#125;</span>, <span style="color: #0033ff; font-weight: bold;">this</span>.contactsLoadHandler<span style="color: #000000;">&#41;</span>;
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> contactsLoadHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000000; font-weight: bold;">:</span>ViewEvent<span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
    <span style="color: #000000;">&#123;</span>					
      <span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #0033ff; font-weight: bold;">each</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> contact<span style="color: #000000; font-weight: bold;">:</span>Contact <span style="color: #0033ff; font-weight: bold;">in</span> event.documents<span style="color: #000000;">&#41;</span>
      <span style="color: #000000;">&#123;</span>
        <span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> property<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span> <span style="color: #0033ff; font-weight: bold;">in</span> contact.<span style="color: #004993;">attributes</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
          <span style="color: #0033ff; font-weight: bold;">this</span>.<span style="color: #004993;">log</span> <span style="color: #000000; font-weight: bold;">+</span>= property <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot;: &quot;</span> <span style="color: #000000; font-weight: bold;">+</span> contact<span style="color: #000000;">&#91;</span>property<span style="color: #000000;">&#93;</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot;<span style="">\n</span>&quot;</span>;	
        <span style="color: #000000;">&#125;</span>
        <span style="color: #0033ff; font-weight: bold;">this</span>.<span style="color: #004993;">log</span> <span style="color: #000000; font-weight: bold;">+</span>= <span style="color: #990000;">&quot;-------------<span style="">\n</span>&quot;</span>;
      <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
  <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>I&#8217;ll write more about the library as soon as it&#8217;s more stable.</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>share</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://buzz.yahoo.com/submit?submitUrl=http://gravityblast.com/2009/11/03/using-couchdb-from-air-applications-with-couchdb-flex/&amp;submitHeadline=Using+CouchDB+from+Air+applications+with+CouchDB+Flex&amp;submitSummary=" rel="nofollow" title="Add to&nbsp;Buzz"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/buzz.png" title="Add to&nbsp;Buzz" alt="Add to&nbsp;Buzz" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://gravityblast.com/2009/11/03/using-couchdb-from-air-applications-with-couchdb-flex/&amp;title=Using+CouchDB+from+Air+applications+with+CouchDB+Flex" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://gravityblast.com/2009/11/03/using-couchdb-from-air-applications-with-couchdb-flex/&amp;title=Using+CouchDB+from+Air+applications+with+CouchDB+Flex" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.dzone.com/links/add.html?description=Using+CouchDB+from+Air+applications+with+CouchDB+Flex&amp;url=http://gravityblast.com/2009/11/03/using-couchdb-from-air-applications-with-couchdb-flex/&amp;title=Using+CouchDB+from+Air+applications+with+CouchDB+Flex" rel="nofollow" title="Add to&nbsp;DZone"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/dzone.png" title="Add to&nbsp;DZone" alt="Add to&nbsp;DZone" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://gravityblast.com/2009/11/03/using-couchdb-from-air-applications-with-couchdb-flex/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://gravityblast.com/2009/11/03/using-couchdb-from-air-applications-with-couchdb-flex/&amp;title=Using+CouchDB+from+Air+applications+with+CouchDB+Flex" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http://gravityblast.com/2009/11/03/using-couchdb-from-air-applications-with-couchdb-flex/&amp;T=Using+CouchDB+from+Air+applications+with+CouchDB+Flex" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://gravityblast.com/2009/11/03/using-couchdb-from-air-applications-with-couchdb-flex/&amp;title=Using+CouchDB+from+Air+applications+with+CouchDB+Flex" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://slashdot.org/bookmark.pl?url=http://gravityblast.com/2009/11/03/using-couchdb-from-air-applications-with-couchdb-flex/&amp;title=Using+CouchDB+from+Air+applications+with+CouchDB+Flex" rel="nofollow" title="Add to&nbsp;Slashdot"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/slashdot.png" title="Add to&nbsp;Slashdot" alt="Add to&nbsp;Slashdot" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://gravityblast.com/2009/11/03/using-couchdb-from-air-applications-with-couchdb-flex/&amp;title=Using+CouchDB+from+Air+applications+with+CouchDB+Flex" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://gravityblast.com/2009/11/03/using-couchdb-from-air-applications-with-couchdb-flex/" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://tipd.com/submit.php?url=http://gravityblast.com/2009/11/03/using-couchdb-from-air-applications-with-couchdb-flex/" rel="nofollow" title="Add to&nbsp;Tip'd"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/tipd.png" title="Add to&nbsp;Tip'd" alt="Add to&nbsp;Tip'd" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Using+CouchDB+from+Air+applications+with+CouchDB+Flex+@+http://gravityblast.com/2009/11/03/using-couchdb-from-air-applications-with-couchdb-flex/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://gravityblast.com/2009/11/03/using-couchdb-from-air-applications-with-couchdb-flex/&amp;t=Using+CouchDB+from+Air+applications+with+CouchDB+Flex" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://gravityblast.com/2009/11/03/using-couchdb-from-air-applications-with-couchdb-flex/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Flex functional testing with FunFx and Cucumber</title>
		<link>http://gravityblast.com/2009/08/20/flex-functional-testing-with-funfx-and-cucumber/</link>
		<comments>http://gravityblast.com/2009/08/20/flex-functional-testing-with-funfx-and-cucumber/#comments</comments>
		<pubDate>Thu, 20 Aug 2009 13:11:56 +0000</pubDate>
		<dc:creator>Andrea Franz</dc:creator>
				<category><![CDATA[Cucumber]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[RIA]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://gravityblast.com/?p=317</guid>
		<description><![CDATA[Cucumber is a great tool I usually use for BDD in my ruby projects, but yesterday I tried it with Flex, and it was very enjoyable. Here a little example on how to test Flex applications with Cucumber.
First of all you need ruby, then you need to install the following gems:

sudo gem install rspec cucumber [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://cukes.info/">Cucumber</a> is a great tool I usually use for <a href="http://en.wikipedia.org/wiki/Behavior_driven_development" title="Behavior Driven Development">BDD</a> in my ruby projects, but yesterday I tried it with Flex, and it was very enjoyable. Here a little example on how to test Flex applications with Cucumber.</p>
<p>First of all you need ruby, then you need to install the following gems:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> rspec cucumber watir safariwatir funfx</pre></div></div>

<p>(I used the following codes on <strong>mac os x</strong>, with <strong>ruby 1.8.6</strong>, <strong>safari 4.0.3</strong> and <strong>funx 0.2.2</strong>)</p>
<p>After that open Flex Builder and create a new project called CucumberExample and use the following code for your main mxml file:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span>xml <span style="color: #004993;">version</span>=<span style="color: #990000;">&quot;1.0&quot;</span> encoding=<span style="color: #990000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;</span>mx<span style="color: #000000; font-weight: bold;">:</span>Application xmlns<span style="color: #000000; font-weight: bold;">:</span>mx=<span style="color: #990000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> layout=<span style="color: #990000;">&quot;absolute&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;</span>mx<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> id=<span style="color: #990000;">&quot;index&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000; font-weight: bold;">&lt;/</span>mx<span style="color: #000000; font-weight: bold;">:</span>Number<span style="color: #000000; font-weight: bold;">&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;</span>mx<span style="color: #000000; font-weight: bold;">:</span>VBox <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;300&quot;</span> <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;200&quot;</span> <span style="color: #004993;">backgroundColor</span>=<span style="color: #990000;">&quot;white&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
		<span style="color: #000000; font-weight: bold;">&lt;</span>mx<span style="color: #000000; font-weight: bold;">:</span>HBox <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;100%&quot;</span> <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;30&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>			
			<span style="color: #000000; font-weight: bold;">&lt;</span>mx<span style="color: #000000; font-weight: bold;">:</span>Button id=<span style="color: #990000;">&quot;buttonDecrement&quot;</span> label=<span style="color: #990000;">&quot;-&quot;</span> <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;100%&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span>
			<span style="color: #000000; font-weight: bold;">&lt;</span>mx<span style="color: #000000; font-weight: bold;">:</span>Button id=<span style="color: #990000;">&quot;buttonIncrement&quot;</span> label=<span style="color: #990000;">&quot;+&quot;</span> <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;100%&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span>
		<span style="color: #000000; font-weight: bold;">&lt;/</span>mx<span style="color: #000000; font-weight: bold;">:</span>HBox<span style="color: #000000; font-weight: bold;">&gt;</span>
		<span style="color: #000000; font-weight: bold;">&lt;</span>mx<span style="color: #000000; font-weight: bold;">:</span>HBox <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;100%&quot;</span> <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;100%&quot;</span> verticalAlign=<span style="color: #990000;">&quot;middle&quot;</span> horizontalAlign=<span style="color: #990000;">&quot;center&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
			<span style="color: #000000; font-weight: bold;">&lt;</span>mx<span style="color: #000000; font-weight: bold;">:</span>Label id=<span style="color: #990000;">&quot;myLabel&quot;</span> <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;{index}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span>			
		<span style="color: #000000; font-weight: bold;">&lt;/</span>mx<span style="color: #000000; font-weight: bold;">:</span>HBox<span style="color: #000000; font-weight: bold;">&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;/</span>mx<span style="color: #000000; font-weight: bold;">:</span>VBox<span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;/</span>mx<span style="color: #000000; font-weight: bold;">:</span>Application<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p>As you can see, we have a number, 2 buttons and a label. Now create a directory called features inside your flex project folder and create the first Cucumber feature file, called counter:</p>
<p><strong>CucumberExample/features/counter.feature</strong>:</p>

<div class="wp_syntax"><div class="code"><pre class="cucumber" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">Feature</span>: Counter
  <span style="color:#9966CC; font-weight:bold;">In order</span> to count something
  As a flex rock star
  I want to use my great flex app
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">Scenario</span>: Increment index
    <span style="color:#9966CC; font-weight:bold;">Given</span> I open my flex app
    <span style="color:#9966CC; font-weight:bold;">And</span> I click the increment button
    <span style="color:#9966CC; font-weight:bold;">Then</span> the label text should be <span style="color:#996600;">&quot;1&quot;</span>
    <span style="color:#9966CC; font-weight:bold;">When</span> I click the decrement button
    <span style="color:#9966CC; font-weight:bold;">Then</span> the label text should be <span style="color:#996600;">&quot;0&quot;</span>
    <span style="color:#9966CC; font-weight:bold;">When</span> I click the decrement button
    <span style="color:#9966CC; font-weight:bold;">Then</span> the label text should be <span style="color:#996600;">&quot;-1&quot;</span></pre></div></div>

<p>It&#8217;s a test written in pure plain text.</p>
<p>In the <strong>features</strong> folder create another folder called <strong>step_definitions</strong> with a blank file called <strong>counter_steps.rb</strong>, we&#8217;ll use it later.</p>
<p>Now open the console, go the to flex project root and run your test:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>CucumberExample
cucumber features</pre></div></div>

<p>You should see something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">...
<span style="color: #000000;">1</span> scenario <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">1</span> undefined<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000;">7</span> steps <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">7</span> undefined<span style="color: #7a0874; font-weight: bold;">&#41;</span>
0m0.002s</pre></div></div>

<p>You can implement step definitions for undefined steps with these snippets:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">Given <span style="color:#006600; font-weight:bold;">/</span>^I <span style="color:#CC0066; font-weight:bold;">open</span> my flex app$<span style="color:#006600; font-weight:bold;">/</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  pending
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
Given <span style="color:#006600; font-weight:bold;">/</span>^I click the increment button$<span style="color:#006600; font-weight:bold;">/</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  pending
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">Then</span> <span style="color:#006600; font-weight:bold;">/</span>^the label text should be <span style="color:#996600;">&quot;([^<span style="color:#000099;">\&quot;</span>]*)&quot;</span>$<span style="color:#006600; font-weight:bold;">/</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>arg1<span style="color:#006600; font-weight:bold;">|</span>
  pending
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">When</span> <span style="color:#006600; font-weight:bold;">/</span>^I click the decrement button$<span style="color:#006600; font-weight:bold;">/</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  pending
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Before implementing the steps above, we need to add the funfx component to our library.</p>
<p>Download the latest <strong>swc</strong> file from <a href="http://rubyforge.org/frs/?group_id=3898&#038;release_id=16452">rubyforge</a> and place it in your <strong>CucumberExample/libs</strong> folder (I used the version 0.2.2).</p>
<p>Duplicate the bin-debug folder and rename it to <strong>test</strong> (you have a bin-debug folder after the first time you run the CucumberExample from FlexBuilder).</p>
<p>Inside the test directory create a file called <strong>test_server.rb</strong> with the following content:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'webrick'</span>
&nbsp;
server = <span style="color:#6666ff; font-weight:bold;">WEBrick::HTTPServer</span>.<span style="color:#9900CC;">new</span> <span style="color:#ff3333; font-weight:bold;">:Port</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">9852</span>, <span style="color:#ff3333; font-weight:bold;">:DocumentRoot</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">dirname</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">__FILE__</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#CC0066; font-weight:bold;">trap</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;INT&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#123;</span> server.<span style="color:#9900CC;">shutdown</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
server.<span style="color:#9900CC;">start</span></pre></div></div>

<p>Now you need a compiled version of your project that includes funfx.We&#8217;ll use it just for testing:</p>
<p><strong>build_test.sh</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #007800;">FLEX_SDK_HOME</span>=<span style="color: #ff0000;">&quot;/Applications/Adobe Flex Builder 3/sdks/3.2.0&quot;</span>
<span style="color: #ff0000;">&quot;<span style="color: #007800;">$FLEX_SDK_HOME</span>/bin/mxmlc&quot;</span> <span style="color: #660033;">-verbose-stacktraces</span> <span style="color: #660033;">-include-libraries</span> .<span style="color: #000000; font-weight: bold;">/</span>libs<span style="color: #000000; font-weight: bold;">/</span>funfx-0.2.2.swc <span style="color: #ff0000;">&quot;<span style="color: #007800;">$FLEX_SDK_HOME</span>/frameworks/libs/automation.swc&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$FLEX_SDK_HOME</span>/frameworks/libs/automation_dmv.swc&quot;</span>  <span style="color: #ff0000;">&quot;<span style="color: #007800;">$FLEX_SDK_HOME</span>/frameworks/libs/automation_agent.swc&quot;</span> <span style="color: #660033;">-output</span> .<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">test</span><span style="color: #000000; font-weight: bold;">/</span>CucumberExample.swf <span style="color: #660033;">--</span> .<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #000000; font-weight: bold;">/</span>CucumberExample.mxml</pre></div></div>

<p>Run test <strong>compile_test.sh</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">755</span> .<span style="color: #000000; font-weight: bold;">/</span>build_test.sh
.<span style="color: #000000; font-weight: bold;">/</span>build_test.sh</pre></div></div>

<p>Now open another terminal window and start the test server:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>CucumberExample<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">test</span>
ruby test_server.rb</pre></div></div>

<p>Open http://localhost:9852/CucumberExample.html with your browser and you should see your flex app.</p>
<p>Now you can come back to your features and implement the step we leave before. Here my implementation:</p>
<p><strong>CucumberExample/features/step_definitions/counter_steps.rb</strong></p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">Given <span style="color:#006600; font-weight:bold;">/</span>^I <span style="color:#CC0066; font-weight:bold;">open</span> my flex app$<span style="color:#006600; font-weight:bold;">/</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  open_flex_app
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
Given <span style="color:#006600; font-weight:bold;">/</span>^I click the <span style="color:#006600; font-weight:bold;">&#40;</span>increment<span style="color:#006600; font-weight:bold;">|</span>decrement<span style="color:#006600; font-weight:bold;">&#41;</span> button$<span style="color:#006600; font-weight:bold;">/</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>button<span style="color:#006600; font-weight:bold;">|</span>  
  click_button<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;button#{button.capitalize}&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>  
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">Then</span> <span style="color:#006600; font-weight:bold;">/</span>^the label text should be <span style="color:#996600;">&quot;([^<span style="color:#000099;">\&quot;</span>]*)&quot;</span>$<span style="color:#006600; font-weight:bold;">/</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>text<span style="color:#006600; font-weight:bold;">|</span>
  label_text.<span style="color:#9900CC;">should</span> == text  
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p><strong>open_flex_app</strong>, <strong>click_button</strong> and <strong>label_text</strong> are methods  defined in my <strong>env.rb</strong> file.</p>
<p><strong>CucumberExample/features/support/env.rb</strong></p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">&quot;rubygems&quot;</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'funfx/browser/safariwatir'</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">module</span> FlexWorld
  <span style="color:#9966CC; font-weight:bold;">def</span> open_flex_app
    <span style="color:#0066ff; font-weight:bold;">@browser</span>.<span style="color:#9900CC;">goto</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;http://localhost:9852/CucumberExample.html&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> click_button<span style="color:#006600; font-weight:bold;">&#40;</span>button_id<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0066ff; font-weight:bold;">@flex_app</span>.<span style="color:#9900CC;">button</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> button_id<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">click</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> label_text
    <span style="color:#0066ff; font-weight:bold;">@flex_app</span>.<span style="color:#9900CC;">label</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;myLabel&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">text</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
Before <span style="color:#9966CC; font-weight:bold;">do</span>
  <span style="color:#0066ff; font-weight:bold;">@browser</span>  = <span style="color:#6666ff; font-weight:bold;">Watir::Safari</span>.<span style="color:#9900CC;">new</span>
  <span style="color:#0066ff; font-weight:bold;">@flex_app</span> = <span style="color:#0066ff; font-weight:bold;">@browser</span>.<span style="color:#9900CC;">flex_app</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;CucumberExample&quot;</span>, <span style="color:#996600;">&quot;CucumberExample&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>  
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
After <span style="color:#9966CC; font-weight:bold;">do</span>
  <span style="color:#0066ff; font-weight:bold;">@browser</span>.<span style="color:#9900CC;">close</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
World<span style="color:#006600; font-weight:bold;">&#40;</span>FlexWorld<span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>Now you are ready to run your tests.  Start the test_server and then the features. You should have  an error:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Then the label text should be <span style="color: #ff0000;">&quot;1&quot;</span>  <span style="color: #666666; font-style: italic;"># features/step_definitions/counter_steps.rb:9</span>
      expected: <span style="color: #ff0000;">&quot;1&quot;</span>,
           got: <span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>using ==<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>This because we didn&#8217;t implement the functionality yet in our flex app. So, change the mxml file with the following:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span>xml <span style="color: #004993;">version</span>=<span style="color: #990000;">&quot;1.0&quot;</span> encoding=<span style="color: #990000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;</span>mx<span style="color: #000000; font-weight: bold;">:</span>Application xmlns<span style="color: #000000; font-weight: bold;">:</span>mx=<span style="color: #990000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> layout=<span style="color: #990000;">&quot;absolute&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;</span>mx<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> id=<span style="color: #990000;">&quot;index&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000; font-weight: bold;">&lt;/</span>mx<span style="color: #000000; font-weight: bold;">:</span>Number<span style="color: #000000; font-weight: bold;">&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;</span>mx<span style="color: #000000; font-weight: bold;">:</span>VBox <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;300&quot;</span> <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;200&quot;</span> <span style="color: #004993;">backgroundColor</span>=<span style="color: #990000;">&quot;white&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
		<span style="color: #000000; font-weight: bold;">&lt;</span>mx<span style="color: #000000; font-weight: bold;">:</span>HBox <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;100%&quot;</span> <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;30&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>			
			<span style="color: #000000; font-weight: bold;">&lt;</span>mx<span style="color: #000000; font-weight: bold;">:</span>Button id=<span style="color: #990000;">&quot;buttonDecrement&quot;</span> label=<span style="color: #990000;">&quot;-&quot;</span> <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;100%&quot;</span> <span style="color: #004993;">click</span>=<span style="color: #990000;">&quot;index--&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span>
			<span style="color: #000000; font-weight: bold;">&lt;</span>mx<span style="color: #000000; font-weight: bold;">:</span>Button id=<span style="color: #990000;">&quot;buttonIncrement&quot;</span> label=<span style="color: #990000;">&quot;+&quot;</span> <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;100%&quot;</span> <span style="color: #004993;">click</span>=<span style="color: #990000;">&quot;index++&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span>
		<span style="color: #000000; font-weight: bold;">&lt;/</span>mx<span style="color: #000000; font-weight: bold;">:</span>HBox<span style="color: #000000; font-weight: bold;">&gt;</span>
		<span style="color: #000000; font-weight: bold;">&lt;</span>mx<span style="color: #000000; font-weight: bold;">:</span>HBox <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;100%&quot;</span> <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;100%&quot;</span> verticalAlign=<span style="color: #990000;">&quot;middle&quot;</span> horizontalAlign=<span style="color: #990000;">&quot;center&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
			<span style="color: #000000; font-weight: bold;">&lt;</span>mx<span style="color: #000000; font-weight: bold;">:</span>Label id=<span style="color: #990000;">&quot;myLabel&quot;</span> <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;{index}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span>			
		<span style="color: #000000; font-weight: bold;">&lt;/</span>mx<span style="color: #000000; font-weight: bold;">:</span>HBox<span style="color: #000000; font-weight: bold;">&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;/</span>mx<span style="color: #000000; font-weight: bold;">:</span>VBox<span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;/</span>mx<span style="color: #000000; font-weight: bold;">:</span>Application<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p>It&#8217;s the same code but I added the click action to the increment and decrement buttons. Now compile the new code and run the features again:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>build_test.sh
cucumber features</pre></div></div>

<p>You shoiuld have the following output, with all the seven steps passed:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Feature: Counter
  In order to count something
  As a <span style="color: #c20cb9; font-weight: bold;">flex</span> rock star
  I want to use my great <span style="color: #c20cb9; font-weight: bold;">flex</span> app
&nbsp;
  Scenario: Increment index            <span style="color: #666666; font-style: italic;"># features/counter.feature:6</span>
    Given I open my <span style="color: #c20cb9; font-weight: bold;">flex</span> app           <span style="color: #666666; font-style: italic;"># features/step_definitions/counter_steps.rb:1</span>
    And I click the increment button   <span style="color: #666666; font-style: italic;"># features/step_definitions/counter_steps.rb:5</span>
    Then the label text should be <span style="color: #ff0000;">&quot;1&quot;</span>  <span style="color: #666666; font-style: italic;"># features/step_definitions/counter_steps.rb:9</span>
    When I click the decrement button  <span style="color: #666666; font-style: italic;"># features/step_definitions/counter_steps.rb:5</span>
    Then the label text should be <span style="color: #ff0000;">&quot;0&quot;</span>  <span style="color: #666666; font-style: italic;"># features/step_definitions/counter_steps.rb:9</span>
    When I click the decrement button  <span style="color: #666666; font-style: italic;"># features/step_definitions/counter_steps.rb:5</span>
    Then the label text should be <span style="color: #ff0000;">&quot;-1&quot;</span> <span style="color: #666666; font-style: italic;"># features/step_definitions/counter_steps.rb:9</span>
&nbsp;
<span style="color: #000000;">1</span> scenario <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">1</span> passed<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000;">7</span> steps <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">7</span> passed<span style="color: #7a0874; font-weight: bold;">&#41;</span>
0m9.781s</pre></div></div>

<p>If you have any problems you may want to clear the cache from safari.</p>
<p>I used the funfx gem from  <a href="http://funfx.rubyforge.org/">rubyforge</a> but it&#8217;s not up to date. If you want you can get the new code from <a href="http://github.com/peternic/funfx/tree/master">github</a>, it should have new features.</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>share</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://buzz.yahoo.com/submit?submitUrl=http://gravityblast.com/2009/08/20/flex-functional-testing-with-funfx-and-cucumber/&amp;submitHeadline=Flex+functional+testing+with+FunFx+and+Cucumber&amp;submitSummary=" rel="nofollow" title="Add to&nbsp;Buzz"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/buzz.png" title="Add to&nbsp;Buzz" alt="Add to&nbsp;Buzz" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://gravityblast.com/2009/08/20/flex-functional-testing-with-funfx-and-cucumber/&amp;title=Flex+functional+testing+with+FunFx+and+Cucumber" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://gravityblast.com/2009/08/20/flex-functional-testing-with-funfx-and-cucumber/&amp;title=Flex+functional+testing+with+FunFx+and+Cucumber" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.dzone.com/links/add.html?description=Flex+functional+testing+with+FunFx+and+Cucumber&amp;url=http://gravityblast.com/2009/08/20/flex-functional-testing-with-funfx-and-cucumber/&amp;title=Flex+functional+testing+with+FunFx+and+Cucumber" rel="nofollow" title="Add to&nbsp;DZone"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/dzone.png" title="Add to&nbsp;DZone" alt="Add to&nbsp;DZone" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://gravityblast.com/2009/08/20/flex-functional-testing-with-funfx-and-cucumber/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://gravityblast.com/2009/08/20/flex-functional-testing-with-funfx-and-cucumber/&amp;title=Flex+functional+testing+with+FunFx+and+Cucumber" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http://gravityblast.com/2009/08/20/flex-functional-testing-with-funfx-and-cucumber/&amp;T=Flex+functional+testing+with+FunFx+and+Cucumber" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://gravityblast.com/2009/08/20/flex-functional-testing-with-funfx-and-cucumber/&amp;title=Flex+functional+testing+with+FunFx+and+Cucumber" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://slashdot.org/bookmark.pl?url=http://gravityblast.com/2009/08/20/flex-functional-testing-with-funfx-and-cucumber/&amp;title=Flex+functional+testing+with+FunFx+and+Cucumber" rel="nofollow" title="Add to&nbsp;Slashdot"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/slashdot.png" title="Add to&nbsp;Slashdot" alt="Add to&nbsp;Slashdot" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://gravityblast.com/2009/08/20/flex-functional-testing-with-funfx-and-cucumber/&amp;title=Flex+functional+testing+with+FunFx+and+Cucumber" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://gravityblast.com/2009/08/20/flex-functional-testing-with-funfx-and-cucumber/" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://tipd.com/submit.php?url=http://gravityblast.com/2009/08/20/flex-functional-testing-with-funfx-and-cucumber/" rel="nofollow" title="Add to&nbsp;Tip'd"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/tipd.png" title="Add to&nbsp;Tip'd" alt="Add to&nbsp;Tip'd" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Flex+functional+testing+with+FunFx+and+Cucumber+@+http://gravityblast.com/2009/08/20/flex-functional-testing-with-funfx-and-cucumber/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://gravityblast.com/2009/08/20/flex-functional-testing-with-funfx-and-cucumber/&amp;t=Flex+functional+testing+with+FunFx+and+Cucumber" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://gravityblast.com/2009/08/20/flex-functional-testing-with-funfx-and-cucumber/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Hostname middleware for rails apps on multiple servers</title>
		<link>http://gravityblast.com/2009/08/15/hostname-middleware-for-rails-apps-on-multiple-servers/</link>
		<comments>http://gravityblast.com/2009/08/15/hostname-middleware-for-rails-apps-on-multiple-servers/#comments</comments>
		<pubDate>Sat, 15 Aug 2009 22:37:36 +0000</pubDate>
		<dc:creator>Andrea Franz</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://gravityblast.com/?p=303</guid>
		<description><![CDATA[If you run a rails application on multiple servers behind a load balancer, almost every time you make a request you have a response from a different host. If you want to know which host has sent back the response, you can use a middleware that adds the hostname in the page title of each [...]]]></description>
			<content:encoded><![CDATA[<p>If you run a rails application on multiple servers behind a load balancer, almost every time you make a request you have a response from a different host. If you want to know which host has sent back the response, you can use a middleware that adds the hostname in the page title of each request.</p>
<p><strong>lib/hostname.rb</strong>:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> Hostname  
  TITLE_REGEXP = <span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&lt;</span>title<span style="color:#006600; font-weight:bold;">&gt;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#91;</span>^<span style="color:#006600; font-weight:bold;">&lt;</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">*</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&lt;</span>\<span style="color:#006600; font-weight:bold;">/</span>title<span style="color:#006600; font-weight:bold;">&gt;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">/</span>i
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> initialize<span style="color:#006600; font-weight:bold;">&#40;</span>app, hostname=<span style="color:#996600;">&quot;&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0066ff; font-weight:bold;">@app</span>          = app
    <span style="color:#0066ff; font-weight:bold;">@title_suffix</span> = <span style="color:#996600;">&quot; - on #{hostname}&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> call<span style="color:#006600; font-weight:bold;">&#40;</span>env<span style="color:#006600; font-weight:bold;">&#41;</span>
    status, headers, response = <span style="color:#0066ff; font-weight:bold;">@app</span>.<span style="color:#9900CC;">call</span><span style="color:#006600; font-weight:bold;">&#40;</span>env<span style="color:#006600; font-weight:bold;">&#41;</span>
    add_hostname<span style="color:#006600; font-weight:bold;">&#40;</span>response, headers<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> headers<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;Content-Type&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span> =~ <span style="color:#006600; font-weight:bold;">%</span>r<span style="color:#006600; font-weight:bold;">&#123;</span>text<span style="color:#006600; font-weight:bold;">/</span>html<span style="color:#006600; font-weight:bold;">&#125;</span>
    <span style="color:#006600; font-weight:bold;">&#91;</span>status, headers, response<span style="color:#006600; font-weight:bold;">&#93;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>  
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> add_hostname<span style="color:#006600; font-weight:bold;">&#40;</span>response, headers<span style="color:#006600; font-weight:bold;">&#41;</span>
    response.<span style="color:#9900CC;">each</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>s<span style="color:#006600; font-weight:bold;">|</span> s.<span style="color:#CC0066; font-weight:bold;">sub!</span><span style="color:#006600; font-weight:bold;">&#40;</span>TITLE_REGEXP, <span style="color:#996600;">&quot;<span style="color:#000099;">\\</span>1<span style="color:#000099;">\\</span>2#{@title_suffix}<span style="color:#000099;">\\</span>3&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> s =~ TITLE_REGEXP<span style="color:#006600; font-weight:bold;">&#125;</span>
    headers<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;Content-Length&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#006600; font-weight:bold;">&#40;</span>headers<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;Content-Length&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">to_i</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#0066ff; font-weight:bold;">@title_suffix</span>.<span style="color:#9900CC;">length</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">to_s</span>
    <span style="color:#0000FF; font-weight:bold;">nil</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>To use it, add this line in your <strong>environment.rb</strong>:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">config.<span style="color:#9900CC;">middleware</span>.<span style="color:#9900CC;">use</span> <span style="color:#996600;">&quot;Hostname&quot;</span>, <span style="color:#006600; font-weight:bold;">%</span>x<span style="color:#996600;">&quot;hostname&quot;</span>.<span style="color:#CC0066; font-weight:bold;">chomp</span></pre></div></div>

<p>When you don&#8217;t need it anymore you can simply remove the line above.</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>share</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://buzz.yahoo.com/submit?submitUrl=http://gravityblast.com/2009/08/15/hostname-middleware-for-rails-apps-on-multiple-servers/&amp;submitHeadline=Hostname+middleware+for+rails+apps+on+multiple+servers&amp;submitSummary=" rel="nofollow" title="Add to&nbsp;Buzz"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/buzz.png" title="Add to&nbsp;Buzz" alt="Add to&nbsp;Buzz" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://gravityblast.com/2009/08/15/hostname-middleware-for-rails-apps-on-multiple-servers/&amp;title=Hostname+middleware+for+rails+apps+on+multiple+servers" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://gravityblast.com/2009/08/15/hostname-middleware-for-rails-apps-on-multiple-servers/&amp;title=Hostname+middleware+for+rails+apps+on+multiple+servers" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.dzone.com/links/add.html?description=Hostname+middleware+for+rails+apps+on+multiple+servers&amp;url=http://gravityblast.com/2009/08/15/hostname-middleware-for-rails-apps-on-multiple-servers/&amp;title=Hostname+middleware+for+rails+apps+on+multiple+servers" rel="nofollow" title="Add to&nbsp;DZone"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/dzone.png" title="Add to&nbsp;DZone" alt="Add to&nbsp;DZone" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://gravityblast.com/2009/08/15/hostname-middleware-for-rails-apps-on-multiple-servers/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://gravityblast.com/2009/08/15/hostname-middleware-for-rails-apps-on-multiple-servers/&amp;title=Hostname+middleware+for+rails+apps+on+multiple+servers" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http://gravityblast.com/2009/08/15/hostname-middleware-for-rails-apps-on-multiple-servers/&amp;T=Hostname+middleware+for+rails+apps+on+multiple+servers" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://gravityblast.com/2009/08/15/hostname-middleware-for-rails-apps-on-multiple-servers/&amp;title=Hostname+middleware+for+rails+apps+on+multiple+servers" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://slashdot.org/bookmark.pl?url=http://gravityblast.com/2009/08/15/hostname-middleware-for-rails-apps-on-multiple-servers/&amp;title=Hostname+middleware+for+rails+apps+on+multiple+servers" rel="nofollow" title="Add to&nbsp;Slashdot"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/slashdot.png" title="Add to&nbsp;Slashdot" alt="Add to&nbsp;Slashdot" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://gravityblast.com/2009/08/15/hostname-middleware-for-rails-apps-on-multiple-servers/&amp;title=Hostname+middleware+for+rails+apps+on+multiple+servers" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://gravityblast.com/2009/08/15/hostname-middleware-for-rails-apps-on-multiple-servers/" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://tipd.com/submit.php?url=http://gravityblast.com/2009/08/15/hostname-middleware-for-rails-apps-on-multiple-servers/" rel="nofollow" title="Add to&nbsp;Tip'd"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/tipd.png" title="Add to&nbsp;Tip'd" alt="Add to&nbsp;Tip'd" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Hostname+middleware+for+rails+apps+on+multiple+servers+@+http://gravityblast.com/2009/08/15/hostname-middleware-for-rails-apps-on-multiple-servers/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://gravityblast.com/2009/08/15/hostname-middleware-for-rails-apps-on-multiple-servers/&amp;t=Hostname+middleware+for+rails+apps+on+multiple+servers" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://gravityblast.com/2009/08/15/hostname-middleware-for-rails-apps-on-multiple-servers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Testing rails generators with Cucumber</title>
		<link>http://gravityblast.com/2009/08/11/testing-rails-generators-with-cucumber/</link>
		<comments>http://gravityblast.com/2009/08/11/testing-rails-generators-with-cucumber/#comments</comments>
		<pubDate>Tue, 11 Aug 2009 13:43:59 +0000</pubDate>
		<dc:creator>Andrea Franz</dc:creator>
				<category><![CDATA[Cucumber]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://gravityblast.com/?p=282</guid>
		<description><![CDATA[In the last days I switched a lot of old projects to use Cucumber, then I started writing test for Web App Theme. Here I haven&#8217;t models or controllers to test, because it&#8217;s just a generator, but I found enjoyable the use of plain text features to describe the ThemeGenerator behavior:

Feature: Layout generation
  In [...]]]></description>
			<content:encoded><![CDATA[<p>In the last days I switched a lot of old projects to use <a href="http://cukes.info/" title="Cucumber">Cucumber</a>, then I started writing test for <a href="http://github.com/pilu/web-app-theme" title="Web App Theme">Web App Theme</a>. Here I haven&#8217;t models or controllers to test, because it&#8217;s just a generator, but I found enjoyable the use of plain text features to describe the <strong>ThemeGenerator</strong> behavior:</p>

<div class="wp_syntax"><div class="code"><pre class="cucumber" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">Feature</span>: Layout generation
  <span style="color:#9966CC; font-weight:bold;">In order</span> to create a great application
  I should be able to generate a layout with Web App Theme
&nbsp;
  <span style="color:#008000; font-style:italic;"># script/generate theme</span>
  <span style="color:#9966CC; font-weight:bold;">Scenario</span>: Generate a layout    
    <span style="color:#9966CC; font-weight:bold;">Given</span> I have a new rails app
    <span style="color:#9966CC; font-weight:bold;">And</span> I have no layouts
    <span style="color:#9966CC; font-weight:bold;">And</span> I have no stylesheets
    <span style="color:#9966CC; font-weight:bold;">When</span> I generate a theme
    <span style="color:#9966CC; font-weight:bold;">Then</span> I should have a layout named <span style="color:#996600;">&quot;application.html.erb&quot;</span>
    <span style="color:#9966CC; font-weight:bold;">And</span> I should have a stylesheet named <span style="color:#996600;">&quot;web_app_theme.css&quot;</span>
    <span style="color:#9966CC; font-weight:bold;">And</span> I should have a stylesheet named <span style="color:#996600;">&quot;web_app_theme_override.css&quot;</span>
    <span style="color:#9966CC; font-weight:bold;">And</span> I should have a stylesheet named <span style="color:#996600;">&quot;themes/default/style.css&quot;</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># script/generate theme admin</span>
  <span style="color:#9966CC; font-weight:bold;">Scenario</span>: Generate a layout with a name
    <span style="color:#9966CC; font-weight:bold;">Given</span> I have a new rails app
    <span style="color:#9966CC; font-weight:bold;">And</span> I have no layouts
    <span style="color:#9966CC; font-weight:bold;">And</span> I generate a theme with name <span style="color:#996600;">&quot;admin&quot;</span>
    <span style="color:#9966CC; font-weight:bold;">Then</span> I should have a layout named <span style="color:#996600;">&quot;admin.html.erb&quot;</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># script/generate theme --theme=&quot;drastic-dark&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">Scenario</span>: Generate a layout choosing a theme
    <span style="color:#9966CC; font-weight:bold;">Given</span> I have a new rails app
    <span style="color:#9966CC; font-weight:bold;">And</span> I have no stylesheets
    <span style="color:#9966CC; font-weight:bold;">And</span> I generate a theme choosing the <span style="color:#996600;">&quot;drastic-dark&quot;</span> theme
    <span style="color:#9966CC; font-weight:bold;">Then</span> I should have a stylesheet named <span style="color:#996600;">&quot;themes/drastic-dark/style.css&quot;</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># script/generate theme --theme=bec --no_layout</span>
  <span style="color:#9966CC; font-weight:bold;">Scenario</span>: Generate only stylesheets without layout
    <span style="color:#9966CC; font-weight:bold;">Given</span> I have a new rails app
    <span style="color:#9966CC; font-weight:bold;">And</span> I have no layouts
    <span style="color:#9966CC; font-weight:bold;">And</span> I generate a theme without layout choosing the <span style="color:#996600;">&quot;bec&quot;</span> theme
    <span style="color:#9966CC; font-weight:bold;">Then</span> I should have a stylesheet named <span style="color:#996600;">&quot;themes/bec/style.css&quot;</span>
    <span style="color:#9966CC; font-weight:bold;">But</span> I should not have any layouts
&nbsp;
  <span style="color:#008000; font-style:italic;"># script/generate theme --app_name=&quot;My New Application&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">Scenario</span>: Generate layout with application name
    <span style="color:#9966CC; font-weight:bold;">Given</span> I have a new rails app
    <span style="color:#9966CC; font-weight:bold;">And</span> I have no layouts
    <span style="color:#9966CC; font-weight:bold;">And</span> I generate a theme with application name <span style="color:#996600;">&quot;My New Application&quot;</span>
    <span style="color:#9966CC; font-weight:bold;">Then</span> the layout <span style="color:#996600;">&quot;application.html.erb&quot;</span> should have <span style="color:#996600;">&quot;My New Application&quot;</span> as page title
&nbsp;
  <span style="color:#008000; font-style:italic;"># script/generate theme --type=sign</span>
  <span style="color:#9966CC; font-weight:bold;">Scenario</span>: Generate layout for signin <span style="color:#9966CC; font-weight:bold;">and</span> signup
    <span style="color:#9966CC; font-weight:bold;">Given</span> I have a new rails app
    <span style="color:#9966CC; font-weight:bold;">And</span> I have no layouts
    <span style="color:#9966CC; font-weight:bold;">And</span> I generate a theme for signin <span style="color:#9966CC; font-weight:bold;">and</span> signup
    <span style="color:#9966CC; font-weight:bold;">Then</span> I should have a layout named <span style="color:#996600;">&quot;sign.html.erb&quot;</span>
    <span style="color:#9966CC; font-weight:bold;">And</span> I should have a layout named <span style="color:#996600;">&quot;sign.html.erb&quot;</span> with just a box</pre></div></div>

<p>Here my steps:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">Given <span style="color:#006600; font-weight:bold;">/</span>^I have a new rails app$<span style="color:#006600; font-weight:bold;">/</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  generate_rails_app
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
Given <span style="color:#006600; font-weight:bold;">/</span>^I have no layouts$<span style="color:#006600; font-weight:bold;">/</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  remove_layouts  
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
Given <span style="color:#006600; font-weight:bold;">/</span>^I have no stylesheets$<span style="color:#006600; font-weight:bold;">/</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  remove_stylesheets
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
Given <span style="color:#006600; font-weight:bold;">/</span>^I generate a theme$<span style="color:#006600; font-weight:bold;">/</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  generate_layout<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:theme</span><span style="color:#006600; font-weight:bold;">&#41;</span>  
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
Given <span style="color:#006600; font-weight:bold;">/</span>^I generate a theme with name <span style="color:#996600;">&quot;([^<span style="color:#000099;">\&quot;</span>]*)&quot;</span>$<span style="color:#006600; font-weight:bold;">/</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>name<span style="color:#006600; font-weight:bold;">|</span>
  generate_layout<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:theme</span>, name<span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
Given <span style="color:#006600; font-weight:bold;">/</span>^I generate a theme choosing the <span style="color:#996600;">&quot;([^<span style="color:#000099;">\&quot;</span>]*)&quot;</span> theme$<span style="color:#006600; font-weight:bold;">/</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>theme_name<span style="color:#006600; font-weight:bold;">|</span>
  generate_layout<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:theme</span>, <span style="color:#ff3333; font-weight:bold;">:theme</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> theme_name<span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">Then</span> <span style="color:#006600; font-weight:bold;">/</span>^I should have a layout named <span style="color:#996600;">&quot;([^<span style="color:#000099;">\&quot;</span>]*)&quot;</span>$<span style="color:#006600; font-weight:bold;">/</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>filename<span style="color:#006600; font-weight:bold;">|</span>
  layout_exists?<span style="color:#006600; font-weight:bold;">&#40;</span>filename<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">should</span> be_true  
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">Then</span> <span style="color:#006600; font-weight:bold;">/</span>^I should have a stylesheet named <span style="color:#996600;">&quot;([^<span style="color:#000099;">\&quot;</span>]*)&quot;</span>$<span style="color:#006600; font-weight:bold;">/</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>filename<span style="color:#006600; font-weight:bold;">|</span>
  stylesheet_exists?<span style="color:#006600; font-weight:bold;">&#40;</span>filename<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">should</span> be_true    
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
Given <span style="color:#006600; font-weight:bold;">/</span>^I generate a theme without layout choosing the <span style="color:#996600;">&quot;([^<span style="color:#000099;">\&quot;</span>]*)&quot;</span> theme$<span style="color:#006600; font-weight:bold;">/</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>theme_name<span style="color:#006600; font-weight:bold;">|</span>
  generate_layout<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:theme</span>, <span style="color:#ff3333; font-weight:bold;">:theme</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> theme_name, <span style="color:#ff3333; font-weight:bold;">:no_layout</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span> <span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">Then</span> <span style="color:#006600; font-weight:bold;">/</span>^I should <span style="color:#9966CC; font-weight:bold;">not</span> have any layouts$<span style="color:#006600; font-weight:bold;">/</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  layouts_count.<span style="color:#9900CC;">should</span> == <span style="color:#006666;">0</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
Given <span style="color:#006600; font-weight:bold;">/</span>^I generate a theme with application name <span style="color:#996600;">&quot;([^<span style="color:#000099;">\&quot;</span>]*)&quot;</span>$<span style="color:#006600; font-weight:bold;">/</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>name<span style="color:#006600; font-weight:bold;">|</span>
  generate_layout<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:theme</span>, <span style="color:#ff3333; font-weight:bold;">:app_name</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> name <span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">Then</span> <span style="color:#006600; font-weight:bold;">/</span>^the layout <span style="color:#996600;">&quot;([^<span style="color:#000099;">\&quot;</span>]*)&quot;</span> should have <span style="color:#996600;">&quot;([^<span style="color:#000099;">\&quot;</span>]*)&quot;</span> as page title$<span style="color:#006600; font-weight:bold;">/</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>layout, title<span style="color:#006600; font-weight:bold;">|</span>
  layout_title<span style="color:#006600; font-weight:bold;">&#40;</span>layout<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">should</span> == title
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
Given <span style="color:#006600; font-weight:bold;">/</span>^I generate a theme <span style="color:#9966CC; font-weight:bold;">for</span> signin <span style="color:#9966CC; font-weight:bold;">and</span> signup$<span style="color:#006600; font-weight:bold;">/</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  generate_layout<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:theme</span>, <span style="color:#ff3333; font-weight:bold;">:layout_type</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:sign</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">Then</span> <span style="color:#006600; font-weight:bold;">/</span>^I should have a layout named <span style="color:#996600;">&quot;([^<span style="color:#000099;">\&quot;</span>]*)&quot;</span> with just a box$<span style="color:#006600; font-weight:bold;">/</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>layout<span style="color:#006600; font-weight:bold;">|</span>
  layout_with_box?<span style="color:#006600; font-weight:bold;">&#40;</span>layout<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">should</span> be_true
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Basically I create a temp folder that I use as fake rails root, and there I launch the generator.  After each feature I remove that folder.</p>
<p>And here my <strong>env.rb</strong></p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">$:.<span style="color:#9900CC;">unshift</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">dirname</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">__FILE__</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">&quot;/../../rails_generators&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">&quot;rubygems&quot;</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">&quot;rails_generator&quot;</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rails_generator/scripts/generate'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">&quot;fileutils&quot;</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">&quot;theme/theme_generator&quot;</span>
&nbsp;
web_app_theme_root  = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">dirname</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">__FILE__</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#996600;">&quot;/../../&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
tmp_rails_app_name  = <span style="color:#996600;">&quot;tmp_rails_app&quot;</span>
tmp_rails_app_root  = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span>web_app_theme_root, tmp_rails_app_name<span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
<span style="color:#6666ff; font-weight:bold;">Rails::<span style="color:#CC00FF; font-weight:bold;">Generator</span>::Base</span>.<span style="color:#9900CC;">append_sources</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#6666ff; font-weight:bold;">Rails::<span style="color:#CC00FF; font-weight:bold;">Generator</span>::PathSource</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:plugin</span>, <span style="color:#996600;">&quot;#{web_app_theme_root}/rails_generators/&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">module</span> GeneratorHelpers
  <span style="color:#9966CC; font-weight:bold;">def</span> generate_rails_app
    <span style="color:#CC00FF; font-weight:bold;">FileUtils</span>.<span style="color:#9900CC;">mkdir</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span>@app_root<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>    
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> remove_layouts
    <span style="color:#CC00FF; font-weight:bold;">FileUtils</span>.<span style="color:#9900CC;">rm_rf</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span>@app_root, <span style="color:#996600;">&quot;app&quot;</span>, <span style="color:#996600;">&quot;views&quot;</span>, <span style="color:#996600;">&quot;layouts&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> remove_stylesheets
    <span style="color:#CC00FF; font-weight:bold;">FileUtils</span>.<span style="color:#9900CC;">rm_rf</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span>@app_root, <span style="color:#996600;">&quot;public&quot;</span>, <span style="color:#996600;">&quot;stylesheets&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> generate_layout<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">*</span>args<span style="color:#006600; font-weight:bold;">&#41;</span>
    options = !args.<span style="color:#9900CC;">empty</span>? <span style="color:#006600; font-weight:bold;">&amp;&amp;</span> args.<span style="color:#9900CC;">last</span>.<span style="color:#9900CC;">is_a</span>?<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">Hash</span><span style="color:#006600; font-weight:bold;">&#41;</span> ? args.<span style="color:#9900CC;">pop</span> : <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span>
    options.<span style="color:#9900CC;">merge</span>!<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#123;</span>:destination <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0066ff; font-weight:bold;">@app_root</span>, <span style="color:#ff3333; font-weight:bold;">:quiet</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>    
    <span style="color:#6666ff; font-weight:bold;">Rails::<span style="color:#CC00FF; font-weight:bold;">Generator</span>::Scripts::Generate</span>.<span style="color:#9900CC;">new</span>.<span style="color:#9900CC;">run</span><span style="color:#006600; font-weight:bold;">&#40;</span>args, options<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> layouts_count
    <span style="color:#CC00FF; font-weight:bold;">Dir</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span>@app_root, <span style="color:#996600;">&quot;app&quot;</span>, <span style="color:#996600;">&quot;views&quot;</span>, <span style="color:#996600;">&quot;layouts&quot;</span>, <span style="color:#996600;">&quot;**&quot;</span>, <span style="color:#996600;">&quot;*.erb&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">size</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> layout_exists?<span style="color:#006600; font-weight:bold;">&#40;</span>filename<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">exists</span>?<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span>@app_root, <span style="color:#996600;">&quot;app&quot;</span>, <span style="color:#996600;">&quot;views&quot;</span>, <span style="color:#996600;">&quot;layouts&quot;</span>, filename<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> stylesheet_exists?<span style="color:#006600; font-weight:bold;">&#40;</span>relative_path<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">exists</span>?<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span>@app_root, <span style="color:#996600;">&quot;public&quot;</span>, <span style="color:#996600;">&quot;stylesheets&quot;</span>, relative_path<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">should</span> be_true
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> layout_title<span style="color:#006600; font-weight:bold;">&#40;</span>layout<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span>@app_root, <span style="color:#996600;">&quot;app&quot;</span>, <span style="color:#996600;">&quot;views&quot;</span>, <span style="color:#996600;">&quot;layouts&quot;</span>, layout<span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#996600;">&quot;r&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">read</span>.<span style="color:#9900CC;">match</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/&lt;</span>title<span style="color:#006600; font-weight:bold;">&gt;</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#91;</span>^<span style="color:#006600; font-weight:bold;">&lt;</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">*</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&lt;</span>\<span style="color:#006600; font-weight:bold;">/</span>title<span style="color:#006600; font-weight:bold;">&gt;/</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> layout_with_box?<span style="color:#006600; font-weight:bold;">&#40;</span>layout<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span>@app_root, <span style="color:#996600;">&quot;app&quot;</span>, <span style="color:#996600;">&quot;views&quot;</span>, <span style="color:#996600;">&quot;layouts&quot;</span>, layout<span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#996600;">&quot;r&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">read</span> =~ <span style="color:#006600; font-weight:bold;">%</span>r<span style="color:#006600; font-weight:bold;">|&lt;</span>div id=<span style="color:#996600;">&quot;box&quot;</span><span style="color:#006600; font-weight:bold;">&gt;|</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
Before <span style="color:#9966CC; font-weight:bold;">do</span>
  <span style="color:#0066ff; font-weight:bold;">@app_root</span> = tmp_rails_app_root  
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
After <span style="color:#9966CC; font-weight:bold;">do</span>
  <span style="color:#CC00FF; font-weight:bold;">FileUtils</span>.<span style="color:#9900CC;">rm_rf</span><span style="color:#006600; font-weight:bold;">&#40;</span>tmp_rails_app_root<span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
World<span style="color:#006600; font-weight:bold;">&#40;</span>GeneratorHelpers<span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>share</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://buzz.yahoo.com/submit?submitUrl=http://gravityblast.com/2009/08/11/testing-rails-generators-with-cucumber/&amp;submitHeadline=Testing+rails+generators+with+Cucumber&amp;submitSummary=" rel="nofollow" title="Add to&nbsp;Buzz"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/buzz.png" title="Add to&nbsp;Buzz" alt="Add to&nbsp;Buzz" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://gravityblast.com/2009/08/11/testing-rails-generators-with-cucumber/&amp;title=Testing+rails+generators+with+Cucumber" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://gravityblast.com/2009/08/11/testing-rails-generators-with-cucumber/&amp;title=Testing+rails+generators+with+Cucumber" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.dzone.com/links/add.html?description=Testing+rails+generators+with+Cucumber&amp;url=http://gravityblast.com/2009/08/11/testing-rails-generators-with-cucumber/&amp;title=Testing+rails+generators+with+Cucumber" rel="nofollow" title="Add to&nbsp;DZone"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/dzone.png" title="Add to&nbsp;DZone" alt="Add to&nbsp;DZone" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://gravityblast.com/2009/08/11/testing-rails-generators-with-cucumber/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://gravityblast.com/2009/08/11/testing-rails-generators-with-cucumber/&amp;title=Testing+rails+generators+with+Cucumber" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http://gravityblast.com/2009/08/11/testing-rails-generators-with-cucumber/&amp;T=Testing+rails+generators+with+Cucumber" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://gravityblast.com/2009/08/11/testing-rails-generators-with-cucumber/&amp;title=Testing+rails+generators+with+Cucumber" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://slashdot.org/bookmark.pl?url=http://gravityblast.com/2009/08/11/testing-rails-generators-with-cucumber/&amp;title=Testing+rails+generators+with+Cucumber" rel="nofollow" title="Add to&nbsp;Slashdot"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/slashdot.png" title="Add to&nbsp;Slashdot" alt="Add to&nbsp;Slashdot" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://gravityblast.com/2009/08/11/testing-rails-generators-with-cucumber/&amp;title=Testing+rails+generators+with+Cucumber" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://gravityblast.com/2009/08/11/testing-rails-generators-with-cucumber/" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://tipd.com/submit.php?url=http://gravityblast.com/2009/08/11/testing-rails-generators-with-cucumber/" rel="nofollow" title="Add to&nbsp;Tip'd"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/tipd.png" title="Add to&nbsp;Tip'd" alt="Add to&nbsp;Tip'd" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Testing+rails+generators+with+Cucumber+@+http://gravityblast.com/2009/08/11/testing-rails-generators-with-cucumber/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://gravityblast.com/2009/08/11/testing-rails-generators-with-cucumber/&amp;t=Testing+rails+generators+with+Cucumber" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://gravityblast.com/2009/08/11/testing-rails-generators-with-cucumber/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>2 minutes admin layout with rails and the web-app-theme generator</title>
		<link>http://gravityblast.com/2009/07/30/2-minutes-admin-layout-with-rails-and-the-web-app-theme-generator/</link>
		<comments>http://gravityblast.com/2009/07/30/2-minutes-admin-layout-with-rails-and-the-web-app-theme-generator/#comments</comments>
		<pubDate>Thu, 30 Jul 2009 14:02:19 +0000</pubDate>
		<dc:creator>Andrea Franz</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://gravityblast.com/?p=257</guid>
		<description><![CDATA[
Many people found out a rails generator inside my web-app-theme project and asked me how to use it.
Here an example, starting from scratch with a new rails app that manages music Albums.


rails cool_albums
cd cool_albums
script/generate scaffold Album name:string artist:string date:date
rake db:migrate

After creating the first controller with a scaffold or with your hands, start creating a theme:

script/plugin [...]]]></description>
			<content:encoded><![CDATA[<p>
Many people found out a rails generator inside my <a href="http://github.com/pilu/web-app-theme">web-app-theme</a> project and asked me how to use it.<br />
Here an example, starting from scratch with a new rails app that manages music Albums.
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">rails cool_albums
<span style="color: #7a0874; font-weight: bold;">cd</span> cool_albums
script<span style="color: #000000; font-weight: bold;">/</span>generate scaffold Album name:string artist:string <span style="color: #c20cb9; font-weight: bold;">date</span>:<span style="color: #c20cb9; font-weight: bold;">date</span>
rake db:migrate</pre></div></div>

<p>After creating the first controller with a scaffold or with your hands, start creating a theme:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">script<span style="color: #000000; font-weight: bold;">/</span>plugin <span style="color: #c20cb9; font-weight: bold;">install</span> git:<span style="color: #000000; font-weight: bold;">//</span>github.com<span style="color: #000000; font-weight: bold;">/</span>pilu<span style="color: #000000; font-weight: bold;">/</span>web-app-theme.git
script<span style="color: #000000; font-weight: bold;">/</span>generate theme application --app_name=<span style="color: #ff0000;">&quot;My Cool Albums&quot;</span> <span style="color: #660033;">--theme</span>=<span style="color: #ff0000;">&quot;drastic-dark&quot;</span></pre></div></div>

<p>The first argument (&#8220;application&#8221;) is the name of the layout that the generator will create (application.html.erb).<br />
The <strong>&#8211;app_name</strong> option specifies the name used as page title, and with the <strong>&#8211;theme</strong> specifies which theme to use among all the <a href="http://pilu.github.com/web-app-theme/" title="Web App Theme Demo">available themes</a> inside the plugin.
</p>
<p>Now remove the default index.html created by rails and the layout created by the scaffold:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">rm</span> app<span style="color: #000000; font-weight: bold;">/</span>views<span style="color: #000000; font-weight: bold;">/</span>layouts<span style="color: #000000; font-weight: bold;">/</span>albums.html.erb 
<span style="color: #c20cb9; font-weight: bold;">rm</span> public<span style="color: #000000; font-weight: bold;">/</span>index.html</pre></div></div>

<p>Add the following line in your <strong>routes.rb</strong> to set the default page of the application:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">map.root :controller =<span style="color: #000000; font-weight: bold;">&gt;</span> :albums</pre></div></div>

<p>Start the server</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">script<span style="color: #000000; font-weight: bold;">/</span>server</pre></div></div>

<p><img src="/wp-content/uploads/2009/07/web-app-theme-example-1.jpg" /></p>
<p>Ok, the layout has been successfully created, but we need to apply a theme for each one of the views generated by the scaffold.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">script<span style="color: #000000; font-weight: bold;">/</span>generate themed albums album <span style="color: #660033;">--layout</span>=application --with_will_paginate</pre></div></div>

<p>
With the first 2 arguments I specified the controller path (albums) and the model used (album).<br />
The <strong>&#8211;layout</strong> options is used by the <strong>themed</strong> generator to know where to add the <strong>Albums</strong> menu link.
</p>
<p>
Since we want to use will paginate (we set the <strong>&#8211;with_will_paginate</strong> option), we need to change one line in our albums controller from:
</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#0066ff; font-weight:bold;">@albums</span> = Album.<span style="color:#9900CC;">all</span></pre></div></div>

<p>to:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#0066ff; font-weight:bold;">@albums</span> = Album.<span style="color:#9900CC;">paginate</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:per_page</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">10</span>, <span style="color:#ff3333; font-weight:bold;">:page</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:page</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>Here a trick to show form error messages inside the auto generated forms, you can add the following lines in your <strong>environment.rb</strong>:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#6666ff; font-weight:bold;">ActionView::Base</span>.<span style="color:#9900CC;">field_error_proc</span> = <span style="color:#CC0066; font-weight:bold;">Proc</span>.<span style="color:#9900CC;">new</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>html_tag, instance<span style="color:#006600; font-weight:bold;">|</span> 
  <span style="color:#9966CC; font-weight:bold;">if</span> html_tag =~ <span style="color:#006600; font-weight:bold;">/&lt;</span>label<span style="color:#006600; font-weight:bold;">/</span>
    <span style="color:#006600; font-weight:bold;">%|&lt;</span>div <span style="color:#9966CC; font-weight:bold;">class</span>=<span style="color:#996600;">&quot;fieldWithErrors&quot;</span><span style="color:#006600; font-weight:bold;">&gt;</span><span style="color:#008000; font-style:italic;">#{html_tag} &lt;span class=&quot;error&quot;&gt;#{[instance.error_message].join(', ')}&lt;/span&gt;&lt;/div&gt;|</span>
  <span style="color:#9966CC; font-weight:bold;">else</span>
    html_tag
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Ok, restart your server and you are done.</p>
<p><img src="/wp-content/uploads/2009/07/web-app-theme-example-2.jpg" /></p>
<p>Feel free to fork the project from <a href="http://github.com/pilu/web-app-theme/tree/master">github</a> to improve the generator or to add a new theme.</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>share</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://buzz.yahoo.com/submit?submitUrl=http://gravityblast.com/2009/07/30/2-minutes-admin-layout-with-rails-and-the-web-app-theme-generator/&amp;submitHeadline=2+minutes+admin+layout+with+rails+and+the+web-app-theme+generator&amp;submitSummary=" rel="nofollow" title="Add to&nbsp;Buzz"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/buzz.png" title="Add to&nbsp;Buzz" alt="Add to&nbsp;Buzz" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://gravityblast.com/2009/07/30/2-minutes-admin-layout-with-rails-and-the-web-app-theme-generator/&amp;title=2+minutes+admin+layout+with+rails+and+the+web-app-theme+generator" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://gravityblast.com/2009/07/30/2-minutes-admin-layout-with-rails-and-the-web-app-theme-generator/&amp;title=2+minutes+admin+layout+with+rails+and+the+web-app-theme+generator" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.dzone.com/links/add.html?description=2+minutes+admin+layout+with+rails+and+the+web-app-theme+generator&amp;url=http://gravityblast.com/2009/07/30/2-minutes-admin-layout-with-rails-and-the-web-app-theme-generator/&amp;title=2+minutes+admin+layout+with+rails+and+the+web-app-theme+generator" rel="nofollow" title="Add to&nbsp;DZone"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/dzone.png" title="Add to&nbsp;DZone" alt="Add to&nbsp;DZone" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://gravityblast.com/2009/07/30/2-minutes-admin-layout-with-rails-and-the-web-app-theme-generator/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://gravityblast.com/2009/07/30/2-minutes-admin-layout-with-rails-and-the-web-app-theme-generator/&amp;title=2+minutes+admin+layout+with+rails+and+the+web-app-theme+generator" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http://gravityblast.com/2009/07/30/2-minutes-admin-layout-with-rails-and-the-web-app-theme-generator/&amp;T=2+minutes+admin+layout+with+rails+and+the+web-app-theme+generator" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://gravityblast.com/2009/07/30/2-minutes-admin-layout-with-rails-and-the-web-app-theme-generator/&amp;title=2+minutes+admin+layout+with+rails+and+the+web-app-theme+generator" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://slashdot.org/bookmark.pl?url=http://gravityblast.com/2009/07/30/2-minutes-admin-layout-with-rails-and-the-web-app-theme-generator/&amp;title=2+minutes+admin+layout+with+rails+and+the+web-app-theme+generator" rel="nofollow" title="Add to&nbsp;Slashdot"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/slashdot.png" title="Add to&nbsp;Slashdot" alt="Add to&nbsp;Slashdot" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://gravityblast.com/2009/07/30/2-minutes-admin-layout-with-rails-and-the-web-app-theme-generator/&amp;title=2+minutes+admin+layout+with+rails+and+the+web-app-theme+generator" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://gravityblast.com/2009/07/30/2-minutes-admin-layout-with-rails-and-the-web-app-theme-generator/" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://tipd.com/submit.php?url=http://gravityblast.com/2009/07/30/2-minutes-admin-layout-with-rails-and-the-web-app-theme-generator/" rel="nofollow" title="Add to&nbsp;Tip'd"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/tipd.png" title="Add to&nbsp;Tip'd" alt="Add to&nbsp;Tip'd" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+2+minutes+admin+layout+with+rails+and+the+web-app-theme+generator+@+http://gravityblast.com/2009/07/30/2-minutes-admin-layout-with-rails-and-the-web-app-theme-generator/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://gravityblast.com/2009/07/30/2-minutes-admin-layout-with-rails-and-the-web-app-theme-generator/&amp;t=2+minutes+admin+layout+with+rails+and+the+web-app-theme+generator" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://gravityblast.com/2009/07/30/2-minutes-admin-layout-with-rails-and-the-web-app-theme-generator/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>Creating PDF with images using flex and AlivePDF</title>
		<link>http://gravityblast.com/2009/07/19/creating-pdf-with-images-using-flex-and-alivepdf/</link>
		<comments>http://gravityblast.com/2009/07/19/creating-pdf-with-images-using-flex-and-alivepdf/#comments</comments>
		<pubDate>Sun, 19 Jul 2009 00:25:39 +0000</pubDate>
		<dc:creator>Andrea Franz</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://gravityblast.com/?p=216</guid>
		<description><![CDATA[
Today I&#8217;m working on an AIR application, and I need to create a PDF starting from a list of images. This PDF needs to have one image for each page. I used AlivePDF, a very useful ActionScript3 library for PDF generation, and I created a simple class that takes an array of image paths and [...]]]></description>
			<content:encoded><![CDATA[<p>
Today I&#8217;m working on an AIR application, and I need to create a PDF starting from a list of images. This PDF needs to have one image for each page. I used<a href="http://alivepdf.bytearray.org/" title="AlivePDF"> AlivePDF</a>, a very useful ActionScript3 library for PDF generation, and I created a simple class that takes an array of image paths and creates the PDF I need.
</p>
<p>Here the class I use:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package
<span style="color: #66cc66;">&#123;</span>	
  <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;
  <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">EventDispatcher</span>;
  <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">filesystem</span>.<span style="color: #006600;">File</span>;
  <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">filesystem</span>.<span style="color: #006600;">FileMode</span>;
  <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">filesystem</span>.<span style="color: #006600;">FileStream</span>;
  <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">net</span>.<span style="color: #006600;">URLLoader</span>;
  <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">net</span>.<span style="color: #006600;">URLLoaderDataFormat</span>;
  <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">net</span>.<span style="color: #006600;">URLRequest</span>;
  <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">utils</span>.<span style="color: #006600;">ByteArray</span>;
&nbsp;
  <span style="color: #0066CC;">import</span> org.<span style="color: #006600;">alivepdf</span>.<span style="color: #006600;">pdf</span>.<span style="color: #006600;">PDF</span>;	
  <span style="color: #0066CC;">import</span> org.<span style="color: #006600;">alivepdf</span>.<span style="color: #006600;">display</span>.<span style="color: #006600;">Display</span>;
  <span style="color: #0066CC;">import</span> org.<span style="color: #006600;">alivepdf</span>.<span style="color: #006600;">images</span>.<span style="color: #006600;">ResizeMode</span>;
  <span style="color: #0066CC;">import</span> org.<span style="color: #006600;">alivepdf</span>.<span style="color: #006600;">layout</span>.<span style="color: #006600;">Layout</span>;
  <span style="color: #0066CC;">import</span> org.<span style="color: #006600;">alivepdf</span>.<span style="color: #006600;">layout</span>.<span style="color: #006600;">Orientation</span>;
  <span style="color: #0066CC;">import</span> org.<span style="color: #006600;">alivepdf</span>.<span style="color: #006600;">layout</span>.<span style="color: #0066CC;">Size</span>;
  <span style="color: #0066CC;">import</span> org.<span style="color: #006600;">alivepdf</span>.<span style="color: #006600;">layout</span>.<span style="color: #006600;">Unit</span>;
  <span style="color: #0066CC;">import</span> org.<span style="color: #006600;">alivepdf</span>.<span style="color: #006600;">saving</span>.<span style="color: #006600;">Method</span>;
&nbsp;
  <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> PdfGenerator <span style="color: #0066CC;">extends</span> EventDispatcher
  <span style="color: #66cc66;">&#123;</span>		  
    <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> pdf:PDF;
    <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> images:<span style="color: #0066CC;">Array</span>;		
    <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> outFilePath:<span style="color: #0066CC;">String</span>;
    <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> completedPages:<span style="color: #0066CC;">int</span>;
&nbsp;
    <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> PdfGenerator<span style="color: #66cc66;">&#40;</span>images:<span style="color: #0066CC;">Array</span>, outFilePath:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#123;</span>
      <span style="color: #0066CC;">this</span>.<span style="color: #006600;">outFilePath</span> = outFilePath;
      <span style="color: #0066CC;">this</span>.<span style="color: #006600;">images</span> = images;
    <span style="color: #66cc66;">&#125;</span>				
&nbsp;
    <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> generate<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
    <span style="color: #66cc66;">&#123;</span>						
      <span style="color: #0066CC;">this</span>.<span style="color: #006600;">completedPages</span> = <span style="color: #cc66cc;">0</span>;
      <span style="color: #0066CC;">this</span>.<span style="color: #006600;">pdf</span> = <span style="color: #000000; font-weight: bold;">new</span> PDF<span style="color: #66cc66;">&#40;</span>Orientation.<span style="color: #006600;">LANDSCAPE</span>, Unit.<span style="color: #006600;">MM</span>, <span style="color: #0066CC;">Size</span>.<span style="color: #006600;">A4</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #0066CC;">this</span>.<span style="color: #006600;">nextPage</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;		
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> nextPage<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
    <span style="color: #66cc66;">&#123;</span>
      <span style="color: #0066CC;">this</span>.<span style="color: #006600;">completedPages</span> <span style="color: #66cc66;">&lt;</span> <span style="color: #0066CC;">this</span>.<span style="color: #006600;">images</span>.<span style="color: #0066CC;">length</span> ? <span style="color: #0066CC;">this</span>.<span style="color: #006600;">loadImage</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>.<span style="color: #006600;">images</span><span style="color: #66cc66;">&#91;</span><span style="color: #0066CC;">this</span>.<span style="color: #006600;">completedPages</span>++<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">this</span>.<span style="color: #006600;">save</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> loadImage<span style="color: #66cc66;">&#40;</span>path:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
    <span style="color: #66cc66;">&#123;</span>						
      <span style="color: #000000; font-weight: bold;">var</span> urlLoader:URLLoader = <span style="color: #000000; font-weight: bold;">new</span> URLLoader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;			
      urlLoader.<span style="color: #006600;">dataFormat</span> = URLLoaderDataFormat.<span style="color: #006600;">BINARY</span>;
      urlLoader.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">COMPLETE</span>, <span style="color: #0066CC;">this</span>.<span style="color: #006600;">onImageLoadComplete</span><span style="color: #66cc66;">&#41;</span>;
      urlLoader.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #66cc66;">&#40;</span>path<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;						
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> onImageLoadComplete<span style="color: #66cc66;">&#40;</span>event:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
    <span style="color: #66cc66;">&#123;</span>						
      <span style="color: #0066CC;">this</span>.<span style="color: #006600;">pdf</span>.<span style="color: #0066CC;">addPage</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #0066CC;">this</span>.<span style="color: #006600;">pdf</span>.<span style="color: #006600;">addImageStream</span><span style="color: #66cc66;">&#40;</span>ByteArray<span style="color: #66cc66;">&#40;</span>event.<span style="color: #0066CC;">target</span>.<span style="color: #0066CC;">data</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">1</span>, ResizeMode.<span style="color: #006600;">FIT_TO_PAGE</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #0066CC;">this</span>.<span style="color: #006600;">dispatchEvent</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> PdfGeneratorEvent<span style="color: #66cc66;">&#40;</span>PdfGeneratorEvent.<span style="color: #006600;">PDF_GENERATOR_PAGE_COMPLETE</span>, <span style="color: #000000; font-weight: bold;">false</span>, <span style="color: #000000; font-weight: bold;">false</span>, <span style="color: #0066CC;">this</span>.<span style="color: #006600;">images</span>.<span style="color: #0066CC;">length</span>, <span style="color: #0066CC;">this</span>.<span style="color: #006600;">completedPages</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #0066CC;">this</span>.<span style="color: #006600;">nextPage</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> save<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
    <span style="color: #66cc66;">&#123;</span>				
      <span style="color: #0066CC;">this</span>.<span style="color: #006600;">pdf</span>.<span style="color: #0066CC;">end</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #0066CC;">this</span>.<span style="color: #006600;">writeOutFile</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;												
      <span style="color: #0066CC;">this</span>.<span style="color: #006600;">dispatchEvent</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> PdfGeneratorEvent<span style="color: #66cc66;">&#40;</span>PdfGeneratorEvent.<span style="color: #006600;">PDF_GENERATOR_COMPLETE</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> writeOutFile<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
    <span style="color: #66cc66;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">var</span> fileStream:FileStream = <span style="color: #000000; font-weight: bold;">new</span> FileStream<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;								
      fileStream.<span style="color: #006600;">open</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> File<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>.<span style="color: #006600;">outFilePath</span><span style="color: #66cc66;">&#41;</span>, FileMode.<span style="color: #006600;">WRITE</span><span style="color: #66cc66;">&#41;</span>;			
      fileStream.<span style="color: #006600;">writeBytes</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>.<span style="color: #006600;">pdf</span>.<span style="color: #006600;">save</span><span style="color: #66cc66;">&#40;</span>Method.<span style="color: #006600;">LOCAL</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
      fileStream.<span style="color: #0066CC;">close</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
  <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Basically for each image it creates a new URLRequest and when the request is completed it adds a new page with the image. As you can see I also dispatch a custom Event called PdfGeneratorEvent. That because I need to create a PDF with a large number of images, and doing like this I can give a feedback to the user with a ProgressBar that display the generation progress.
</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package
<span style="color: #66cc66;">&#123;</span>
  <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;
&nbsp;
  <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> PdfGeneratorEvent <span style="color: #0066CC;">extends</span> Event
  <span style="color: #66cc66;">&#123;</span>			
    <span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> const PDF_GENERATOR_PAGE_COMPLETE:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;PDF_GENERATOR_PAGE_COMPLETE&quot;</span>;
    <span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> const PDF_GENERATOR_COMPLETE:<span style="color: #0066CC;">String</span>      = <span style="color: #ff0000;">&quot;PDF_GENERATOR_COMPLETE&quot;</span>;			
&nbsp;
    <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> totalPages:<span style="color: #0066CC;">int</span>;
    <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> completedPages:<span style="color: #0066CC;">int</span>;
&nbsp;
    <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> PdfGeneratorEvent<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">type</span>:<span style="color: #0066CC;">String</span>, bubbles:<span style="color: #0066CC;">Boolean</span>=<span style="color: #000000; font-weight: bold;">false</span>, cancelable:<span style="color: #0066CC;">Boolean</span>=<span style="color: #000000; font-weight: bold;">false</span>, totalPages:<span style="color: #0066CC;">int</span>=<span style="color: #cc66cc;">0</span>, completedPages:<span style="color: #0066CC;">int</span>=<span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#123;</span>			
      <span style="color: #0066CC;">super</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">type</span>, bubbles, cancelable<span style="color: #66cc66;">&#41;</span>;
      <span style="color: #0066CC;">this</span>.<span style="color: #006600;">totalPages</span>     = totalPages;
      <span style="color: #0066CC;">this</span>.<span style="color: #006600;">completedPages</span> = completedPages;
    <span style="color: #66cc66;">&#125;</span>
  <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>And here the main file that uses this class:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> createPdf<span style="color: #66cc66;">&#40;</span>images:<span style="color: #0066CC;">Array</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">var</span> generator:PdfGenerator = <span style="color: #000000; font-weight: bold;">new</span> PdfGenerator<span style="color: #66cc66;">&#40;</span>images, <span style="color: #ff0000;">&quot;/path/to/my/test.pdf&quot;</span><span style="color: #66cc66;">&#41;</span>;
  generator.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>PdfGeneratorEvent.<span style="color: #006600;">PDF_GENERATOR_COMPLETE</span>, <span style="color: #0066CC;">this</span>.<span style="color: #006600;">onPdfComplete</span><span style="color: #66cc66;">&#41;</span>;
  generator.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>PdfGeneratorEvent.<span style="color: #006600;">PDF_GENERATOR_PAGE_COMPLETE</span>, <span style="color: #0066CC;">this</span>.<span style="color: #006600;">onPdfPageComplete</span><span style="color: #66cc66;">&#41;</span>;				
  generator.<span style="color: #006600;">generate</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;				
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> onPdfPageComplete<span style="color: #66cc66;">&#40;</span>event:PdfGeneratorEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>					
  progressBar.<span style="color: #006600;">setProgress</span><span style="color: #66cc66;">&#40;</span>event.<span style="color: #006600;">completedPages</span>, event.<span style="color: #006600;">totalPages</span><span style="color: #66cc66;">&#41;</span>;
  progressBar.<span style="color: #006600;">label</span> = event.<span style="color: #006600;">completedPages</span> + <span style="color: #ff0000;">&quot; of &quot;</span> + event.<span style="color: #006600;">totalPages</span>;															
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> onPdfComplete<span style="color: #66cc66;">&#40;</span>event:PdfGeneratorEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>											
  <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;completed&quot;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>share</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://buzz.yahoo.com/submit?submitUrl=http://gravityblast.com/2009/07/19/creating-pdf-with-images-using-flex-and-alivepdf/&amp;submitHeadline=Creating+PDF+with+images+using+flex+and+AlivePDF&amp;submitSummary=" rel="nofollow" title="Add to&nbsp;Buzz"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/buzz.png" title="Add to&nbsp;Buzz" alt="Add to&nbsp;Buzz" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://gravityblast.com/2009/07/19/creating-pdf-with-images-using-flex-and-alivepdf/&amp;title=Creating+PDF+with+images+using+flex+and+AlivePDF" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://gravityblast.com/2009/07/19/creating-pdf-with-images-using-flex-and-alivepdf/&amp;title=Creating+PDF+with+images+using+flex+and+AlivePDF" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.dzone.com/links/add.html?description=Creating+PDF+with+images+using+flex+and+AlivePDF&amp;url=http://gravityblast.com/2009/07/19/creating-pdf-with-images-using-flex-and-alivepdf/&amp;title=Creating+PDF+with+images+using+flex+and+AlivePDF" rel="nofollow" title="Add to&nbsp;DZone"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/dzone.png" title="Add to&nbsp;DZone" alt="Add to&nbsp;DZone" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://gravityblast.com/2009/07/19/creating-pdf-with-images-using-flex-and-alivepdf/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://gravityblast.com/2009/07/19/creating-pdf-with-images-using-flex-and-alivepdf/&amp;title=Creating+PDF+with+images+using+flex+and+AlivePDF" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http://gravityblast.com/2009/07/19/creating-pdf-with-images-using-flex-and-alivepdf/&amp;T=Creating+PDF+with+images+using+flex+and+AlivePDF" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://gravityblast.com/2009/07/19/creating-pdf-with-images-using-flex-and-alivepdf/&amp;title=Creating+PDF+with+images+using+flex+and+AlivePDF" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://slashdot.org/bookmark.pl?url=http://gravityblast.com/2009/07/19/creating-pdf-with-images-using-flex-and-alivepdf/&amp;title=Creating+PDF+with+images+using+flex+and+AlivePDF" rel="nofollow" title="Add to&nbsp;Slashdot"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/slashdot.png" title="Add to&nbsp;Slashdot" alt="Add to&nbsp;Slashdot" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://gravityblast.com/2009/07/19/creating-pdf-with-images-using-flex-and-alivepdf/&amp;title=Creating+PDF+with+images+using+flex+and+AlivePDF" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://gravityblast.com/2009/07/19/creating-pdf-with-images-using-flex-and-alivepdf/" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://tipd.com/submit.php?url=http://gravityblast.com/2009/07/19/creating-pdf-with-images-using-flex-and-alivepdf/" rel="nofollow" title="Add to&nbsp;Tip'd"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/tipd.png" title="Add to&nbsp;Tip'd" alt="Add to&nbsp;Tip'd" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Creating+PDF+with+images+using+flex+and+AlivePDF+@+http://gravityblast.com/2009/07/19/creating-pdf-with-images-using-flex-and-alivepdf/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://gravityblast.com/2009/07/19/creating-pdf-with-images-using-flex-and-alivepdf/&amp;t=Creating+PDF+with+images+using+flex+and+AlivePDF" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://gravityblast.com/2009/07/19/creating-pdf-with-images-using-flex-and-alivepdf/feed/</wfw:commentRss>
		<slash:comments>35</slash:comments>
		</item>
		<item>
		<title>Mask problem with flex canvas and drag &amp; drop</title>
		<link>http://gravityblast.com/2009/07/12/mask-problem-with-flex-canvas-and-drag-drop/</link>
		<comments>http://gravityblast.com/2009/07/12/mask-problem-with-flex-canvas-and-drag-drop/#comments</comments>
		<pubDate>Sun, 12 Jul 2009 23:34:37 +0000</pubDate>
		<dc:creator>Andrea Franz</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[RIA]]></category>

		<guid isPermaLink="false">http://gravityblast.com/?p=170</guid>
		<description><![CDATA[Some weeks ago a spent a lot of time trying to fix a bug inside an AIR application I was working on.
I wrote a custom component that has an image as child. This image is draggable, and the container should act as a mask. The problem was that when I started dragging the picture, the [...]]]></description>
			<content:encoded><![CDATA[<p>Some weeks ago a spent a lot of time trying to fix a bug inside an AIR application I was working on.<br />
I wrote a custom component that has an image as child. This image is draggable, and the container should act as a mask. The problem was that when I started dragging the picture, the picture went outside its container, like the following example. </p>
<p>Try dragging the red square outside the white one:</p>
<p>
<object width="500" height="300">
<param name="movie" value="/wp-content/uploads/2009/07/dragdropcanvas1.swf"></param>
<param name="quality" value="high"></param>
<param name="wmode" value="window"></param>
<param name="menu" value="false"></param>
<param name="bgcolor" value="#FFFFFF"></param>
<embed type="application/x-shockwave-flash" width="500" height="300" src="/wp-content/uploads/2009/07/dragdropcanvas1.swf" quality="high" bgcolor="#FFFFFF" wmode="window" menu="false" ></embed>
</object>
</p>
<p>I fixed this bug just setting the scrollRect property to the container:</p>
<p>
<object width="500" height="300">
<param name="movie" value="/wp-content/uploads/2009/07/dragdropcanvas2.swf"></param>
<param name="quality" value="high"></param>
<param name="wmode" value="window"></param>
<param name="menu" value="false"></param>
<param name="bgcolor" value="#FFFFFF"></param>
<embed type="application/x-shockwave-flash" width="500" height="300" src="/wp-content/uploads/2009/07/dragdropcanvas2.swf" quality="high" bgcolor="#FFFFFF" wmode="window" menu="false" ></embed>
</object>
</p>
<p>Only when I realized how to fix the bug I found <a href="http://www.alterlogic.co.uk/blog/2009/1/20/flex-component-clipcontent-problems-and-mask-gotchas.html">another guy</a> with the same problem and the same solution.</p>
<p>Here the code:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&lt;</span>?<span style="color: #0066CC;">xml</span> <span style="color: #0066CC;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;</span>mx:Application <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;500&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;300&quot;</span> xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> 
  layout=<span style="color: #ff0000;">&quot;vertical&quot;</span> verticalAlign=<span style="color: #ff0000;">&quot;middle&quot;</span> horizontalAlign=<span style="color: #ff0000;">&quot;center&quot;</span>
  applicationComplete=<span style="color: #ff0000;">&quot;init()&quot;</span><span style="color: #66cc66;">&gt;</span>
  <span style="color: #66cc66;">&lt;</span>mx:Script<span style="color: #66cc66;">&gt;</span>
    <span style="color: #66cc66;">&lt;!</span><span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span>												
      <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
      <span style="color: #66cc66;">&#123;</span>				
        <span style="color: #0066CC;">this</span>.<span style="color: #006600;">container</span>.<span style="color: #006600;">scrollRect</span> = <span style="color: #000000; font-weight: bold;">new</span> Rectangle<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #0066CC;">this</span>.<span style="color: #006600;">container</span>.<span style="color: #0066CC;">width</span>, <span style="color: #0066CC;">this</span>.<span style="color: #006600;">container</span>.<span style="color: #0066CC;">height</span><span style="color: #66cc66;">&#41;</span>;																
        <span style="color: #0066CC;">this</span>.<span style="color: #006600;">draggableCanvas</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_UP</span>, <span style="color: #0066CC;">this</span>.<span style="color: #006600;">mouseUpHandler</span><span style="color: #66cc66;">&#41;</span>;				
        <span style="color: #0066CC;">this</span>.<span style="color: #006600;">draggableCanvas</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_DOWN</span>, <span style="color: #0066CC;">this</span>.<span style="color: #006600;">mouseDownHandler</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #66cc66;">&#125;</span>			
&nbsp;
      <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> mouseDownHandler<span style="color: #66cc66;">&#40;</span>event:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
      <span style="color: #66cc66;">&#123;</span>
        <span style="color: #0066CC;">this</span>.<span style="color: #006600;">draggableCanvas</span>.<span style="color: #0066CC;">startDrag</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #66cc66;">&#125;</span>
&nbsp;
      <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> mouseUpHandler<span style="color: #66cc66;">&#40;</span>event:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
      <span style="color: #66cc66;">&#123;</span>
        <span style="color: #0066CC;">this</span>.<span style="color: #006600;">draggableCanvas</span>.<span style="color: #0066CC;">stopDrag</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>
    <span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&gt;</span>
  <span style="color: #66cc66;">&lt;/</span>mx:Script<span style="color: #66cc66;">&gt;</span>
  <span style="color: #66cc66;">&lt;</span>mx:Canvas id=<span style="color: #ff0000;">&quot;container&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;300&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;250&quot;</span> <span style="color: #0066CC;">backgroundColor</span>=<span style="color: #ff0000;">&quot;white&quot;</span> horizontalScrollPolicy=<span style="color: #ff0000;">&quot;off&quot;</span> verticalScrollPolicy=<span style="color: #ff0000;">&quot;off&quot;</span><span style="color: #66cc66;">&gt;</span>
    <span style="color: #66cc66;">&lt;</span>mx:Canvas id=<span style="color: #ff0000;">&quot;draggableCanvas&quot;</span> x=<span style="color: #ff0000;">&quot;50&quot;</span> y=<span style="color: #ff0000;">&quot;25&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;200&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;200&quot;</span> <span style="color: #0066CC;">backgroundColor</span>=<span style="color: #ff0000;">&quot;#AA0000&quot;</span><span style="color: #66cc66;">&gt;</span>			
    <span style="color: #66cc66;">&lt;/</span>mx:Canvas<span style="color: #66cc66;">&gt;</span>
  <span style="color: #66cc66;">&lt;/</span>mx:Canvas<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;/</span>mx:Application<span style="color: #66cc66;">&gt;</span></pre></div></div>

<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>share</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://buzz.yahoo.com/submit?submitUrl=http://gravityblast.com/2009/07/12/mask-problem-with-flex-canvas-and-drag-drop/&amp;submitHeadline=Mask+problem+with+flex+canvas+and+drag+%26%23038%3B+drop&amp;submitSummary=" rel="nofollow" title="Add to&nbsp;Buzz"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/buzz.png" title="Add to&nbsp;Buzz" alt="Add to&nbsp;Buzz" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://gravityblast.com/2009/07/12/mask-problem-with-flex-canvas-and-drag-drop/&amp;title=Mask+problem+with+flex+canvas+and+drag+%26%23038%3B+drop" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://gravityblast.com/2009/07/12/mask-problem-with-flex-canvas-and-drag-drop/&amp;title=Mask+problem+with+flex+canvas+and+drag+%26%23038%3B+drop" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.dzone.com/links/add.html?description=Mask+problem+with+flex+canvas+and+drag+%26%23038%3B+drop&amp;url=http://gravityblast.com/2009/07/12/mask-problem-with-flex-canvas-and-drag-drop/&amp;title=Mask+problem+with+flex+canvas+and+drag+%26%23038%3B+drop" rel="nofollow" title="Add to&nbsp;DZone"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/dzone.png" title="Add to&nbsp;DZone" alt="Add to&nbsp;DZone" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://gravityblast.com/2009/07/12/mask-problem-with-flex-canvas-and-drag-drop/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://gravityblast.com/2009/07/12/mask-problem-with-flex-canvas-and-drag-drop/&amp;title=Mask+problem+with+flex+canvas+and+drag+%26%23038%3B+drop" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http://gravityblast.com/2009/07/12/mask-problem-with-flex-canvas-and-drag-drop/&amp;T=Mask+problem+with+flex+canvas+and+drag+%26%23038%3B+drop" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://gravityblast.com/2009/07/12/mask-problem-with-flex-canvas-and-drag-drop/&amp;title=Mask+problem+with+flex+canvas+and+drag+%26%23038%3B+drop" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://slashdot.org/bookmark.pl?url=http://gravityblast.com/2009/07/12/mask-problem-with-flex-canvas-and-drag-drop/&amp;title=Mask+problem+with+flex+canvas+and+drag+%26%23038%3B+drop" rel="nofollow" title="Add to&nbsp;Slashdot"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/slashdot.png" title="Add to&nbsp;Slashdot" alt="Add to&nbsp;Slashdot" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://gravityblast.com/2009/07/12/mask-problem-with-flex-canvas-and-drag-drop/&amp;title=Mask+problem+with+flex+canvas+and+drag+%26%23038%3B+drop" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://gravityblast.com/2009/07/12/mask-problem-with-flex-canvas-and-drag-drop/" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://tipd.com/submit.php?url=http://gravityblast.com/2009/07/12/mask-problem-with-flex-canvas-and-drag-drop/" rel="nofollow" title="Add to&nbsp;Tip'd"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/tipd.png" title="Add to&nbsp;Tip'd" alt="Add to&nbsp;Tip'd" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Mask+problem+with+flex+canvas+and+drag+%26%23038%3B+drop+@+http://gravityblast.com/2009/07/12/mask-problem-with-flex-canvas-and-drag-drop/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://gravityblast.com/2009/07/12/mask-problem-with-flex-canvas-and-drag-drop/&amp;t=Mask+problem+with+flex+canvas+and+drag+%26%23038%3B+drop" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://gravityblast.com/2009/07/12/mask-problem-with-flex-canvas-and-drag-drop/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>2 things I like in prototype 1.6.1</title>
		<link>http://gravityblast.com/2009/03/31/2-things-i-like-in-prototype-161/</link>
		<comments>http://gravityblast.com/2009/03/31/2-things-i-like-in-prototype-161/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 13:11:02 +0000</pubDate>
		<dc:creator>Andrea Franz</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[prototype]]></category>

		<guid isPermaLink="false">http://gravityblast.com/?p=132</guid>
		<description><![CDATA[
The stable version of prototype is  1.6.0.3. I just fiddled around with the edge version (1.6.1_rc2) and I found 2 new features I really like. The first one is the Element#clone method. At last I can easily clone an element,  or make a deep clone of it passing true as first argument:


&#60;div id=&#34;genres&#34;&#62;
 [...]]]></description>
			<content:encoded><![CDATA[<p>
The stable version of <a href="http://www.prototypejs.org/">prototype</a> is  1.6.0.3. I just fiddled around with the edge version (<a href="http://prototypejs.org/assets/2009/3/27/prototype.js">1.6.1_rc2</a>) and I found 2 new features I really like. The first one is the Element#clone method. At last I can easily clone an element,  or make a deep clone of it passing true as first argument:
</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;genres&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;genre&quot;</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">select</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;genre[]&quot;</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span>&gt;</span>Your favorite genre...<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span>&gt;</span>Death Metal<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span>&gt;</span>Black Metal<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span>&gt;</span>Speed Metal<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">select</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;add-genre&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>Add<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">document.<span style="color: #660066;">observe</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;dom:loaded&quot;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;add-genre&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">observe</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;click&quot;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    event.<span style="color: #000066;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> genres <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;genres&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
    genres.<span style="color: #660066;">insert</span><span style="color: #009900;">&#40;</span>genres.<span style="color: #660066;">down</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.genre&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">clone</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Just click the <strong>Add</strong> link to add a new the select tag.</p>
<p>Another cool new feature is the <a href="http://prototypejs.org/2009/2/16/pimp-my-code-1-element-storage">Element Storage</a>. You can store any kind of data inside a element, and retrieve it when you need it.</p>
<p>Here an example:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;items&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;item&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;item-1&quot;</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h1</span>&gt;</span>Item 1<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h1</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;save&quot;</span>&gt;</span>Save<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;item&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;item-2&quot;</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h1</span>&gt;</span>Item 2<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h1</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;save&quot;</span>&gt;</span>Save<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">document.<span style="color: #660066;">observe</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;dom:loaded&quot;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #003366; font-weight: bold;">var</span> <span style="color: #000066; font-weight: bold;">item</span> <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;item-1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #003366; font-weight: bold;">var</span> data <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">item</span>.<span style="color: #660066;">retrieve</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;data&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  data.<span style="color: #660066;">url</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;http://cowboys.from.hell/items/1&quot;</span><span style="color: #339933;">;</span>			
&nbsp;
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;items&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">select</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;a.save&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">invoke</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;observe&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;click&quot;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>event.<span style="color: #660066;">target</span>.<span style="color: #660066;">up</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.item&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">retrieve</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;data&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Just click the first <strong>save</strong> link and an alert will display the url I previously stored inside the first item element.</p>
<p>Given what I&#8217;m seeing I&#8217;m pretty excited about the upcoming version of prototype.</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>share</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://buzz.yahoo.com/submit?submitUrl=http://gravityblast.com/2009/03/31/2-things-i-like-in-prototype-161/&amp;submitHeadline=2+things+I+like+in+prototype+1.6.1&amp;submitSummary=" rel="nofollow" title="Add to&nbsp;Buzz"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/buzz.png" title="Add to&nbsp;Buzz" alt="Add to&nbsp;Buzz" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://gravityblast.com/2009/03/31/2-things-i-like-in-prototype-161/&amp;title=2+things+I+like+in+prototype+1.6.1" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://gravityblast.com/2009/03/31/2-things-i-like-in-prototype-161/&amp;title=2+things+I+like+in+prototype+1.6.1" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.dzone.com/links/add.html?description=2+things+I+like+in+prototype+1.6.1&amp;url=http://gravityblast.com/2009/03/31/2-things-i-like-in-prototype-161/&amp;title=2+things+I+like+in+prototype+1.6.1" rel="nofollow" title="Add to&nbsp;DZone"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/dzone.png" title="Add to&nbsp;DZone" alt="Add to&nbsp;DZone" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://gravityblast.com/2009/03/31/2-things-i-like-in-prototype-161/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://gravityblast.com/2009/03/31/2-things-i-like-in-prototype-161/&amp;title=2+things+I+like+in+prototype+1.6.1" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http://gravityblast.com/2009/03/31/2-things-i-like-in-prototype-161/&amp;T=2+things+I+like+in+prototype+1.6.1" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://gravityblast.com/2009/03/31/2-things-i-like-in-prototype-161/&amp;title=2+things+I+like+in+prototype+1.6.1" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://slashdot.org/bookmark.pl?url=http://gravityblast.com/2009/03/31/2-things-i-like-in-prototype-161/&amp;title=2+things+I+like+in+prototype+1.6.1" rel="nofollow" title="Add to&nbsp;Slashdot"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/slashdot.png" title="Add to&nbsp;Slashdot" alt="Add to&nbsp;Slashdot" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://gravityblast.com/2009/03/31/2-things-i-like-in-prototype-161/&amp;title=2+things+I+like+in+prototype+1.6.1" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://gravityblast.com/2009/03/31/2-things-i-like-in-prototype-161/" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://tipd.com/submit.php?url=http://gravityblast.com/2009/03/31/2-things-i-like-in-prototype-161/" rel="nofollow" title="Add to&nbsp;Tip'd"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/tipd.png" title="Add to&nbsp;Tip'd" alt="Add to&nbsp;Tip'd" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+2+things+I+like+in+prototype+1.6.1+@+http://gravityblast.com/2009/03/31/2-things-i-like-in-prototype-161/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://gravityblast.com/2009/03/31/2-things-i-like-in-prototype-161/&amp;t=2+things+I+like+in+prototype+1.6.1" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://gravityblast.com/2009/03/31/2-things-i-like-in-prototype-161/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Terror the micro aggregator</title>
		<link>http://gravityblast.com/2009/03/17/terror-the-micro-aggregator/</link>
		<comments>http://gravityblast.com/2009/03/17/terror-the-micro-aggregator/#comments</comments>
		<pubDate>Tue, 17 Mar 2009 15:55:54 +0000</pubDate>
		<dc:creator>Andrea Franz</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Sinatra]]></category>

		<guid isPermaLink="false">http://gravityblast.com/?p=120</guid>
		<description><![CDATA[Terror is a micro feed aggregator made with sinatra and bundled as a gem. It&#8217;s very simple to use, just install the gem:

gem sources -a http://gems.github.com
sudo gem install pilu-terror

Create a new project
terror new_aggregator_name
cd new_aggregator_name 
Start the server
thin start -C config/thin.yml
Run the feeds fetcher
rake feeds:fetch # run it as a cron job
You can browse the source [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://github.com/pilu/terror/tree/master" title="Terror the micro feed aggregator">Terror</a> is a micro feed aggregator made with <a href="http://www.sinatrarb.com/" title="Sinatra">sinatra</a> and bundled as a gem. It&#8217;s very simple to use, just install the gem:
</p>
<pre><code>gem sources -a http://gems.github.com
sudo gem install pilu-terror
</code></pre>
<p>Create a new project</p>
<pre><code>terror new_aggregator_name
cd new_aggregator_name </code></pre>
<p>Start the server</p>
<pre><code>thin start -C config/thin.yml</code></pre>
<p>Run the feeds fetcher</p>
<pre><code>rake feeds:fetch # run it as a cron job</code></pre>
<p>You can browse the source and fork it on <a href="http://github.com/pilu/terror/tree/master" title="Terror the micro feed aggregator">github</a>.
</p>
<p>
<img src="http://gravityblast.com/wp-content/uploads/2009/03/terror.jpg" alt="" title="terror" width="500" height="591" class="alignnone size-full wp-image-123" /></p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>share</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://buzz.yahoo.com/submit?submitUrl=http://gravityblast.com/2009/03/17/terror-the-micro-aggregator/&amp;submitHeadline=Terror+the+micro+aggregator&amp;submitSummary=" rel="nofollow" title="Add to&nbsp;Buzz"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/buzz.png" title="Add to&nbsp;Buzz" alt="Add to&nbsp;Buzz" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://gravityblast.com/2009/03/17/terror-the-micro-aggregator/&amp;title=Terror+the+micro+aggregator" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://gravityblast.com/2009/03/17/terror-the-micro-aggregator/&amp;title=Terror+the+micro+aggregator" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.dzone.com/links/add.html?description=Terror+the+micro+aggregator&amp;url=http://gravityblast.com/2009/03/17/terror-the-micro-aggregator/&amp;title=Terror+the+micro+aggregator" rel="nofollow" title="Add to&nbsp;DZone"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/dzone.png" title="Add to&nbsp;DZone" alt="Add to&nbsp;DZone" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://gravityblast.com/2009/03/17/terror-the-micro-aggregator/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://gravityblast.com/2009/03/17/terror-the-micro-aggregator/&amp;title=Terror+the+micro+aggregator" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http://gravityblast.com/2009/03/17/terror-the-micro-aggregator/&amp;T=Terror+the+micro+aggregator" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://gravityblast.com/2009/03/17/terror-the-micro-aggregator/&amp;title=Terror+the+micro+aggregator" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://slashdot.org/bookmark.pl?url=http://gravityblast.com/2009/03/17/terror-the-micro-aggregator/&amp;title=Terror+the+micro+aggregator" rel="nofollow" title="Add to&nbsp;Slashdot"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/slashdot.png" title="Add to&nbsp;Slashdot" alt="Add to&nbsp;Slashdot" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://gravityblast.com/2009/03/17/terror-the-micro-aggregator/&amp;title=Terror+the+micro+aggregator" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://gravityblast.com/2009/03/17/terror-the-micro-aggregator/" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://tipd.com/submit.php?url=http://gravityblast.com/2009/03/17/terror-the-micro-aggregator/" rel="nofollow" title="Add to&nbsp;Tip'd"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/tipd.png" title="Add to&nbsp;Tip'd" alt="Add to&nbsp;Tip'd" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Terror+the+micro+aggregator+@+http://gravityblast.com/2009/03/17/terror-the-micro-aggregator/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://gravityblast.com/2009/03/17/terror-the-micro-aggregator/&amp;t=Terror+the+micro+aggregator" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://gravityblast.com/2009/03/17/terror-the-micro-aggregator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
