Every repository with this icon (
Every repository with this icon (
tree 060d626c21a15191ebaf4d645e24653bea7c9314
parent b16a5f37ae226e2414fce4bd46b066e78adb462c
| name | age | message | |
|---|---|---|---|
| |
.gitignore | Mon Jun 15 03:16:57 -0700 2009 | |
| |
CHANGELOG.rdoc | ||
| |
LICENSE.rdoc | Mon Feb 16 16:03:05 -0800 2009 | |
| |
Manifest | Fri Jul 03 01:57:29 -0700 2009 | |
| |
README.rdoc | ||
| |
Rakefile | ||
| |
helperful.gemspec | ||
| |
init.rb | Tue Feb 17 13:51:06 -0800 2009 | |
| |
install.rb | Mon Nov 03 12:29:15 -0800 2008 | |
| |
lib/ | ||
| |
rails/ | Tue Feb 17 13:51:06 -0800 2009 | |
| |
tasks/ | Mon Nov 03 12:29:15 -0800 2008 | |
| |
test/ | ||
| |
uninstall.rb | Mon Nov 03 12:29:15 -0800 2008 |
Helperful
Helperful aims to be a collection of useful and reusable Rails helpers.
Plugin Installation
As a Gem
This is the preferred way to install Helperful and the best way if you want install a stable version.
$ gem install weppos-helperful --source http://gems.github.com
You can specify the GEM dependency in your application environment.rb file:
Rails::Initializer.run do |config|
config.gem "weppos-helperful", :lib => "helperful", :source => "http://gems.github.com"
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.








