access_kit 0.02 → 0.03
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.
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'rails/all'
|
2
|
-
|
3
1
|
raise "ActionView::Helpers::UrlHelper not loaded!" unless defined?(ActionView::Helpers::UrlHelper)
|
4
2
|
raise "AccessKit::UrlHelperAdditions not loaded!" unless defined?(AccessKit::UrlHelperAdditions)
|
5
3
|
|
@@ -8,14 +6,16 @@ module ActionView
|
|
8
6
|
module UrlHelper
|
9
7
|
|
10
8
|
def link_to_with_supplement(*args, &block)
|
11
|
-
if
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
link_to_without_supplement(new_name, *args)
|
17
|
-
else
|
9
|
+
if block_given? ||
|
10
|
+
( new_args = AccessKit::UrlHelperAdditions.process_options_for_link_to_with_supplement(*args) ).nil?
|
11
|
+
# either a block was passed or
|
12
|
+
# the arguments did not include options for suplementary text
|
13
|
+
# so just pass through to original link_to without modification
|
18
14
|
link_to_without_supplement(*args, &block)
|
15
|
+
else
|
16
|
+
# call original link_to with new args which contain
|
17
|
+
# new name that includes supplementary text
|
18
|
+
link_to_without_supplement(*new_args)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
@@ -38,11 +38,22 @@ module AccessKit
|
|
38
38
|
)
|
39
39
|
end
|
40
40
|
|
41
|
+
# TODO: maybe rename to 'process_args'
|
41
42
|
def process_options_for_link_to_with_supplement(*args)
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
43
|
+
if args_for_link_to_with_supplement?(*args)
|
44
|
+
# TODO: move to separate method: 'extract_supplement_opts'
|
45
|
+
supplement_opts = [ DEFAULT_KEY_NAME_FOR_PRECEDING_TEXT, DEFAULT_KEY_NAME_FOR_FOLLOWING_TEXT, :auto_pad ].inject({}) do |memo, k|
|
46
|
+
value = args[2].delete(k)
|
47
|
+
value.blank? ? memo : memo.merge( k => value )
|
48
|
+
end
|
49
|
+
|
50
|
+
new_args = args.dup
|
51
|
+
# replace the name argument with new_name
|
52
|
+
new_args[0] = AccessKit::UrlHelperAdditions.add_supplement_to_text(args[0], supplement_opts)
|
53
|
+
new_args
|
54
|
+
else
|
55
|
+
nil
|
56
|
+
end
|
46
57
|
end
|
47
58
|
|
48
59
|
private
|
data/lib/access_kit/version.rb
CHANGED
@@ -13,8 +13,61 @@ module AccessKit
|
|
13
13
|
:intro => "Click to learn about"
|
14
14
|
).should == "<a href=\"#unicorns\"><span>Click to learn about </span>unicorns</a>"
|
15
15
|
end
|
16
|
+
|
17
|
+
context "#args_for_link_to_with_supplement?" do
|
18
|
+
context "should return true if :intro or :outro options are passed" do
|
19
|
+
UrlHelperAdditions.args_for_link_to_with_supplement?(
|
20
|
+
"unicorns",
|
21
|
+
'#unicorns',
|
22
|
+
:intro => "Click to learn about"
|
23
|
+
).should == true
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should return false if neither :intro nor :outro options are passed" do
|
27
|
+
UrlHelperAdditions.args_for_link_to_with_supplement?(
|
28
|
+
"unicorns",
|
29
|
+
'#unicorns'
|
30
|
+
).should == false
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should return false if a block is given" do
|
34
|
+
some_block = lambda{ 'link_name' }
|
35
|
+
UrlHelperAdditions.args_for_link_to_with_supplement?(
|
36
|
+
'#unicorns',
|
37
|
+
:intro => "Click to learn about",
|
38
|
+
&some_block
|
39
|
+
).should == false
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context "#process_options_for_link_to_with_supplement" do
|
44
|
+
context "args_for_link_to_with_supplement? is true" do
|
45
|
+
it "should return hash with new name" do
|
46
|
+
UrlHelperAdditions.process_options_for_link_to_with_supplement(
|
47
|
+
"unicorns",
|
48
|
+
'#unicorns',
|
49
|
+
:intro => "Click to learn about",
|
50
|
+
:class => 'mythical'
|
51
|
+
).should == ["<span>Click to learn about </span>unicorns",
|
52
|
+
'#unicorns',
|
53
|
+
{ :class => 'mythical' }
|
54
|
+
]
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context "args_for_link_to_with_supplement? is false" do
|
60
|
+
it "should return nil" do
|
61
|
+
UrlHelperAdditions.process_options_for_link_to_with_supplement(
|
62
|
+
"unicorns",
|
63
|
+
'#unicorns'
|
64
|
+
).should be_nil
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
16
69
|
end
|
17
|
-
|
70
|
+
|
18
71
|
context "#add_supplement_to_text" do
|
19
72
|
it "should add before" do
|
20
73
|
UrlHelperAdditions.add_supplement_to_text(
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: access_kit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 13
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: "0.
|
8
|
+
- 3
|
9
|
+
version: "0.03"
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Mani Tadayon
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-02-
|
17
|
+
date: 2011-02-28 00:00:00 -08:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|