diff options
Diffstat (limited to 'railties/doc/guides/source/creating_plugins/odds_and_ends.txt')
-rw-r--r-- | railties/doc/guides/source/creating_plugins/odds_and_ends.txt | 57 |
1 files changed, 2 insertions, 55 deletions
diff --git a/railties/doc/guides/source/creating_plugins/odds_and_ends.txt b/railties/doc/guides/source/creating_plugins/odds_and_ends.txt index eb127f73ca..e328c04a79 100644 --- a/railties/doc/guides/source/creating_plugins/odds_and_ends.txt +++ b/railties/doc/guides/source/creating_plugins/odds_and_ends.txt @@ -1,36 +1,5 @@ == Odds and ends == -=== Work with init.rb === - -The plugin initializer script 'init.rb' is invoked via `eval` (not `require`) so it has slightly different behavior. - -If you reopen any classes in init.rb itself your changes will potentially be made to the wrong module. There are 2 ways around this: - -The first way is to explicitly define the top-level module space for all modules and classes, like `::Hash`: - -[source, ruby] ---------------------------------------------------- -# File: vendor/plugins/yaffle/init.rb - -class ::Hash - def is_a_special_hash? - true - end -end ---------------------------------------------------- - -OR you can use `module_eval` or `class_eval`: - ---------------------------------------------------- -# File: vendor/plugins/yaffle/init.rb - -Hash.class_eval do - def is_a_special_hash? - true - end -end ---------------------------------------------------- - === Generate RDoc Documentation === Once your plugin is stable, the tests pass on all database and you are ready to deploy do everyone else a favor and document it! Luckily, writing documentation for your plugin is easy. @@ -50,38 +19,16 @@ Once your comments are good to go, navigate to your plugin directory and run: rake rdoc - -=== Store models, views, helpers, and controllers in your plugins === - -You can easily store models, views, helpers and controllers in plugins. Just create a folder for each in the lib folder, add them to the load path and remove them from the load once path: - -[source, ruby] ---------------------------------------------------------- -# File: vendor/plugins/yaffle/init.rb - -%w{ models controllers helpers }.each do |dir| - path = File.join(directory, 'lib', dir) - $LOAD_PATH << path - Dependencies.load_paths << path - Dependencies.load_once_paths.delete(path) -end ---------------------------------------------------------- - -Adding directories to the load path makes them appear just like files in the the main app directory - except that they are only loaded once, so you have to restart the web server to see the changes in the browser. - -Adding directories to the load once paths allow those changes to picked up as soon as you save the file - without having to restart the web server. - - === Write custom Rake tasks in your plugin === When you created the plugin with the built-in rails generator, it generated a rake file for you in 'vendor/plugins/yaffle/tasks/yaffle.rake'. Any rake task you add here will be available to the app. Many plugin authors put all of their rake tasks into a common namespace that is the same as the plugin, like so: +*vendor/plugins/yaffle/tasks/yaffle.rake* + [source, ruby] --------------------------------------------------------- -# File: vendor/plugins/yaffle/tasks/yaffle.rake - namespace :yaffle do desc "Prints out the word 'Yaffle'" task :squawk => :environment do |