weppos-helperful 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG.rdoc ADDED
@@ -0,0 +1,22 @@
1
+ = Changelog
2
+
3
+ == master
4
+
5
+ * ADDED: Added Helperful::ContentHelper module (subsequently renamed to Helperful::ContentHelper) with #sidebar helper for passing content_for :sidebar to the layout. Even if this is a really simple method, this method adds a bit of semantic meaning to common application usage of content_for for created sidebars.
6
+
7
+ * ADDED: Added HelperfulAffiliationsHelper module (subsequently renamed to Helperful::AffiliationsHelper).
8
+
9
+ * ADDED: Added HelperfulAffiliationsHelper#tradedoubler_verification_tag helper for generating Tradedoubler verifications tags (subsequently renamed to Helperful::AffiliationsHelper).
10
+
11
+ * ADDED: Added #helperful method as shortcut for including helper modules from the Helperful namespace.
12
+
13
+ * ADDED: Packaged library as a GEM.
14
+
15
+ * CHANGED: Renamed TitleHelper to HelperfulTitleHelper to prevent conflicts with other common helpers (subsequently renamed to Helperful::TitleHelper).
16
+
17
+ * CHANGED: Renamed all helper modules from HelperfulHelperName to Helperful::HelperName.
18
+
19
+
20
+ == Release 0.1.0
21
+
22
+ * ADDED: Imported TitleHelper from Gist.
data/LICENSE.rdoc ADDED
@@ -0,0 +1,24 @@
1
+ = License
2
+
3
+ (The MIT License)
4
+
5
+ Copyright (c) 2008-2009 Simone Carletti <weppos@weppos.net>
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining
8
+ a copy of this software and associated documentation files (the
9
+ "Software"), to deal in the Software without restriction, including
10
+ without limitation the rights to use, copy, modify, merge, publish,
11
+ distribute, sublicense, and/or sell copies of the Software, and to
12
+ permit persons to whom the Software is furnished to do so, subject to
13
+ the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be
16
+ included in all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,171 @@
1
+ = Helperful
2
+
3
+ Helperful aims to be a collection of useful and reusable Rails helpers.
4
+
5
+ *WARNING*: This library has not been released yet. This package seems stable, but should be considered a development release. You should not use it in production.
6
+ Changes to specifications may occur at any time and without notice. For the full list of changes look at the CHANGELOG file.
7
+
8
+
9
+ == Getting Started
10
+
11
+ Helper methods are grouped into different files according to their scope.
12
+
13
+ Before using an helper method you should include the helper file in your Rails application,
14
+ as you would expected to do for a standard Rails helper.
15
+ All helpers belongs to the Helperful namespace to prevent conflicts with default Rails helpers.
16
+ Don't forget to add the namespace when including an helper from your controller.
17
+
18
+ class MyController < ApplicationController
19
+
20
+ # include the title_helper
21
+ helper 'helperful/title'
22
+
23
+ # include the title_helper passing the qualified the module name
24
+ helper Helperful::TitleHelper
25
+
26
+ end
27
+
28
+
29
+ Moreover, the <tt>Helperful</tt> library provides a helpful method called <tt>helperful</tt>.
30
+ It aliases the standard Rails <tt>ActionController::Base#helper</tt> method with the exception that it automatically prepends the <tt>helperful</tt> namespace when necessary.
31
+
32
+ class MyController < ApplicationController
33
+
34
+ # include the title_helper
35
+ helperful :title
36
+
37
+ # include the title_helper passing the qualified the module name
38
+ helperful Helperful::TitleHelper
39
+
40
+ end
41
+
42
+
43
+ The following lines are equivalent:
44
+
45
+ helper 'helperful/title'
46
+ helper :'helperful/title'
47
+ helper Helperful::TitleHelper
48
+ helperful 'title'
49
+ helperful :title
50
+ helperful Helperful::TitleHelper
51
+
52
+
53
+ The <tt>helperful</tt> methods accepts any parameter accepted by the original <tt>helper</tt> method.
54
+
55
+ helper 'helperful/title', 'helperful/affiliations'
56
+ helperful :title, :affiliations
57
+
58
+
59
+ See the Rails documentation for <tt>ActionController::Base#helper</tt> method
60
+ for more details about how to include an helper into a Rails application.
61
+
62
+ Once included, all helper methods are available in the View.
63
+
64
+ <html>
65
+ <title><%= title 'This is a title' %></title>
66
+ <body>
67
+ <%= yield %>
68
+ </body>
69
+ </html>
70
+
71
+
72
+ == Helpers
73
+
74
+ This is a short description of all available helpers.
75
+ Please refer to the documentation available at the beginning of any helper file for further details.
76
+
77
+ === Affiliations Helper
78
+
79
+ Provides a set of helpers for working with online affiliations.
80
+
81
+ The <tt>tradedoubler_verification_tag</tt> helper method returns the site verification tag required by {Tradedoubler}[http://www.tradedoubler.com/] to verify the publisher account ownership.
82
+
83
+ # In your template
84
+ <html>
85
+ <head>
86
+ <%= tradedoubler_verification_tag('00112233') %>
87
+ </head>
88
+ <body>
89
+ This is your page content.
90
+ </body>
91
+ </html>
92
+
93
+ # Will produce the following output.
94
+ <html>
95
+ <head>
96
+ <%= tradedoubler_verification_tag('00112233') %>
97
+ </head>
98
+ <body>
99
+ <!-- TradeDoubler site verification 00112233 -->
100
+ </body>
101
+ </html>
102
+
103
+ === Content Helper
104
+
105
+ Provides a set of helpers for capturing and working with your page content in a more effective way.
106
+
107
+ The <tt>sidebar</tt> helper method is a syntactic sugar addition to store content for your website sidebars.
108
+
109
+ <% sidebar do %>
110
+ <div>This is a sidebar module.</div>
111
+ <% end %>
112
+ <% sidebar do %>
113
+ <div>This is an other sidebar module.</div>
114
+ <% end %>
115
+
116
+ <%= yield :sidebar # Produces the following output %>
117
+ <div>This is an other sidebar module.</div>
118
+ <div>This is a sidebar module.</div>
119
+
120
+ The <tt>has_content?</tt> helper is a natural fulfillment for the original <tt>content_for</tt> helper.
121
+
122
+ <% content_for :foo do %>
123
+ <div>This is a foo content.</div>
124
+ <% end %>
125
+
126
+ <% has_content? :foo # => true %>
127
+ <% has_content? "foo" # => true %>
128
+
129
+ === Title Helper
130
+
131
+ Provides an helper for managing page title in Rails views and layouts.
132
+
133
+ # Include the helper in your controller.
134
+ # You might want to include it in ApplicationController to make it available
135
+ # always and everywhere in your templates.
136
+ class ApplicationController < ActionController::Base
137
+ helperful :title
138
+ end
139
+
140
+ # Now you can use set a title in your action
141
+ # Example. index.html.rb
142
+ <h1><%= title 'This is a title' %></h1>
143
+
144
+ # And print the title with a :site decorator in your layout.
145
+ <html>
146
+ <head>
147
+ <title><%= title :site => 'My Cool Site!' %></title>
148
+ </head>
149
+ <body>
150
+ <%= yield %>
151
+ </body>
152
+ </html>
153
+
154
+ Originally available at http://gist.github.com/3840.
155
+
156
+
157
+ == Credits
158
+
159
+ Author:: {Simone Carletti}[http://www.simonecarletti.com/] <weppos@weppos.net>
160
+
161
+
162
+ == Resources
163
+
164
+ * {Homepage}[http://code.simonecarletti.com/helperful]
165
+ * {GitHub}[http://github.com/weppos/helperful]
166
+
167
+
168
+ == License
169
+
170
+ Copyright (c) 2008-2009 Simone Carletti, Helperful is released under the MIT license.
171
+
data/Rakefile ADDED
@@ -0,0 +1,52 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+
5
+ $:.unshift(File.dirname(__FILE__) + "/lib")
6
+ require 'helperful'
7
+
8
+
9
+ PKG_NAME = ENV['PKG_NAME'] || Helperful::GEM
10
+ PKG_VERSION = ENV['PKG_VERSION'] || Helperful::VERSION
11
+ PKG_SUMMARY = "A collection of useful Rails helpers."
12
+ PKG_FILES = FileList.new("{lib,rails,tasks,test}/**/*") do |files|
13
+ files.include %w(*.{rdoc,rb})
14
+ files.include %w(Rakefile)
15
+ end
16
+ RUBYFORGE_PROJECT = nil
17
+
18
+ if ENV['SNAPSHOT'].to_i == 1
19
+ PKG_VERSION << "." << Time.now.utc.strftime("%Y%m%d%H%M%S")
20
+ end
21
+
22
+
23
+ Echoe.new(PKG_NAME, PKG_VERSION) do |p|
24
+ p.author = "Simone Carletti"
25
+ p.email = "weppos@weppos.net"
26
+ p.summary = PKG_SUMMARY
27
+ p.description = <<-EOD
28
+ Helperful aims to be a collection of useful and reusable Rails helpers.
29
+ EOD
30
+ p.url = "http://code.simonecarletti.com/helperful"
31
+ p.project = RUBYFORGE_PROJECT
32
+
33
+ p.need_zip = true
34
+ p.rcov_options = ["--main << README.rdoc -x Rakefile -x mocha -x rcov"]
35
+ p.rdoc_pattern = /^(lib|CHANGELOG.rdoc|README.rdoc|LICENSE.rdoc)/
36
+
37
+ p.development_dependencies += ["rake >=0.8",
38
+ "echoe >=3.1",
39
+ "mocha >=0.9"]
40
+ end
41
+
42
+
43
+ begin
44
+ require 'code_statistics'
45
+ desc "Show library's code statistics"
46
+ task :stats do
47
+ CodeStatistics.new(["Helperful", "lib"],
48
+ ["Tests", "test"]).to_s
49
+ end
50
+ rescue LoadError
51
+ puts "CodeStatistics (Rails) is not available"
52
+ end
data/helperful.gemspec ADDED
@@ -0,0 +1,40 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{helperful}
5
+ s.version = "0.2.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Simone Carletti"]
9
+ s.date = %q{2009-02-25}
10
+ s.description = %q{Helperful aims to be a collection of useful and reusable Rails helpers.}
11
+ s.email = %q{weppos@weppos.net}
12
+ s.extra_rdoc_files = ["CHANGELOG.rdoc", "lib/helperful/affiliations_helper.rb", "lib/helperful/content_helper.rb", "lib/helperful/deprecations.rb", "lib/helperful/title_helper.rb", "lib/helperful/version.rb", "lib/helperful.rb", "LICENSE.rdoc", "README.rdoc"]
13
+ s.files = ["CHANGELOG.rdoc", "init.rb", "install.rb", "lib/helperful/affiliations_helper.rb", "lib/helperful/content_helper.rb", "lib/helperful/deprecations.rb", "lib/helperful/title_helper.rb", "lib/helperful/version.rb", "lib/helperful.rb", "LICENSE.rdoc", "rails/init.rb", "Rakefile", "README.rdoc", "tasks/helperful_tasks.rake", "test/affiliations_helper_test.rb", "test/content_helper_test.rb", "test/fixtures/content/has_content.html.erb", "test/fixtures/content/sidebar.html.erb", "test/fixtures/content/sidebar_concatenate.html.erb", "test/fixtures/layouts/has_content.html.erb", "test/fixtures/layouts/sidebar.html.erb", "test/helperful_test.rb", "test/test_helper.rb", "test/title_helper_test.rb", "uninstall.rb", "Manifest", "helperful.gemspec"]
14
+ s.has_rdoc = true
15
+ s.homepage = %q{http://code.simonecarletti.com/helperful}
16
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Helperful", "--main", "README.rdoc"]
17
+ s.require_paths = ["lib"]
18
+ s.rubygems_version = %q{1.3.1}
19
+ s.summary = %q{A collection of useful Rails helpers.}
20
+ s.test_files = ["test/affiliations_helper_test.rb", "test/content_helper_test.rb", "test/helperful_test.rb", "test/test_helper.rb", "test/title_helper_test.rb"]
21
+
22
+ if s.respond_to? :specification_version then
23
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
24
+ s.specification_version = 2
25
+
26
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
27
+ s.add_development_dependency(%q<rake>, [">= 0.8"])
28
+ s.add_development_dependency(%q<echoe>, [">= 3.1"])
29
+ s.add_development_dependency(%q<mocha>, [">= 0.9"])
30
+ else
31
+ s.add_dependency(%q<rake>, [">= 0.8"])
32
+ s.add_dependency(%q<echoe>, [">= 3.1"])
33
+ s.add_dependency(%q<mocha>, [">= 0.9"])
34
+ end
35
+ else
36
+ s.add_dependency(%q<rake>, [">= 0.8"])
37
+ s.add_dependency(%q<echoe>, [">= 3.1"])
38
+ s.add_dependency(%q<mocha>, [">= 0.9"])
39
+ end
40
+ end
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require File.join(File.dirname(__FILE__), 'rails', 'init')
data/install.rb ADDED
@@ -0,0 +1 @@
1
+ # Install hook code here
@@ -0,0 +1,44 @@
1
+ #
2
+ # = Helperful
3
+ #
4
+ # A collection of useful Rails helpers.
5
+ #
6
+ #
7
+ # Category:: Rails
8
+ # Package:: Helperful
9
+ # Author:: Simone Carletti <weppos@weppos.net>
10
+ # Copyright:: 2008-2009 The Authors
11
+ # License:: MIT License
12
+ #
13
+ #--
14
+ #
15
+ #++
16
+
17
+
18
+ module Helperful
19
+
20
+ #
21
+ # = Affiliations Helper
22
+ #
23
+ # Provides a set of helpers for working with online affiliations.
24
+ #
25
+ module AffiliationsHelper
26
+
27
+ #
28
+ # Returns the tradedoubler site verification tag for +publisher_id+.
29
+ #
30
+ # tradedoubler_verification_tag('123456')
31
+ # # => <!-- TradeDoubler site verification 123456 -->
32
+ #
33
+ # tradedoubler_verification_tag(123456)
34
+ # # => <!-- TradeDoubler site verification 123456 -->
35
+ #
36
+ # tradedoubler_verification_tag(nil)
37
+ # # => <!-- TradeDoubler site verification -->
38
+ #
39
+ def tradedoubler_verification_tag(publisher_id)
40
+ "<!-- TradeDoubler site verification #{publisher_id.to_s} -->"
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,125 @@
1
+ #
2
+ # = Helperful
3
+ #
4
+ # A collection of useful Rails helpers.
5
+ #
6
+ #
7
+ # Category:: Rails
8
+ # Package:: Helperful
9
+ # Author:: Simone Carletti <weppos@weppos.net>
10
+ # Copyright:: 2008-2009 The Authors
11
+ # License:: MIT License
12
+ #
13
+ #--
14
+ #
15
+ #++
16
+
17
+
18
+ module Helperful
19
+
20
+ #
21
+ # = Content Helper
22
+ #
23
+ # Provides a set of helpers for capturing and working with your page content
24
+ # in a more effective way.
25
+ #
26
+ # ==== Requires
27
+ #
28
+ # The following requirements are mandatory for this module.
29
+ # Including this helper will automatically include them unless already included.
30
+ #
31
+ # * ActionView::Helpers::CaptureHelper
32
+ #
33
+ module ContentHelper
34
+
35
+ def self.included(base)
36
+ base.class_eval do
37
+ base.included_modules.include?(ActionView::Helpers::CaptureHelper) || include(ActionView::Helpers::CaptureHelper)
38
+ alias_method_chain :content_for, :has
39
+ end
40
+ end
41
+
42
+ #
43
+ # Evaluates the content of <tt>block</tt> and stores the result as <tt>content_for :sidebar</tt>.
44
+ #
45
+ # Because <tt>content_for</tt> concatenates the block, you can call <tt>sidebar</tt> multiple time
46
+ # and yield all the final content once.
47
+ #
48
+ # See <tt>ActionView::Helpers::CaptureHelper#content_for</tt> for the full API documentation.
49
+ #
50
+ # ==== Examples
51
+ #
52
+ # <% sidebar do %>
53
+ # <p>Sidebar</p>
54
+ # <% end %>
55
+ #
56
+ # <%= yield :sidebar %>
57
+ # # => <p>Sidebar</p>
58
+ #
59
+ def sidebar(&block)
60
+ content_for :sidebar, &block
61
+ end
62
+
63
+ #
64
+ # Returns <tt>true</tt> if <tt>name</tt> has any content,
65
+ # in other workds if content_for(name) has ever been called.
66
+ #
67
+ # ==== Important
68
+ #
69
+ # Some important details to keep in mind.
70
+ #
71
+ # Due to the way <tt>content_for</tt> stores data, it doesn't matter
72
+ # whether name is a Symbol or a String.
73
+ # They are treated in the same way. The following calls are equivalent.
74
+ #
75
+ # has_content? :foo # => true
76
+ # has_content? "foo" # => true
77
+ #
78
+ # This method doesn't make any difference between an empty,
79
+ # blank or nil content. It always returns <tt>true</tt> if
80
+ # <tt>content_for</tt> has been called with <tt>name</tt>,
81
+ # it doesn't matter which content is stored.
82
+ # A call to <tt>has_content?</tt> will always return true
83
+ # in any of the following cases:
84
+ #
85
+ # content_for :name, nil
86
+ # content_for :name, ''
87
+ # content_for :name, []
88
+ # content_for :name, 'A real content'
89
+ # content_for :name do
90
+ # "nothing here"
91
+ # end
92
+ #
93
+ def has_content?(name)
94
+ @has_content.key?(name.to_s)
95
+ end
96
+
97
+ # Flags +name+ to ensure <tt>has_content?</tt> will work as expected.
98
+ # You would probably never call this method directly.
99
+ # In fact, you are encouraged to not do so.
100
+ def has_content!(name) # :nodoc:
101
+ @has_content ||= {}
102
+ @has_content[name.to_s] = true
103
+ end
104
+
105
+ #
106
+ # Despite its name, this method is a transparent replacement for
107
+ # the original <tt>content_for</tt> Rails helper.
108
+ #
109
+ # It forwards any request to the original Rails helper,
110
+ # but before it keep tracks of every request to ensure <tt>has_content?</tt>
111
+ # will work as expected.
112
+ #
113
+ # == Behind this original name
114
+ #
115
+ # For those of you interested in, this name arises from the need
116
+ # to chain it with <tt>alias_method_chain</tt>, following
117
+ # Rails best practice for extending original core methods.
118
+ #
119
+ def content_for_with_has(*args, &block) # :nodoc:
120
+ has_content!(args.first)
121
+ content_for_without_has(*args, &block)
122
+ end
123
+
124
+ end
125
+ end
@@ -0,0 +1,26 @@
1
+ #
2
+ # = Helperful
3
+ #
4
+ # A collection of useful Rails helpers.
5
+ #
6
+ #
7
+ # Category:: Rails
8
+ # Package:: Helperful
9
+ # Author:: Simone Carletti <weppos@weppos.net>
10
+ # Copyright:: 2008-2009 The Authors
11
+ # License:: MIT License
12
+ #
13
+ #--
14
+ #
15
+ #++
16
+
17
+
18
+ unless defined?(TitleHelper)
19
+ module TitleHelper
20
+ def self.included(base)
21
+ ActiveSupport::Deprecation.warn("TitleHelper is deprecated and will be removed in a future version. " +
22
+ "Please include Helperful::TitleHelper instead.", caller)
23
+ base.send :include, Helperful::TitleHelper
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,79 @@
1
+ #
2
+ # = Helperful
3
+ #
4
+ # A collection of useful Rails helpers.
5
+ #
6
+ #
7
+ # Category:: Rails
8
+ # Package:: Helperful
9
+ # Author:: Simone Carletti <weppos@weppos.net>
10
+ # Copyright:: 2008-2009 The Authors
11
+ # License:: MIT License
12
+ #
13
+ #--
14
+ #
15
+ #++
16
+
17
+
18
+ module Helperful
19
+
20
+ #
21
+ # = Title Helper
22
+ #
23
+ # This module provides an helper for managing page title in Rails views and layouts.
24
+ #
25
+ module TitleHelper
26
+
27
+ #
28
+ # = Title Helper
29
+ #
30
+ # This helper provides both input and output capabilities
31
+ # for managing page title in Rails views and layouts.
32
+ #
33
+ # When called with +args+, it stores all args for later retrieval.
34
+ # Additionally, it always return a formatted title so that
35
+ # it can be easily called without arguments to display the full page title.
36
+ #
37
+ # You can pass some additional options to customize the behavior of the returned string.
38
+ # The following options are supported:
39
+ #
40
+ # :separator::
41
+ # the separator used to join all title elements, by default a dash.
42
+ #
43
+ # :site::
44
+ # the name of the site to be appended to page title.
45
+ #
46
+ # :headline::
47
+ # website headline to be appended to page title, after any element.
48
+ #
49
+ # ==== Examples
50
+ #
51
+ # # in a template set the title of the page
52
+ # <h1><%= title "Latest news" %></h1>
53
+ # # => <h1>Latest news</h1>
54
+ #
55
+ # # in the layout print the title of the page
56
+ # # with the name of the site
57
+ # <title><%= title :site => 'My Site' %></title>
58
+ # # => <title>Latest news | My Site</title>
59
+ #
60
+ def title(*args)
61
+ @helperful_title ||= []
62
+ @helperful_title_options ||= {
63
+ :separator => ' - ',
64
+ :headline => nil,
65
+ :site => nil,
66
+ }
67
+ options = args.extract_options!
68
+
69
+ @helperful_title += args
70
+ @helperful_title_options.merge!(options)
71
+
72
+ t = @helperful_title.clone
73
+ t << @helperful_title_options[:site]
74
+ t << @helperful_title_options[:headline]
75
+ t.compact.join(@helperful_title_options[:separator])
76
+ end
77
+
78
+ end
79
+ end
@@ -0,0 +1,32 @@
1
+ #
2
+ # = Helperful
3
+ #
4
+ # A collection of useful Rails helpers.
5
+ #
6
+ #
7
+ # Category:: Rails
8
+ # Package:: Helperful
9
+ # Author:: Simone Carletti <weppos@weppos.net>
10
+ # Copyright:: 2008-2009 The Authors
11
+ # License:: MIT License
12
+ #
13
+ #--
14
+ #
15
+ #++
16
+
17
+
18
+ module Helperful
19
+
20
+ module Version
21
+ MAJOR = 0
22
+ MINOR = 2
23
+ TINY = 0
24
+
25
+ STRING = [MAJOR, MINOR, TINY].join('.')
26
+ end
27
+
28
+ VERSION = Version::STRING
29
+ STATUS = 'alpha'
30
+ BUILD = ''.match(/(\d+)/).to_a.first
31
+
32
+ end
data/lib/helperful.rb ADDED
@@ -0,0 +1,46 @@
1
+ #
2
+ # = Helperful
3
+ #
4
+ # A collection of useful Rails helpers.
5
+ #
6
+ #
7
+ # Category:: Rails
8
+ # Package:: Helperful
9
+ # Author:: Simone Carletti <weppos@weppos.net>
10
+ # Copyright:: 2008-2009 The Authors
11
+ # License:: MIT License
12
+ #
13
+ #--
14
+ #
15
+ #++
16
+
17
+
18
+ Dir.glob(File.dirname(__FILE__) + '/helperful/*_helper.rb').each { |helper| require helper }
19
+ require 'helperful/deprecations'
20
+ require 'helperful/version'
21
+
22
+
23
+ module Helperful
24
+
25
+ NAME = 'Helperful'
26
+ GEM = 'helperful'
27
+ AUTHOR = 'Simone Carletti <weppos@weppos.net>'
28
+
29
+
30
+ module ControllerMixin
31
+
32
+ def helperful(*args, &block)
33
+ args.flatten.each do |arg|
34
+ case arg
35
+ when String, Symbol
36
+ file_name = 'helperful/' + arg.to_s.underscore
37
+ helper(file_name)
38
+ else
39
+ helper(arg, &block)
40
+ end
41
+ end
42
+ end
43
+
44
+ end
45
+
46
+ end
data/rails/init.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'helperful'
2
+
3
+ ActionController::Base.extend Helperful::ControllerMixin
4
+
5
+ RAILS_DEFAULT_LOGGER.info("** Helperful: initialized properly") if defined?(RAILS_DEFAULT_LOGGER)
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :helperful do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,12 @@
1
+ require 'test_helper'
2
+
3
+ class AffiliationsHelperTest < ActionView::TestCase
4
+ tests Helperful::AffiliationsHelper
5
+
6
+ def test_tradedoubler_verification_tag
7
+ assert_equal('<!-- TradeDoubler site verification 112233 -->', tradedoubler_verification_tag('112233'))
8
+ assert_equal('<!-- TradeDoubler site verification 112233 -->', tradedoubler_verification_tag(112233))
9
+ assert_equal('<!-- TradeDoubler site verification -->', tradedoubler_verification_tag(nil))
10
+ end
11
+
12
+ end
@@ -0,0 +1,71 @@
1
+ require 'test_helper'
2
+
3
+ class ContentController < ActionController::Base
4
+ def self.controller_name; "content"; end
5
+ def self.controller_path; "content"; end
6
+
7
+ helperful "content"
8
+
9
+ def sidebar
10
+ render :layout => "sidebar"
11
+ end
12
+
13
+ def sidebar_concatenate
14
+ render :layout => "sidebar"
15
+ end
16
+
17
+ def has_content
18
+ render :layout => "has_content"
19
+ end
20
+
21
+ def rescue_action(e) raise end
22
+ end
23
+
24
+ ContentController.view_paths = [ File.dirname(__FILE__) + "/fixtures/" ]
25
+
26
+
27
+ class ContentTest < ActiveSupport::TestCase
28
+
29
+ def setup
30
+ @controller = ContentController.new
31
+ @request = ActionController::TestRequest.new
32
+ @response = ActionController::TestResponse.new
33
+
34
+ @request.host = "test.host"
35
+ end
36
+
37
+ def test_sidebar
38
+ get :sidebar
39
+ assert_equal expected_sidebar_content_for_output, @response.body
40
+ end
41
+
42
+ def test_sidebar_concatenate
43
+ get :sidebar_concatenate
44
+ assert_equal expected_sidebar_content_for_output, @response.body
45
+ end
46
+
47
+ def test_has_content
48
+ get :has_content
49
+ assert_equal %Q{
50
+ `one' has content: this is :one for :one\n
51
+ `two' has content: this is 'two' for 'two'\n
52
+ \n
53
+ `four' has content: this is 'four' for :four\n
54
+ `five' has content: this is 'five' for :five\n}, @response.body
55
+ end
56
+
57
+ protected
58
+
59
+ def expected_sidebar_content_for_output
60
+ <<-EOS
61
+ <title>This is the title</title>
62
+ <div id="first">
63
+ <p>First Sidebar</p>
64
+ </div>
65
+ <div id="second">
66
+ <p>Second Sidebar</p>
67
+ </div>
68
+ EOS
69
+ end
70
+
71
+ end
@@ -0,0 +1,4 @@
1
+ <% content_for :one, "this is :one for :one" -%>
2
+ <% content_for 'two', "this is 'two' for 'two'" -%>
3
+ <% content_for 'four', "this is 'four' for :four" -%>
4
+ <% content_for 'five' do %>this is 'five' for :five<% end %>
@@ -0,0 +1,8 @@
1
+ <% sidebar do -%>
2
+ <div id="first">
3
+ <p>First Sidebar</p>
4
+ </div>
5
+ <div id="second">
6
+ <p>Second Sidebar</p>
7
+ </div>
8
+ <% end %>
@@ -0,0 +1,10 @@
1
+ <% sidebar do -%>
2
+ <div id="first">
3
+ <p>First Sidebar</p>
4
+ </div>
5
+ <% end %>
6
+ <% sidebar do -%>
7
+ <div id="second">
8
+ <p>Second Sidebar</p>
9
+ </div>
10
+ <% end %>
@@ -0,0 +1,3 @@
1
+ <% for name in [:one, 'two', :three, :four, :five] %>
2
+ <% if has_content? name %>`<%= name %>' has content: <%= yield name %><% end %>
3
+ <% end %>
@@ -0,0 +1,2 @@
1
+ <title>This is the title</title>
2
+ <%= yield :sidebar %>
@@ -0,0 +1,55 @@
1
+ require 'test_helper'
2
+
3
+ class HelperfulController < ActionController::Base
4
+ end
5
+
6
+ %w(First Second Third).each do |name|
7
+ class_eval <<-RUBY
8
+ module Helperful::#{name}Helper
9
+ end
10
+ RUBY
11
+ end
12
+
13
+
14
+ class HelperfulTest < Test::Unit::TestCase
15
+
16
+ def setup
17
+ @controller = HelperfulController
18
+ end
19
+
20
+ def test_helperful_should_delegate_module
21
+ @controller.expects(:helper).with(Helperful::FirstHelper)
22
+ @controller.helperful(Helperful::FirstHelper)
23
+ end
24
+
25
+ def test_helperful_should_delegate_modules
26
+ @controller.expects(:helper).with(Helperful::FirstHelper)
27
+ @controller.expects(:helper).with(Helperful::SecondHelper)
28
+ @controller.helperful(Helperful::FirstHelper, Helperful::SecondHelper)
29
+ end
30
+
31
+ def test_helperful_should_prepend_namespace_and_delegate_string_symbol
32
+ @controller.expects(:helper).with('helperful/first')
33
+ @controller.helperful('first')
34
+
35
+ @controller.expects(:helper).with('helperful/first')
36
+ @controller.helperful(:first)
37
+ end
38
+
39
+ def test_helperful_should_prepend_namespace_and_delegate_strings_symbols
40
+ @controller.expects(:helper).with('helperful/first')
41
+ @controller.helperful('first')
42
+
43
+ @controller.expects(:helper).with('helperful/first')
44
+ @controller.helperful(:first)
45
+
46
+ @controller.expects(:helper).with('helperful/first')
47
+ @controller.expects(:helper).with('helperful/second')
48
+ @controller.helperful('first', 'second')
49
+
50
+ @controller.expects(:helper).with('helperful/first')
51
+ @controller.expects(:helper).with('helperful/second')
52
+ @controller.helperful(:first, :second)
53
+ end
54
+
55
+ end
@@ -0,0 +1,37 @@
1
+ #
2
+ # = Helperful
3
+ #
4
+ # A collection of useful Rails helpers.
5
+ #
6
+ #
7
+ # Category:: Rails
8
+ # Package:: Helperful
9
+ # Author:: Simone Carletti <weppos@weppos.net>
10
+ # Copyright:: 2008-2009 The Authors
11
+ # License:: MIT License
12
+ #
13
+ #--
14
+ #
15
+ #++
16
+
17
+
18
+ require 'test/unit'
19
+ require 'rubygems'
20
+ require 'mocha'
21
+ require 'active_support'
22
+ require 'action_controller'
23
+ require 'action_controller/cgi_ext'
24
+ require 'action_controller/test_process'
25
+ require 'action_view/test_case'
26
+
27
+ $:.unshift File.dirname(__FILE__) + '/../lib'
28
+ require File.dirname(__FILE__) + '/../init.rb'
29
+
30
+ RAILS_ROOT = '.' unless defined? RAILS_ROOT
31
+ RAILS_ENV = 'test' unless defined? RAILS_ENV
32
+
33
+ ActionController::Base.logger = nil
34
+ ActionController::Routing::Routes.reload rescue nil
35
+
36
+ # Unit tests for Helpers are based on unit tests created and developed by Rails core team.
37
+ # See action_pack/test/abstract_unit for more details.
@@ -0,0 +1,69 @@
1
+ require 'test_helper'
2
+
3
+ class HelperfulTitleHelperTest < ActionView::TestCase
4
+ tests Helperful::TitleHelper
5
+
6
+ def setup
7
+ reset!
8
+ end
9
+
10
+ def test_title_should_accepts_zero_or_more_params
11
+ assert_nothing_raised { title }
12
+ assert_nothing_raised { title('One') }
13
+ assert_nothing_raised { title('One', 'Two', 'Three') }
14
+ end
15
+
16
+ def test_title_should_return_content
17
+ assert_equal('', title)
18
+ assert_equal('One', title('One'))
19
+ end
20
+
21
+ def test_title_should_return_empty_string_if_empty
22
+ assert_equal('', title)
23
+ end
24
+
25
+ def test_title_should_store_content
26
+ assert_equal('', title)
27
+ assert_equal('One', title('One'))
28
+ assert_equal('One', title)
29
+ end
30
+
31
+ def test_title_should_join_content
32
+ assert_equal('', title)
33
+ assert_equal('One', title('One'))
34
+ assert_equal('One - Two', title('Two'))
35
+ assert_equal('One - Two - Three - Four', title('Three', 'Four'))
36
+ end
37
+
38
+ def test_title_should_join_content_with_separator
39
+ assert_equal('One - Two', title('One', 'Two'))
40
+ assert_equal('One | Two', title(:separator => ' | '))
41
+ assert_equal('One x Two x Three', title('Three', :separator => ' x '))
42
+ end
43
+
44
+ def test_title_should_append_headline_to_content
45
+ assert_equal('One - Two', title('One', 'Two'))
46
+ assert_equal('One - Two - Cool!', title(:headline => 'Cool!'))
47
+ assert_equal('One - Two - Three - Yeah!', title('Three', :headline => 'Yeah!'))
48
+ end
49
+
50
+ def test_title_should_append_site_to_content
51
+ assert_equal('One - Two', title('One', 'Two'))
52
+ assert_equal('One - Two - Cool!', title(:site => 'Cool!'))
53
+ assert_equal('One - Two - Three - Yeah!', title('Three', :site => 'Yeah!'))
54
+ end
55
+
56
+ def test_title_should_append_site_then_headline
57
+ assert_equal('One - Two', title('One', 'Two'))
58
+ assert_equal('One - Two - Cool!', title(:site => 'Cool!'))
59
+ assert_equal('One - Two - Cool! - Yeah!', title(:headline => 'Yeah!'))
60
+ end
61
+
62
+
63
+ protected
64
+
65
+ def reset!
66
+ title(nil)
67
+ end
68
+
69
+ end
data/uninstall.rb ADDED
@@ -0,0 +1 @@
1
+ # Uninstall hook code here
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: weppos-helperful
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Simone Carletti
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-02-25 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rake
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0.8"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: echoe
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "3.1"
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: mocha
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0.9"
44
+ version:
45
+ description: Helperful aims to be a collection of useful and reusable Rails helpers.
46
+ email: weppos@weppos.net
47
+ executables: []
48
+
49
+ extensions: []
50
+
51
+ extra_rdoc_files:
52
+ - CHANGELOG.rdoc
53
+ - lib/helperful/affiliations_helper.rb
54
+ - lib/helperful/content_helper.rb
55
+ - lib/helperful/deprecations.rb
56
+ - lib/helperful/title_helper.rb
57
+ - lib/helperful/version.rb
58
+ - lib/helperful.rb
59
+ - LICENSE.rdoc
60
+ - README.rdoc
61
+ files:
62
+ - CHANGELOG.rdoc
63
+ - init.rb
64
+ - install.rb
65
+ - lib/helperful/affiliations_helper.rb
66
+ - lib/helperful/content_helper.rb
67
+ - lib/helperful/deprecations.rb
68
+ - lib/helperful/title_helper.rb
69
+ - lib/helperful/version.rb
70
+ - lib/helperful.rb
71
+ - LICENSE.rdoc
72
+ - rails/init.rb
73
+ - Rakefile
74
+ - README.rdoc
75
+ - tasks/helperful_tasks.rake
76
+ - test/affiliations_helper_test.rb
77
+ - test/content_helper_test.rb
78
+ - test/fixtures/content/has_content.html.erb
79
+ - test/fixtures/content/sidebar.html.erb
80
+ - test/fixtures/content/sidebar_concatenate.html.erb
81
+ - test/fixtures/layouts/has_content.html.erb
82
+ - test/fixtures/layouts/sidebar.html.erb
83
+ - test/helperful_test.rb
84
+ - test/test_helper.rb
85
+ - test/title_helper_test.rb
86
+ - uninstall.rb
87
+ - Manifest
88
+ - helperful.gemspec
89
+ has_rdoc: true
90
+ homepage: http://code.simonecarletti.com/helperful
91
+ post_install_message:
92
+ rdoc_options:
93
+ - --line-numbers
94
+ - --inline-source
95
+ - --title
96
+ - Helperful
97
+ - --main
98
+ - README.rdoc
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: "0"
106
+ version:
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: "1.2"
112
+ version:
113
+ requirements: []
114
+
115
+ rubyforge_project:
116
+ rubygems_version: 1.2.0
117
+ signing_key:
118
+ specification_version: 2
119
+ summary: A collection of useful Rails helpers.
120
+ test_files:
121
+ - test/affiliations_helper_test.rb
122
+ - test/content_helper_test.rb
123
+ - test/helperful_test.rb
124
+ - test/test_helper.rb
125
+ - test/title_helper_test.rb