Class: Facades::Helpers::Navigation::NavigationLink
- Inherits:
-
Object
- Object
- Facades::Helpers::Navigation::NavigationLink
- Defined in:
- lib/facades/helpers/navigation.rb
Instance Attribute Summary collapse
-
#href ⇒ Object
Returns the value of attribute href.
-
#matcher ⇒ Object
readonly
Returns the value of attribute matcher.
-
#options ⇒ Object
Returns the value of attribute options.
-
#text ⇒ Object
Returns the value of attribute text.
Instance Method Summary collapse
-
#active? ⇒ Boolean
Checks the link’s href against either a proc, regexp, or current request.path depending on the options provided.
-
#initialize(text, href, options) ⇒ NavigationLink
constructor
A new instance of NavigationLink.
Constructor Details
#initialize(text, href, options) ⇒ NavigationLink
Returns a new instance of NavigationLink.
169 170 171 172 173 174 |
# File 'lib/facades/helpers/navigation.rb', line 169 def initialize(text, href, ) @href, @text, @options = href, text, @matcher = (.delete(:proc) || .delete(:matcher)) curr_path = .delete(:path) @matcher ||= curr_path end |
Instance Attribute Details
#href ⇒ Object
Returns the value of attribute href.
166 167 168 |
# File 'lib/facades/helpers/navigation.rb', line 166 def href @href end |
#matcher ⇒ Object (readonly)
Returns the value of attribute matcher.
167 168 169 |
# File 'lib/facades/helpers/navigation.rb', line 167 def matcher @matcher end |
#options ⇒ Object
Returns the value of attribute options.
166 167 168 |
# File 'lib/facades/helpers/navigation.rb', line 166 def @options end |
#text ⇒ Object
Returns the value of attribute text.
166 167 168 |
# File 'lib/facades/helpers/navigation.rb', line 166 def text @text end |
Instance Method Details
#active? ⇒ Boolean
Checks the link’s href against either a proc, regexp, or current request.path depending on the options provided. Returns true if there is a match, false if not.
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/facades/helpers/navigation.rb', line 182 def active? return matcher.call(href) if matcher.is_a?(Proc) return ( (href =~ matcher).to_i >= 1 ) if matcher.is_a?(Regexp) match_path = normalize_path(matcher) href_path = normalize_path(href) return false if href_path.blank? && !match_path.blank? if key = .delete(:match) path_matcher = case key.to_s when 'exact' then match_path.match(%r{^/?#{href_path}/?$}i) when 'after' then match_path.match(%r{/?#{href_path}/?(.*)$}i) when 'before' then match_path.match(%r{#{href_path}/?$}i) end else path_matcher = match_path.match(/#{href_path}\/.*/i) end !!(match_path == href_path || path_matcher) end |