Skip to content
This repository
Browse code

Plugin guide: updated to start working with GemPlugin

  • Loading branch information...
commit fa9ea057d1252a578f8e056defef41b93853bc8b 1 parent 88a13fa
Jeff Dean zilkey authored
10 railties/doc/guides/html/creating_plugins.html
@@ -447,6 +447,7 @@ <h3 id="_generate_the_plugin_skeleton">1.2. Generate the plugin skeleton</h3>
447 447 create vendor/plugins/yaffle/generators/yaffle/yaffle_generator.rb
448 448 create vendor/plugins/yaffle/generators/yaffle/USAGE</tt></pre>
449 449 </div></div>
  450 +<div class="para"><p>To begin just change one thing - move <em>init.rb</em> to <em>rails/init.rb</em>.</p></div>
450 451 <h3 id="_setup_the_plugin_for_testing">1.3. Setup the plugin for testing</h3>
451 452 <div class="para"><p>If your plugin interacts with a database, you'll need to setup a database connection. In this guide you will learn how to test your plugin against multiple different database adapters using Active Record. This guide will not cover how to use fixtures in plugin tests.</p></div>
452 453 <div class="para"><p>To setup your plugin to allow for easy testing you'll need to add 3 files:</p></div>
@@ -553,7 +554,7 @@ <h3 id="_setup_the_plugin_for_testing">1.3. Setup the plugin for testing</h3>
553 554
554 555 ActiveRecord<span style="color: #990000">::</span>Base<span style="color: #990000">.</span>establish_connection<span style="color: #990000">(</span>config<span style="color: #990000">[</span>db_adapter<span style="color: #990000">])</span>
555 556 <span style="font-weight: bold"><span style="color: #0000FF">load</span></span><span style="color: #990000">(</span>File<span style="color: #990000">.</span>dirname<span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #0000FF">__FILE__</span></span><span style="color: #990000">)</span> <span style="color: #990000">+</span> <span style="color: #FF0000">"/schema.rb"</span><span style="color: #990000">)</span>
556   - <span style="font-weight: bold"><span style="color: #000080">require</span></span> File<span style="color: #990000">.</span>dirname<span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #0000FF">__FILE__</span></span><span style="color: #990000">)</span> <span style="color: #990000">+</span> <span style="color: #FF0000">'/../init.rb'</span>
  557 + <span style="font-weight: bold"><span style="color: #000080">require</span></span> File<span style="color: #990000">.</span>dirname<span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #0000FF">__FILE__</span></span><span style="color: #990000">)</span> <span style="color: #990000">+</span> <span style="color: #FF0000">'/../rails/init.rb'</span>
557 558 <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
558 559 </tt></pre></div></div>
559 560 <div class="para"><p>Now whenever you write a test that requires the database, you can call <em>load_schema</em>.</p></div>
@@ -668,14 +669,13 @@ <h3 id="_organize_your_files">2.2. Organize your files</h3>
668 669 <div class="para"><p>A common pattern in rails plugins is to set up the file structure like this:</p></div>
669 670 <div class="listingblock">
670 671 <div class="content">
671   -<pre><tt>|-- init.rb
672   -|-- lib
  672 +<pre><tt>|-- lib
673 673 | |-- yaffle
674 674 | | `-- core_ext.rb
675 675 | `-- yaffle.rb</tt></pre>
676 676 </div></div>
677   -<div class="para"><p>The first thing we need to to is to require our <em>lib/yaffle.rb</em> file from <em>init.rb</em>:</p></div>
678   -<div class="para"><p><strong>vendor/plugins/yaffle/init.rb</strong></p></div>
  677 +<div class="para"><p>The first thing we need to to is to require our <em>lib/yaffle.rb</em> file from <em>rails/init.rb</em>:</p></div>
  678 +<div class="para"><p><strong>vendor/plugins/yaffle/rails/init.rb</strong></p></div>
679 679 <div class="listingblock">
680 680 <div class="content"><!-- Generator: GNU source-highlight 2.9
681 681 by Lorenzo Bettini
5 railties/doc/guides/source/creating_plugins/core_ext.txt
@@ -45,16 +45,15 @@ Great - now you are ready to start development.
45 45 A common pattern in rails plugins is to set up the file structure like this:
46 46
47 47 --------------------------------------------------------
48   -|-- init.rb
49 48 |-- lib
50 49 | |-- yaffle
51 50 | | `-- core_ext.rb
52 51 | `-- yaffle.rb
53 52 --------------------------------------------------------
54 53
55   -The first thing we need to to is to require our 'lib/yaffle.rb' file from 'init.rb':
  54 +The first thing we need to to is to require our 'lib/yaffle.rb' file from 'rails/init.rb':
56 55
57   -*vendor/plugins/yaffle/init.rb*
  56 +*vendor/plugins/yaffle/rails/init.rb*
58 57
59 58 [source, ruby]
60 59 --------------------------------------------------------
1  railties/doc/guides/source/creating_plugins/gem.txt
... ... @@ -0,0 +1 @@
  1 +http://www.mbleigh.com/2008/6/11/gemplugins-a-brief-introduction-to-the-future-of-rails-plugins
3  railties/doc/guides/source/creating_plugins/test_setup.txt
@@ -61,6 +61,7 @@ create vendor/plugins/yaffle/generators/yaffle/yaffle_generator.rb
61 61 create vendor/plugins/yaffle/generators/yaffle/USAGE
62 62 ----------------------------------------------
63 63
  64 +To begin just change one thing - move 'init.rb' to 'rails/init.rb'.
64 65
65 66 === Setup the plugin for testing ===
66 67
@@ -157,7 +158,7 @@ def load_schema
157 158
158 159 ActiveRecord::Base.establish_connection(config[db_adapter])
159 160 load(File.dirname(__FILE__) + "/schema.rb")
160   - require File.dirname(__FILE__) + '/../init.rb'
  161 + require File.dirname(__FILE__) + '/../rails/init.rb'
161 162 end
162 163 ----------------------------------------------
163 164

0 comments on commit fa9ea05

Please sign in to comment.
Something went wrong with that request. Please try again.