helper_methods 0.0.4 → 0.0.5
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/README.md +3 -0
- data/lib/helper_methods/version.rb +1 -1
- data/lib/helper_methods.rb +39 -0
- metadata +1 -1
data/README.md
CHANGED
@@ -26,6 +26,7 @@ Included helpers:
|
|
26
26
|
youtube('z8WXgoBGRb4')
|
27
27
|
youtube_link('z8WXgoBGRb4')
|
28
28
|
icon('th-large icon-white')
|
29
|
+
active_link_to 'some string', some_path
|
29
30
|
|
30
31
|
### Youtube helpers
|
31
32
|
|
@@ -107,6 +108,8 @@ And this helps you to manage mobile views
|
|
107
108
|
|
108
109
|
mobile_device?
|
109
110
|
|
111
|
+
We have also a copy of active_link_to gem inside. If you want to use the original gem, please, visit: http://rubygems.org/gems/active_link_to
|
112
|
+
|
110
113
|
## Contributing
|
111
114
|
|
112
115
|
1. Fork it
|
data/lib/helper_methods.rb
CHANGED
@@ -49,6 +49,45 @@ module HelperMethods
|
|
49
49
|
%(<li#{tag_class}#{lp}>#{link_to text, path, a_properties}</li>).html_safe
|
50
50
|
end
|
51
51
|
|
52
|
+
|
53
|
+
def active_link_to(*args, &block)
|
54
|
+
if block_given?
|
55
|
+
name = capture(&block)
|
56
|
+
options = args[0] || {}
|
57
|
+
html_options = args[1] || {}
|
58
|
+
else
|
59
|
+
name = args[0]
|
60
|
+
options = args[1] || {}
|
61
|
+
html_options = args[2] || {}
|
62
|
+
end
|
63
|
+
url = url_for(options)
|
64
|
+
|
65
|
+
active_options = { }
|
66
|
+
link_options = { }
|
67
|
+
html_options.each do |k, v|
|
68
|
+
if [:active, :class_active, :class_inactive, :active_disable, :wrap_tag].member?(k)
|
69
|
+
active_options[k] = v
|
70
|
+
else
|
71
|
+
link_options[k] = v
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
css_class = link_options.delete(:class).to_s + ' '
|
76
|
+
css_class << active_link_to_class(url, active_options)
|
77
|
+
css_class.strip!
|
78
|
+
|
79
|
+
wrap_tag = active_options[:wrap_tag].present? ? active_options[:wrap_tag] : nil
|
80
|
+
link_options[:class] = css_class if css_class.present? && !wrap_tag
|
81
|
+
|
82
|
+
link = if active_options[:active_disable] === true && is_active_link?(url, active_options[:active])
|
83
|
+
content_tag(:span, name, link_options)
|
84
|
+
else
|
85
|
+
link_to(name, url, link_options)
|
86
|
+
end
|
87
|
+
|
88
|
+
wrap_tag ? content_tag(wrap_tag, link, :class => css_class) : link
|
89
|
+
end
|
90
|
+
|
52
91
|
def is_active_link?(url, condition = nil)
|
53
92
|
url = url_for(url).sub(/\?.*/, '') # ignore GET params
|
54
93
|
case condition
|