<?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>Dr Nic &#187; RailsCore</title>
	<atom:link href="http://drnicwilliams.com/category/ruby/ruby-on-rails/railscore/feed/" rel="self" type="application/rss+xml" />
	<link>http://drnicwilliams.com</link>
	<description>Ruby makes Rails, Javascript makes Ajax, Dr Nic makes Magic</description>
	<lastBuildDate>Sat, 12 Nov 2011 01:05:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>Where art thou generator?</title>
		<link>http://drnicwilliams.com/2007/06/25/rails-generators-in-rubygems/</link>
		<comments>http://drnicwilliams.com/2007/06/25/rails-generators-in-rubygems/#comments</comments>
		<pubDate>Mon, 25 Jun 2007 12:03:09 +0000</pubDate>
		<dc:creator>Dr Nic</dc:creator>
				<category><![CDATA[Gems]]></category>
		<category><![CDATA[RailsCore]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://drnicwilliams.com/2007/06/25/rails-generators-in-rubygems/</guid>
		<description><![CDATA[Summary: click to select UPDATE: Rails Generators within RubyGems support is now in Rails Edge Generators in Rails are awesome. No? So you don&#8217;t use the rails command to create a new rails app? Nor the model, migration, or plugin generators? Yeah, they are awesome. Hug the next one you meet. On my part-time quest [...]


Related posts:<ol><li><a href='http://drnicwilliams.com/2009/11/04/hacking-someones-gem-with-github-and-gemcutter/' rel='bookmark' title='Permanent Link: Hacking someone&#8217;s gem with github and gemcutter'>Hacking someone&#8217;s gem with github and gemcutter</a> <small> Ever used a rubygem, found a bug, and just...</small></li><li><a href='http://drnicwilliams.com/2009/11/03/first-look-at-rails-3-0-pre/' rel='bookmark' title='Permanent Link: First look at rails 3.0.pre'>First look at rails 3.0.pre</a> <small> This article is out of date in some aspects....</small></li><li><a href='http://drnicwilliams.com/2008/10/31/newgem-100-all-thanks-to-cucumber/' rel='bookmark' title='Permanent Link: newgem 1.0.0 all thanks to Cucumber'>newgem 1.0.0 all thanks to Cucumber</a> <small>The New Gem Generator (newgem) was exciting, moderately revolutionary, and...</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p id="bk_summary_197" name="bk_summary_197" class="bk_summary"><strong>Summary: </strong> <span class="help">click to select</span></p>
<input id="bk_summary_input_197" value="Rails Generators stored within RubyGems; and Vendor Everything core patch" style="width:100%"  onClick="javascript:var summary = document.getElementById('bk_summary_input_197'); summary.focus();summary.select();" readonly="true" /></span></p>
<p><strong>UPDATE:</strong> Rails Generators within RubyGems support is now in <a href="http://dev.rubyonrails.org/changeset/7139">Rails Edge</a></p>
<p>Generators in Rails are awesome. No? So you don&#8217;t use the <code>rails</code> command to create a new rails app? Nor the <code>model</code>, <code>migration</code>, or <code>plugin</code> generators? Yeah, they are awesome. Hug the next one you meet.</p>
<p>On my part-time quest to replace the use of Plugins with RubyGems within Rails, it occurred to <a href="http://geoffreygrosenbach.com/">Geoffrey Grosenbach</a> [<a href="http://drnicwilliams.com/2007/06/25/rails-generators-in-rubygems/#1-topfunky">1</a>] and myself that there is no easy way to bundle rails generators within RubyGems. Patooey, we say!</p>
<p>Currently, there are <a href="http://wiki.rubyonrails.com/rails/pages/UnderstandingGenerators#gen_search">several places</a> you can store Rails generators:</p>
<ul>
<li>Builtin ones &#8211; like <code>model</code>, <code>scaffold</code> etc &#8211; are stored in the <code>rails</code> gem. </li>
<li><code>~/.rails/generators/</code> for your own personal generators. </li>
<li>Rubygems whose name ends with <code>_generator</code>, such as <code>ajax_scaffold_generator</code></li>
<li><code>vendor/generators/</code></li>
<li><code>vendor/plugins/_some_plugin_/generators/</code> &#8211; the most common mechanism for deploying generators</li>
</ul>
<p>But no way to bundle multiple generators in a RubyGem or have a gem without <code>_generator</code> in its name. And Rails has laid claim to the <code>_generator</code> namespace, which is a bit greedy.</p>
<h3>This is outrageous!</h3>
<p>Damn it, you&#8217;re right! Its now in <a href="http://dev.rubyonrails.org/changeset/7139">Rails Edge</a>!</p>
<pre>
rails newapp
cd newapp
rake rails:freeze:edge
</pre>
<p><strike>So try out <a href="http://dev.rubyonrails.org/ticket/8730">this new Rails Core patch</a>. Never touched a raw patch before? Nevermind. To play with it, let&#8217;s create a new rails app: </p>
<pre>
cd vendor/rails/railties
wget http://dev.rubyonrails.org/attachment/ticket/8730/gem_generators.patch?format=txt -O gem_generators.patch
patch -p0 &lt; gem_generators.patch
cd ../../..
</pre>
<p>	</strike></p>
<h3>The world&#8217;s first Generator-Enabled RubyGem is&#8230;</h3>
<p>So you can play with this fabbo new feature and explore how to add generators to your RubyGems, Rick Olson&#8217;s <a href="http://svn.techno-weenie.net/projects/plugins/restful_authentication/">restful_authentication</a> plugin has been ported into a RubyGem. It is currently available for <a href="http://drnicwilliams.com/wp-content/ruby/gems/restful_authentication-1.0.0.gem">manual download</a> and will soon be live on RubyForge.</p>
<pre>
wget http://drnicwilliams.com/wp-content/ruby/gems/restful_authentication-1.0.0.gem
gem install restful_authentication
ruby script/generate
</pre>
<p>And you&#8217;ll see the <code>authenticated</code> generator is discovered from the RubyGem. Neat. Note, we didn&#8217;t install the old plugin within the rails app.</p>
<p>So, now let&#8217;s play with it&#8230;</p>
<pre>
ruby script/generate authenticated user
</pre>
<p>It works exactly like it did from the original plugin. But now its a RubyGem, and you never ever need to reinstall this plugin for each new app, ever again. Ever.</p>
<h3>Merge plugin generators into RubyGems</h3>
<p>There exists a RubyGem <a href="http://rubyforge.org/projects/daemons/">daemons</a>, and there exists a separate <a href="http://agilewebdevelopment.com/plugins/daemon_generator">plugin</a>, that makes it easy to use daemons via your rails app.</p>
<p>This separation will be no longer necessary!</p>
<p>Now the generator code can be moved into the daemons gem itself.</p>
<p>Have a look at the <a href="http://svn.kylemaxwell.com/rails_plugins/daemon_generator/trunk/">plugin</a>, and note the <code>generators</code> folder. Simply copy this folder into the <code>daemons</code> gem. Then rename this folder to <code>rails_generators</code>. Repackage and release.</p>
<p>Shaazam!</p>
<p>PS. To the owner of <a href="http://rubyforge.org/scm/?group_id=524">daemons repository</a>, come on dude! Upgrade from <span class="caps">CVS</span> to <span class="caps">SVN</span>&#8230; <img src='http://drnicwilliams.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h3>Want to write your own generators?</h3>
<p>There is some useful info on <a href="http://wiki.rubyonrails.org/rails/pages/UnderstandingGenerators">writing</a> <a href="http://www.aidanf.net/rails/creating-your-own-generators-in-rails">generators</a> on the tubes. Start there.</p>
<p>In all cases, (for an example &#8220;foo&#8221; generator) the generator file must be called <code>foo_generator.rb</code>, and it must contain a class called <code>FooGenerator</code>.</p>
<h3>Does it work with &#8220;vendor everything?&#8221;</h3>
<p>Normal people living normal lives won&#8217;t know there exists a <a href="http://dev.rubyonrails.org/ticket/8511">Rails Core ticket</a> to support &#8220;<a href="http://errtheblog.com/post/2120">vendor everything</a>&#8221;, created by <a href="http://www.vernix.org/">Marcel Molina Jr</a> [<a href="http://drnicwilliams.com/2007/06/25/rails-generators-in-rubygems/#2-marcel">2</a>] (and his backing singer <a href="http://pragdave.pragprog.com/">Dave Thomas</a>).</p>
<p>This allows you to store <code>gem</code> files in a <code>/vendor/gems</code> folder, and it will be super magically exploded into the <code>/vendor/gems/home</code> folder. That is, you can freeze raw gems into your rails source structure.</p>
<p>To test this, first uninstall the <code>restful_authentication</code> gem and then reload it into the <code>/vendor/gems</code> folder:</p>
<pre>
gem uninstall restful_authentication
cd vendor/rails/railties
wget http://dev.rubyonrails.org/attachment/ticket/8511/gems_loaded_from_vendor_like_plugins.diff?format=txt -O gems_loaded.patch
patch -p0 &lt; gems_loaded.patch
cd ../../..
ruby script/generate
</pre>
<p>Do this just to confirm that the <code>authenticated</code> generate is no longer available.</p>
<pre>
cd vendor
ls .
</pre>
<p>Note that you now have a <code>gems</code> folder, and within it you have a <code>home</code> folder, which itself stores lots more new folders. This is Marcel&#8217;s patch in action!</p>
<pre>
cd gems
wget http://drnicwilliams.com/wp-content/ruby/gems/restful_authentication-1.0.0.gem
cd ../..
ruby script/generate
</pre>
<p>And the <code>authenticated</code> generator is back! Discovered auto-magically from within your own rails source! Investigate the <code>vendor/gems/home</code> folders at your leisure.</p>
<h3>So this article is about two things&#8230;</h3>
<p>Herein layeth a tale of <a href="http://dev.rubyonrails.org/ticket/8730">two</a> <a href="http://dev.rubyonrails.org/ticket/8511">tickets</a> (first one is now in Rails Edge). Sneaky, nay?</p>
<p>Please try them out and comment within each ticket about any praise/thoughts/fixes/outright-damnations so the nice Rails Core team (esp. to <a href="http://www.loudthinking.com/"><span class="caps">DHH</span></a> who is not sure if &#8220;vendor everything&#8221; is something that should be in Rails Core [<a href="http://drnicwilliams.com/2007/06/25/rails-generators-in-rubygems/#3-dhh">3</a>]) know this is an important direction for Rails to go.</p>
<p><a name="1-topfunky"/><br />
[1] Normally I&#8217;d reference/link <a href="http://nubyonrails.com/">Nuby On Rails</a> or <a href="http://peepcode.com/">Peepcode</a>, but I just love the &#8220;half a head&#8221; self-photo on his home page.</p>
<p><a name="2-marcel"/><br />
[2] More info about Marcel on <a href="http://rubyonrails.com/core">Rails Core</a> page.</p>
<p><a name="3-dhh"/><br />
[3] Based on a chat in irc #rails-contrib the other day, when that ticket was first created.</p>


<p>Related posts:<ol><li><a href='http://drnicwilliams.com/2009/11/04/hacking-someones-gem-with-github-and-gemcutter/' rel='bookmark' title='Permanent Link: Hacking someone&#8217;s gem with github and gemcutter'>Hacking someone&#8217;s gem with github and gemcutter</a> <small> Ever used a rubygem, found a bug, and just...</small></li><li><a href='http://drnicwilliams.com/2009/11/03/first-look-at-rails-3-0-pre/' rel='bookmark' title='Permanent Link: First look at rails 3.0.pre'>First look at rails 3.0.pre</a> <small> This article is out of date in some aspects....</small></li><li><a href='http://drnicwilliams.com/2008/10/31/newgem-100-all-thanks-to-cucumber/' rel='bookmark' title='Permanent Link: newgem 1.0.0 all thanks to Cucumber'>newgem 1.0.0 all thanks to Cucumber</a> <small>The New Gem Generator (newgem) was exciting, moderately revolutionary, and...</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://drnicwilliams.com/2007/06/25/rails-generators-in-rubygems/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>

