Skip to content

Commit

Permalink
Merge pull request #27 from gucki/master
Browse files Browse the repository at this point in the history
fix for #19
  • Loading branch information
jejacks0n committed Feb 13, 2013
2 parents 707d35b + 3d5f025 commit d4dbd32
Showing 1 changed file with 24 additions and 23 deletions.
47 changes: 24 additions & 23 deletions lib/navigasmic/core/item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,39 +22,40 @@ def link?
end

def highlights_on?(path, params)
return false unless @rules.any?
params = clean_unwanted_keys(params)
result = false

@rules.each do |rule|
highlighted = true

case rule
when String then highlighted &= path == rule
when Regexp then highlighted &= path.match(rule)
when TrueClass then highlighted &= rule
when FalseClass then highlighted &= rule
when Hash
clean_unwanted_keys(rule).each do |key, value|
value.gsub(/^\//, '') if key == :controller
highlighted &= value == params[key].to_s
end
else raise 'highlighting rules should be an array containing any of/or a Boolean, String, Regexp, Hash or Proc'
when String
return false unless path == rule
when Regexp
return false unless path.match(rule)
when TrueClass
# no-op
when FalseClass
return false
when Hash
clean_unwanted_keys(rule).each do |key, value|
value.gsub(/^\//, '') if key == :controller
return false unless value == params[key].to_s
end
else
raise ArgumentError, 'Highlighting rules should be an array containing any of/or a Boolean, String, Regexp, Hash or Proc'
end

result |= highlighted
end

result
true
end

private

def calculate_highlighting_rules(rules)
highlighting_rules = []
highlighting_rules << @link if link?

return [] if highlighting_rules.blank?
highlighting_rules += Array(rules)
[].tap do |highlighting_rules|
if rules
highlighting_rules.concat Array(rules)
else
highlighting_rules << @link if link?
end
end
end

def clean_unwanted_keys(hash)
Expand Down

0 comments on commit d4dbd32

Please sign in to comment.