Module: Goldencobra::NavigationHelper

Included in:
ApplicationHelper
Defined in:
app/helpers/goldencobra/navigation_helper.rb

Instance Method Summary collapse

Instance Method Details



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/helpers/goldencobra/navigation_helper.rb', line 4

def breadcrumb(options={})
  id_name = options[:id] || "breadcrumb"
  class_name = options[:class] || ""
  if @article
    list = ""
    @article.path.each do |art|
      link_name = link_to(art.breadcrumb_name, art.public_url)
      list << (:li, raw(link_name))
    end
    content_list = (:ol, raw(list))
    if id_name.present?
      result = (:nav, raw(content_list), :id => "#{id_name}", :class => "#{class_name}")
    else
      result = (:nav, raw(content_list), :class => "#{class_name}")
    end
    return raw(result)
  end
end

TODO: offset implementieren



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'app/helpers/goldencobra/navigation_helper.rb', line 31

def navigation_menu(menue_id, options={})
  return "id can't be blank" if menue_id.blank?
  depth = options[:depth] || 9999
  offset = options[:offset] || 0
  class_name = options[:class] || ""
  id_name = options[:id] || ""
  submenue_of_article = options[:submenue_of_article] || ""
  current_article = options[:current_article] || ""

  if menue_id.class == String
    if current_article.present? && current_article.public_url.present?
      current_menue = Goldencobra::Menue.active.where(:target => current_article.public_url(false)).select{|a| a.path.map(&:title).join("/").include?(menue_id)}.first
      if current_menue
        master_menue = Goldencobra::Menue.find_by_id(current_menue.path_ids[offset])
      else
        return ""
      end
    elsif submenue_of_article.present? && submenue_of_article.public_url.present?
      master_menue = Goldencobra::Menue.active.where(:target => submenue_of_article.public_url).select{|a| a.path.map(&:title).join("/").include?(menue_id)}.first
    else
      master_menue = Goldencobra::Menue.active.find_by_pathname(menue_id)
    end
  else
    master_menue = Goldencobra::Menue.active.find_by_id(menue_id)
  end

  return "" if master_menue.blank?

  current_depth = master_menue.ancestry_depth
  #Check for Permission
  if params[:frontend_tags] && params[:frontend_tags].class != String && params[:frontend_tags][:format] && params[:frontend_tags][:format] == "email"
    #Wenn format email, dann gibt es keinen realen webseit besucher
    ability = Ability.new()
  else
    operator = current_user || current_visitor
    ability = Ability.new(operator)
  end
  if !ability.can?(:read, master_menue)
    return ""
  end
  if master_menue.present?
    content = ""
    subtree_menues = master_menue.subtree.after_depth(current_depth + offset).to_depth(current_depth + depth).active.includes(:permissions).includes(:image)
    subtree_menues = subtree_menues.to_a.delete_if{|a| !ability.can?(:read, a)}

    current_depth = 1
    menue_roots(subtree_menues).each do |root|
      content << navigation_menu_helper(root, options, subtree_menues, current_depth)
    end

    if id_name.present?
      result = (:ul, raw(content),:id => "#{id_name}", :class => "#{class_name} #{depth} navigation #{master_menue.css_class.to_s.gsub(/\W/,' ')}".squeeze(' ').strip)
    else
      result = (:ul, raw(content), :class => "#{class_name} #{depth} navigation #{master_menue.css_class.to_s.gsub(/\W/,' ')}".squeeze(' ').strip)
    end
  end
  return raw(result)
end