weppos-helperful 0.2.2 → 0.3.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 +9 -0
- data/README.rdoc +42 -2
- data/helperful.gemspec +5 -5
- data/lib/helperful/content_helper.rb +1 -0
- data/lib/helperful/javascript_helper.rb +84 -0
- data/lib/helperful/version.rb +2 -2
- data/test/content_helper_test.rb +11 -1
- data/test/fixtures/content/has_content_is_called_alone.html.erb +1 -0
- data/test/javascript_helper_test.rb +53 -0
- data/test/test_helper.rb +3 -1
- metadata +8 -3
data/CHANGELOG.rdoc
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
= Changelog
|
|
2
2
|
|
|
3
3
|
|
|
4
|
+
== Release 0.3.0
|
|
5
|
+
|
|
6
|
+
* ADDED: Added #javascript_content_for helper. #javascript_content_for combines the features of #content_for and #javascript_tag (closes #149).
|
|
7
|
+
|
|
8
|
+
* FIXED: has_content? raises an error when has_content isn't initialized (closes #179).
|
|
9
|
+
|
|
10
|
+
* CHANGED: Changed status to alpha and removed development warning (closes #151).
|
|
11
|
+
|
|
12
|
+
|
|
4
13
|
== Release 0.2.2
|
|
5
14
|
|
|
6
15
|
* FIXED: The "Unhandled special" error message for real!
|
data/README.rdoc
CHANGED
|
@@ -2,8 +2,30 @@
|
|
|
2
2
|
|
|
3
3
|
Helperful aims to be a collection of useful and reusable Rails helpers.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
|
|
6
|
+
== Rails Installation
|
|
7
|
+
|
|
8
|
+
=== As a Gem
|
|
9
|
+
|
|
10
|
+
This is the preferred way to install Helperful and the best way if you want install a stable version.
|
|
11
|
+
|
|
12
|
+
$ gem install weppos-helperful --source http://gems.github.com
|
|
13
|
+
|
|
14
|
+
You can specify the GEM dependency in your application environment.rb file:
|
|
15
|
+
|
|
16
|
+
Rails::Initializer.run do |config|
|
|
17
|
+
|
|
18
|
+
# other configurations
|
|
19
|
+
|
|
20
|
+
config.gem "weppos-helperful", :lib => "helperful", :source => "http://gems.github.com"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
=== As a Plugin
|
|
25
|
+
|
|
26
|
+
This is the preferred way if you want to live on the edge and install a development version.
|
|
27
|
+
|
|
28
|
+
$ script/plugin install git://github.com/weppos/helperful.git
|
|
7
29
|
|
|
8
30
|
|
|
9
31
|
== Getting Started
|
|
@@ -126,6 +148,24 @@ The <tt>has_content?</tt> helper is a natural fulfillment for the original <tt>c
|
|
|
126
148
|
<% has_content? :foo # => true %>
|
|
127
149
|
<% has_content? "foo" # => true %>
|
|
128
150
|
|
|
151
|
+
|
|
152
|
+
=== Javascript Helper
|
|
153
|
+
|
|
154
|
+
Provides a set of helpers for working with JavaScript in your views.
|
|
155
|
+
|
|
156
|
+
The <tt>javascript_content_for</tt> helper combines the features of <tt>content_for</tt> and <tt>javascript_tag</tt> into a single helper.
|
|
157
|
+
|
|
158
|
+
<% javascript_content_for :head do %>
|
|
159
|
+
$("#id").hide();
|
|
160
|
+
<% end %>
|
|
161
|
+
|
|
162
|
+
The code above looks like much more readable than the following one. Isn't it?
|
|
163
|
+
|
|
164
|
+
<% javascript_content_for :head do; javascript_tag do %>
|
|
165
|
+
$("#id").hide();
|
|
166
|
+
<% end; end %>
|
|
167
|
+
|
|
168
|
+
|
|
129
169
|
=== Title Helper
|
|
130
170
|
|
|
131
171
|
Provides an helper for managing page title in Rails views and layouts.
|
data/helperful.gemspec
CHANGED
|
@@ -2,22 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
Gem::Specification.new do |s|
|
|
4
4
|
s.name = %q{helperful}
|
|
5
|
-
s.version = "0.
|
|
5
|
+
s.version = "0.3.0"
|
|
6
6
|
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
|
8
8
|
s.authors = ["Simone Carletti"]
|
|
9
|
-
s.date = %q{2009-
|
|
9
|
+
s.date = %q{2009-03-11}
|
|
10
10
|
s.description = %q{Helperful aims to be a collection of useful and reusable Rails helpers.}
|
|
11
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", "helperful.gemspec", "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/
|
|
12
|
+
s.extra_rdoc_files = ["CHANGELOG.rdoc", "lib/helperful/affiliations_helper.rb", "lib/helperful/content_helper.rb", "lib/helperful/deprecations.rb", "lib/helperful/javascript_helper.rb", "lib/helperful/title_helper.rb", "lib/helperful/version.rb", "lib/helperful.rb", "LICENSE.rdoc", "README.rdoc"]
|
|
13
|
+
s.files = ["CHANGELOG.rdoc", "helperful.gemspec", "init.rb", "install.rb", "lib/helperful/affiliations_helper.rb", "lib/helperful/content_helper.rb", "lib/helperful/deprecations.rb", "lib/helperful/javascript_helper.rb", "lib/helperful/title_helper.rb", "lib/helperful/version.rb", "lib/helperful.rb", "LICENSE.rdoc", "Manifest", "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/has_content_is_called_alone.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/javascript_helper_test.rb", "test/test_helper.rb", "test/title_helper_test.rb", "uninstall.rb"]
|
|
14
14
|
s.has_rdoc = true
|
|
15
15
|
s.homepage = %q{http://code.simonecarletti.com/helperful}
|
|
16
16
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Helperful", "--main", "README.rdoc"]
|
|
17
17
|
s.require_paths = ["lib"]
|
|
18
18
|
s.rubygems_version = %q{1.3.1}
|
|
19
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"]
|
|
20
|
+
s.test_files = ["test/affiliations_helper_test.rb", "test/content_helper_test.rb", "test/helperful_test.rb", "test/javascript_helper_test.rb", "test/test_helper.rb", "test/title_helper_test.rb"]
|
|
21
21
|
|
|
22
22
|
if s.respond_to? :specification_version then
|
|
23
23
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
|
@@ -0,0 +1,84 @@
|
|
|
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
|
+
# = Javascript Helper
|
|
22
|
+
#
|
|
23
|
+
# Provides a set of helpers for working with JavaScript in your views.
|
|
24
|
+
#
|
|
25
|
+
# ==== Requires
|
|
26
|
+
#
|
|
27
|
+
# The following requirements are mandatory for this module.
|
|
28
|
+
# Including this helper will automatically include them unless already included.
|
|
29
|
+
#
|
|
30
|
+
# * ActionView::Helpers::CaptureHelper
|
|
31
|
+
# * ActionView::Helpers::JavaScriptHelper
|
|
32
|
+
#
|
|
33
|
+
module JavascriptHelper
|
|
34
|
+
|
|
35
|
+
def self.included(base)
|
|
36
|
+
base.class_eval do
|
|
37
|
+
# base.included_modules.include?(ActionView::Helpers::CaptureHelper) || include(ActionView::Helpers::CaptureHelper)
|
|
38
|
+
# base.included_modules.include?(ActionView::Helpers::JavaScriptHelper) || include(ActionView::Helpers::JavaScriptHelper)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
#
|
|
43
|
+
# Mixes the features of <tt>content_for</tt> and <tt>javascript_tag</tt> into a single helper.
|
|
44
|
+
#
|
|
45
|
+
# Supports all original method options and features, including the ability to use write the content
|
|
46
|
+
# in a block and javascript tag options.
|
|
47
|
+
#
|
|
48
|
+
# ==== Examples
|
|
49
|
+
#
|
|
50
|
+
# <% javascript_content_for :head do %>
|
|
51
|
+
# $("#id").hide();
|
|
52
|
+
# <% end %>
|
|
53
|
+
#
|
|
54
|
+
# The block is passed as it is to <tt>javascript_tag</tt>,
|
|
55
|
+
# then the result is stored as <tt>content_for</tt> :head.
|
|
56
|
+
# Now you can call <tt>yield</tt> and output your javascript content.
|
|
57
|
+
#
|
|
58
|
+
# <%= yield :head %>
|
|
59
|
+
#
|
|
60
|
+
# <script>$("#id").hide();</script>
|
|
61
|
+
#
|
|
62
|
+
# This example is equal to the following statements.
|
|
63
|
+
#
|
|
64
|
+
# <% javascript_content_for :head do; javascript_tag do %>
|
|
65
|
+
# $("#id").hide();
|
|
66
|
+
# <% end; end %>
|
|
67
|
+
#
|
|
68
|
+
# <% javascript_content_for :head do %>
|
|
69
|
+
# <script>$("#id").hide();</script>
|
|
70
|
+
# <% end %>
|
|
71
|
+
#
|
|
72
|
+
# You can make subsequent calls to <tt>javascript_content_for</tt> and <tt>content_for</tt>,
|
|
73
|
+
# the result for each call will be appended to the value currently stored for <tt>name</tt>.
|
|
74
|
+
#
|
|
75
|
+
def javascript_content_for(name, content_or_options_with_block = nil, html_options = {}, &block)
|
|
76
|
+
if block_given?
|
|
77
|
+
content_for(name, javascript_tag(content_or_options_with_block, &block))
|
|
78
|
+
else
|
|
79
|
+
content_for(name, javascript_tag(content_or_options_with_block, html_options))
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
end
|
|
84
|
+
end
|
data/lib/helperful/version.rb
CHANGED
data/test/content_helper_test.rb
CHANGED
|
@@ -17,7 +17,11 @@ class ContentController < ActionController::Base
|
|
|
17
17
|
def has_content
|
|
18
18
|
render :layout => "has_content"
|
|
19
19
|
end
|
|
20
|
-
|
|
20
|
+
|
|
21
|
+
def has_content_is_called_alone
|
|
22
|
+
render :layout => false
|
|
23
|
+
end
|
|
24
|
+
|
|
21
25
|
def rescue_action(e) raise end
|
|
22
26
|
end
|
|
23
27
|
|
|
@@ -54,6 +58,12 @@ class ContentTest < ActiveSupport::TestCase
|
|
|
54
58
|
`five' has content: this is 'five' for :five\n}, @response.body
|
|
55
59
|
end
|
|
56
60
|
|
|
61
|
+
def test_has_content_is_called_alone
|
|
62
|
+
get :has_content_is_called_alone
|
|
63
|
+
assert_response :success
|
|
64
|
+
assert_equal('bar', @response.body)
|
|
65
|
+
end
|
|
66
|
+
|
|
57
67
|
protected
|
|
58
68
|
|
|
59
69
|
def expected_sidebar_content_for_output
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<% if has_content? :foo %>foo<% end %><% if !has_content? :bar %>bar<% end %>
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class JavascriptHelperTest < ActionView::TestCase
|
|
4
|
+
tests Helperful::JavascriptHelper
|
|
5
|
+
|
|
6
|
+
attr_accessor :output_buffer
|
|
7
|
+
|
|
8
|
+
def setup
|
|
9
|
+
@content_for_name = nil
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def test_javascript_content_for
|
|
13
|
+
javascript_content_for(:name, "alert('hello')")
|
|
14
|
+
|
|
15
|
+
assert_dom_equal "<script type=\"text/javascript\">\n//<![CDATA[\nalert('hello')\n//]]>\n</script>",
|
|
16
|
+
@content_for_name
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def test_javascript_content_for_with_options
|
|
20
|
+
javascript_content_for(:name, "alert('hello')", :id => "the_js_tag")
|
|
21
|
+
|
|
22
|
+
assert_dom_equal "<script id=\"the_js_tag\" type=\"text/javascript\">\n//<![CDATA[\nalert('hello')\n//]]>\n</script>",
|
|
23
|
+
@content_for_name
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def test_javascript_content_for_with_block_in_erb
|
|
27
|
+
__in_erb_template = ''
|
|
28
|
+
javascript_content_for(:name) { concat "alert('hello')" }
|
|
29
|
+
|
|
30
|
+
assert_dom_equal "<script type=\"text/javascript\">\n//<![CDATA[\nalert('hello')\n//]]>\n</script>",
|
|
31
|
+
@content_for_name
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def test_javascript_content_for_with_block_in_erb_and_options
|
|
35
|
+
__in_erb_template = ''
|
|
36
|
+
javascript_content_for(:name, :id => "the_js_tag") { concat "alert('hello')" }
|
|
37
|
+
|
|
38
|
+
assert_dom_equal "<script id=\"the_js_tag\" type=\"text/javascript\">\n//<![CDATA[\nalert('hello')\n//]]>\n</script>",
|
|
39
|
+
@content_for_name
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def test_javascript_content_for_with_subsequent_calls
|
|
43
|
+
javascript_content_for(:name, "alert('hello')")
|
|
44
|
+
javascript_content_for(:name, "alert('world')")
|
|
45
|
+
|
|
46
|
+
expected = "<script type=\"text/javascript\">\n//<![CDATA[\nalert('hello')\n//]]>\n</script>"
|
|
47
|
+
expected += "<script type=\"text/javascript\">\n//<![CDATA[\nalert('world')\n//]]>\n</script>"
|
|
48
|
+
|
|
49
|
+
assert_dom_equal expected,
|
|
50
|
+
@content_for_name
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: weppos-helperful
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Simone Carletti
|
|
@@ -9,7 +9,7 @@ autorequire:
|
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
11
|
|
|
12
|
-
date: 2009-
|
|
12
|
+
date: 2009-03-11 00:00:00 -07:00
|
|
13
13
|
default_executable:
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
@@ -53,6 +53,7 @@ extra_rdoc_files:
|
|
|
53
53
|
- lib/helperful/affiliations_helper.rb
|
|
54
54
|
- lib/helperful/content_helper.rb
|
|
55
55
|
- lib/helperful/deprecations.rb
|
|
56
|
+
- lib/helperful/javascript_helper.rb
|
|
56
57
|
- lib/helperful/title_helper.rb
|
|
57
58
|
- lib/helperful/version.rb
|
|
58
59
|
- lib/helperful.rb
|
|
@@ -66,10 +67,12 @@ files:
|
|
|
66
67
|
- lib/helperful/affiliations_helper.rb
|
|
67
68
|
- lib/helperful/content_helper.rb
|
|
68
69
|
- lib/helperful/deprecations.rb
|
|
70
|
+
- lib/helperful/javascript_helper.rb
|
|
69
71
|
- lib/helperful/title_helper.rb
|
|
70
72
|
- lib/helperful/version.rb
|
|
71
73
|
- lib/helperful.rb
|
|
72
74
|
- LICENSE.rdoc
|
|
75
|
+
- Manifest
|
|
73
76
|
- rails/init.rb
|
|
74
77
|
- Rakefile
|
|
75
78
|
- README.rdoc
|
|
@@ -77,15 +80,16 @@ files:
|
|
|
77
80
|
- test/affiliations_helper_test.rb
|
|
78
81
|
- test/content_helper_test.rb
|
|
79
82
|
- test/fixtures/content/has_content.html.erb
|
|
83
|
+
- test/fixtures/content/has_content_is_called_alone.html.erb
|
|
80
84
|
- test/fixtures/content/sidebar.html.erb
|
|
81
85
|
- test/fixtures/content/sidebar_concatenate.html.erb
|
|
82
86
|
- test/fixtures/layouts/has_content.html.erb
|
|
83
87
|
- test/fixtures/layouts/sidebar.html.erb
|
|
84
88
|
- test/helperful_test.rb
|
|
89
|
+
- test/javascript_helper_test.rb
|
|
85
90
|
- test/test_helper.rb
|
|
86
91
|
- test/title_helper_test.rb
|
|
87
92
|
- uninstall.rb
|
|
88
|
-
- Manifest
|
|
89
93
|
has_rdoc: true
|
|
90
94
|
homepage: http://code.simonecarletti.com/helperful
|
|
91
95
|
post_install_message:
|
|
@@ -121,5 +125,6 @@ test_files:
|
|
|
121
125
|
- test/affiliations_helper_test.rb
|
|
122
126
|
- test/content_helper_test.rb
|
|
123
127
|
- test/helperful_test.rb
|
|
128
|
+
- test/javascript_helper_test.rb
|
|
124
129
|
- test/test_helper.rb
|
|
125
130
|
- test/title_helper_test.rb
|