h1. Rich-Support A small gem making your own gem Rails 2 and 3 compliant and providing the String class a few goodies h2. Introduction Rich-Support is a small module of E9s ("http://github.com/archan937/e9s":http://github.com/archan937/e9s) making your own gem Rails 2 and 3 compliant. It also adds a small amount of handy methods to the String class. *Attention:* This gem does *NOT* add Rails 3 functionality to a Rails 2 application, but provides an unified interface for certain differences in implementation between Rails 2 and 3. A few examples: * it provides a unified interface for the @after_initialize@ hook of the Rails application * it provides the @ActiveSupport::Dependencies.autoload_paths@ to be called in both Rails 2 and 3 * it defines @String.html_safe@ if it hasn't been defined already (it only returns the String and does *NOT* HTML escapes the String) A real world example of a Rich-Support implementation is the "Rich-CMS":https://github.com/archan937/rich_cms/tree/edge gem of which Rich-Support is extracted from. h2. Installation Add Rich-Support as gem dependency in your @gemspec@ file:
s.add_dependency "rich_support"Require Rich-Support in your gem (e.g. in @libs/rich_cms.rb@ for the gem Rich-CMS)
require "rich_support"Your gem is now Rails 2 and 3 compliant. h2. Using the Rails configuration after_initialize hook regardless of the major Rails version As calling the @after_initialize@ differs in the major Rails versions, but you can just call @Rich::Support.after_initialize@ instead as it will handle things for you:
Rich::Support.after_initialize do register_assets copy_images require_models endh2. Registering your gem controllers, views and routes in Rails 2 As only Rails 3 recognizes your controllers, views and routes automatically, you will have to append them in Rails 2 yourself. Fortunately with Rich::Support, you will only have to append your gem path:
Rich::Support.append_gem_path File.expand_path("../..", __FILE__)*Note*: The source file in this example is located in the @lib@ directory of the gem itself Calling @append_gem_path@ registers the following in Rails 2: * @controllers@ - Which is assumed to be located in @app/controllers@ * @views@ - Which is assumed to be located in @app/views@ * @routes@ - Which is assumed to be located in @config/routes.rb@ h2. Some String class goodies Rich-Support adds a small amount of methods to the @String@ class: * @String.upcase_first@ - Upcases the first character of a String and leaves the remainder alone unlike @String.capitalize@ which downcases it * @String.upcase_first!@ - Only returns the upcased String when it has changed otherwise it returns a @nil@ value * @String.copy_case@ - Copies the letter casing of a passed String (e.g. @"paul".copy_case("Engel")@ returns @"Paul"@ and @"CoDe".copy_case("HERO")@ returns @"CODE"@) * @String.copy_case!@ - Only returns the case copied String when it has changed otherwise it returns a @nil@ value * @String.singularize!@ and @String.pluralize!@ - Which (as you expected) only returns a String when it has changed otherwise a @nil@ value h2. Developing Rich-Support yourself 1. Create your own Rich-Support fork "https://github.com/archan937/rich_support/fork":https://github.com/archan937/rich_support/fork 2. Clone your Rich-Support fork repository
git clone git@github.com:3. Setup your environment in order to use the "GemSuit":https://github.com/archan937/gem_suit tests provided within Rich-Support/rich_support.git && cd rich_support
gem install gem_suit && suit fit -v4. Run unit tests in both Rails 2 and 3
suit test unit -v5. Start either of the dummy Rails applications for development purposes (Rails 3 at default)
suit sTo run the Rails 2 application:
suit s -r26. *Get on programming* and send your pull request! ;) *Note*: For more information about GemSuit, please visit "its Github page":https://github.com/archan937/gem_suit. h2. Contact me For support, remarks and requests please mail me at "paul.engel@holder.nl":mailto:paul.engel@holder.nl. h2. Enrichments The all-in-one gem at – "http://codehero.es/rails_gems_plugins/e9s":http://codehero.es/rails_gems_plugins/e9s – "http://github.com/archan937/e9s":http://github.com/archan937/e9s h2. E9s modules * Rich-Support