public
Description: A collection of useful Rails helpers.
Homepage: http://code.simonecarletti.com/projects/show/helperful
Clone URL: git://github.com/weppos/helperful.git
weppos (author)
Mon Oct 12 10:27:27 -0700 2009
commit  80052c6a4b7f9ce52b9ea487655f6a9571e28f41
tree    523f99511ca1bbca2981c5643c5d4f04c2c8aa50
parent  e87b812b232d7cf139dd6178468986502cab9b1f
name age message
file .gitignore Mon Jun 15 03:16:57 -0700 2009 GitHub now requires the Manifest file to be inc... [weppos]
file CHANGELOG.rdoc Mon Oct 12 10:27:27 -0700 2009 Release Helperful 0.5.2 [weppos]
file LICENSE.rdoc Mon Feb 16 16:03:05 -0800 2009 Forced CHANGELOG, README and LICENSE file to be... [weppos]
file Manifest Fri Jul 03 01:57:29 -0700 2009 Helperful release 0.5.0 [weppos]
file README.rdoc Mon Oct 12 10:20:51 -0700 2009 GitHub Gem Building is Defunct. The gem is now ... [weppos]
file Rakefile Thu Aug 20 04:25:27 -0700 2009 Cleaned up Rakefile. [weppos]
file helperful.gemspec Thu Aug 20 04:34:08 -0700 2009 Release Helperful 0.5.1 [weppos]
file init.rb Tue Feb 17 13:51:06 -0800 2009 Added #helperful method as shortcut for includi... [weppos]
file install.rb Mon Nov 03 12:29:15 -0800 2008 * Added empty Rails plugin structure [weppos]
directory lib/ Mon Oct 12 10:27:27 -0700 2009 Release Helperful 0.5.2 [weppos]
directory rails/ Tue Feb 17 13:51:06 -0800 2009 Added #helperful method as shortcut for includi... [weppos]
directory tasks/ Mon Nov 03 12:29:15 -0800 2008 * Added empty Rails plugin structure [weppos]
directory test/ Mon Oct 12 10:20:51 -0700 2009 GitHub Gem Building is Defunct. The gem is now ... [weppos]
file uninstall.rb Mon Nov 03 12:29:15 -0800 2008 * Added empty Rails plugin structure [weppos]
README.rdoc

Helperful

Helperful aims to be a collection of useful and reusable Rails helpers.

Requirements

  • Ruby >= 1.8.6
  • Rails >= 2.2.x (tested up to Rails 2.3.3)

Plugin Installation

As a Gem

This is the preferred way to install Helperful and the best way if you want install a stable version. The GEM is hosted on Gemcutter.

  $ gem install helperful --source http://gemcutter.org

With Rails >= 2.2, you can specify the GEM dependency in your environment.rb file so that Rails will automatically check the requirement on startup.

  Rails::Initializer.run do |config|

    # other configurations
    # ...

    config.gem "helperful", :source => "http://gemcutter.org"

  end

As a Plugin

This is the preferred way if you want to live on the edge and install a development version.

  $ script/plugin install git://github.com/weppos/helperful.git

Getting Started

Helper methods are grouped into different files according to their scope.

Before using an helper method you should include the helper file in your Rails application, as you would expected to do for a standard Rails helper. All helpers belongs to the Helperful namespace to prevent conflicts with default Rails helpers. Don’t forget to add the namespace when including an helper from your controller.

  class MyController < ApplicationController

    # include the title_helper
    helper 'helperful/title'

    # include the title_helper passing the qualified the module name
    helper Helperful::TitleHelper

  end

Moreover, the Helperful library provides a helpful method called helperful. It aliases the standard Rails ActionController::Base#helper method with the exception that it automatically prepends the helperful namespace when necessary.

  class MyController < ApplicationController

    # include the title_helper
    helperful :title

    # include the title_helper passing the qualified the module name
    helperful Helperful::TitleHelper

  end

The following lines are equivalent:

  helper    'helperful/title'
  helper    :'helperful/title'
  helper    Helperful::TitleHelper
  helperful 'title'
  helperful :title
  helperful Helperful::TitleHelper

The helperful methods accepts any parameter accepted by the original helper method.

  helper    'helperful/title', 'helperful/affiliations'
  helperful :title, :affiliations

See the Rails documentation for ActionController::Base#helper method for more details about how to include an helper into a Rails application.

Once included, all helper methods are available in the View.

  <html>
    <title><%= title 'This is a title' %></title>
    <body>
      <%= yield %>
    </body>
  </html>

Helpers

This is a short description of all available helpers. Please refer to the documentation available at the beginning of any helper file for further details.

Asset Tag Helper

Provides a set of helpers for generating HTML that links views to assets such as images, javascripts, stylesheets, and feeds.

Affiliations Helper

Provides a set of helpers for working with online affiliations.

The tradedoubler_verification_tag helper method returns the site verification tag required by Tradedoubler to verify the publisher account ownership.

  # In your template
  <html>
    <head>
      <%= tradedoubler_verification_tag('00112233') %>
    </head>
    <body>
      This is your page content.
    </body>
  </html>

  # Will produce the following output.
  <html>
    <head>
      <%= tradedoubler_verification_tag('00112233') %>
    </head>
    <body>
      <!-- TradeDoubler site verification 00112233 -->
    </body>
  </html>

Content Helper

Provides a set of helpers for capturing and working with your page content in a more effective way.

The has_content? helper is a natural fulfillment for the original content_for helper.

  <% content_for :foo do %>
    <div>This is a foo content.</div>
  <% end %>

  <% has_content? :foo  # => true %>
  <% has_content? "foo" # => true %>

Javascript Helper

Provides a set of helpers for working with JavaScript in your views.

The javascript_content_for helper combines the features of content_for and javascript_tag into a single helper.

  <% javascript_content_for :head do %>
    $("#id").hide();
  <% end %>

The code above looks like much more readable than the following one. Isn’t it?

  <% javascript_content_for :head do; javascript_tag do %>
    $("#id").hide();
  <% end; end %>

Title Helper

Provides an helper for managing page title in Rails views and layouts.

  # Include the helper in your controller.
  # You might want to include it in ApplicationController to make it available
  # always and everywhere in your templates.
  class ApplicationController < ActionController::Base
    helperful :title
  end

  # Now you can use set a title in your action
  # Example. index.html.rb
  <h1><%= title 'This is a title' %></h1>

  # And print the title with a :site decorator in your layout.
  <html>
    <head>
      <title><%= title :site => 'My Cool Site!' %></title>
    </head>
    <body>
      <%= yield %>
    </body>
  </html>

Originally available at gist.github.com/3840.

Credits

Author:Simone Carletti <weppos@weppos.net>

Resources

License

Copyright © 2008-2009 Simone Carletti, Helperful is released under the MIT license.