Froze rails gems
[depot.git] / vendor / rails / railties / doc / guides / source / creating_plugins / helpers.txt
1 == Add a helper ==
2
3 This section describes how to add a helper named 'WoodpeckersHelper' to your plugin that will behave the same as a helper in your main app. This is very similar to adding a model and a controller.
4
5 You can test your plugin's helper as you would test any other helper:
6
7 *vendor/plugins/yaffle/test/woodpeckers_helper_test.rb*
8
9 [source, ruby]
10 ---------------------------------------------------------------
11 require File.dirname(__FILE__) + '/test_helper.rb'
12 include WoodpeckersHelper
13
14 class WoodpeckersHelperTest < Test::Unit::TestCase
15 def test_tweet
16 assert_equal "Tweet! Hello", tweet("Hello")
17 end
18 end
19 ---------------------------------------------------------------
20
21 This is just a simple test to make sure the helper is being loaded correctly. After watching it fail with `rake`, you can make it pass like so:
22
23 *vendor/plugins/yaffle/lib/yaffle.rb:*
24
25 [source, ruby]
26 ----------------------------------------------
27 %w{ models controllers helpers }.each do |dir|
28 path = File.join(File.dirname(__FILE__), 'app', dir)
29 $LOAD_PATH << path
30 ActiveSupport::Dependencies.load_paths << path
31 ActiveSupport::Dependencies.load_once_paths.delete(path)
32 end
33
34 ActionView::Base.send :include, WoodpeckersHelper
35 ----------------------------------------------
36
37
38 *vendor/plugins/yaffle/lib/app/helpers/woodpeckers_helper.rb:*
39
40 [source, ruby]
41 ----------------------------------------------
42 module WoodpeckersHelper
43
44 def tweet(text)
45 "Tweet! #{text}"
46 end
47
48 end
49 ----------------------------------------------
50
51 Now your test should be passing, and you should be able to use the Woodpeckers helper in your app.