Class: Goldencobra::Menue
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Goldencobra::Menue
- Defined in:
- app/models/goldencobra/menue.rb
Class Method Summary collapse
-
.filtered_methods(method_names = []) ⇒ Array
Filtert die übergebenen mthodennamen anhand einer Whiteliste und ersetzt exteren methodenbezeichnungen mit internene helpern.
- .find_by_pathname(name) ⇒ Object
-
.json_tree(nodes, display_methods) ⇒ Hash
Liefert ein Hash der übegenene Anestry Arranged Daten }.
Instance Method Summary collapse
- #article_id ⇒ Object
- #has_active_child?(request, subtree_menues) ⇒ Boolean
- #has_active_descendant?(subtree_menues, request) ⇒ Boolean
- #has_children ⇒ Object
- #is_active?(request) ⇒ Boolean
-
#liquid_description ⇒ String
Render Content of Description with liquid Tags.
- #mapped_to_article? ⇒ Boolean
- #navigation_image ⇒ Object
Class Method Details
.filtered_methods(method_names = []) ⇒ Array
Filtert die übergebenen mthodennamen anhand einer Whiteliste und ersetzt exteren methodenbezeichnungen mit internene helpern
description => liquid_description
124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'app/models/goldencobra/menue.rb', line 124 def self.filtered_methods(method_names=[]) #Alle zugelasssenen methodennamen als Array of Strings allowed_attribute_methods = Goldencobra::Menue.new.attributes.keys additional_whitelist_methods = ["liquid_description", "navigation_image", "article_id"] all_allowed_methodes = allowed_attribute_methods + additional_whitelist_methods #Filter übergebene methodenliste auf die zugelassenen namen selected_methods = method_names.select{ |a| all_allowed_methodes.include?(a) } #Wandle method names um in Symbols method_names = selected_methods.map{ |a| a.to_sym } return method_names.sort end |
.find_by_pathname(name) ⇒ Object
63 64 65 66 67 68 69 |
# File 'app/models/goldencobra/menue.rb', line 63 def self.find_by_pathname(name) if name.include?("/") where(title: name.split("/").last).select{|a| a.path.map(&:title).join("/") == name}.first else find_by_title(name) end end |
.json_tree(nodes, display_methods) ⇒ Hash
Liefert ein Hash der übegenene Anestry Arranged Daten }
152 153 154 155 156 |
# File 'app/models/goldencobra/menue.rb', line 152 def self.json_tree(nodes, display_methods ) nodes.map do |node, sub_nodes| node.as_json(only: [:id, :title, :target], methods: display_methods).merge({children: json_tree(sub_nodes, display_methods).compact}) end end |
Instance Method Details
#article_id ⇒ Object
95 96 97 |
# File 'app/models/goldencobra/menue.rb', line 95 def article_id Goldencobra::Article.select([:url_name, :startpage, :ancestry, :id, :url_path]).select{ |a| a.public_url == target }.first.try(:id) end |
#has_active_child?(request, subtree_menues) ⇒ Boolean
76 77 78 79 |
# File 'app/models/goldencobra/menue.rb', line 76 def has_active_child?(request, ) @has_active_child_result ||= {} @has_active_child_result[request.path.squeeze("/").split("?")[0]] ||= has_active_descendant?(, request) end |
#has_active_descendant?(subtree_menues, request) ⇒ Boolean
81 82 83 |
# File 'app/models/goldencobra/menue.rb', line 81 def has_active_descendant?(,request) .select{|a| a.ancestry.to_s.starts_with?("#{self.ancestry}/#{self.id}")}.map(&:target).include?(request.path.squeeze("/").split("?")[0]) end |
#has_children ⇒ Object
85 86 87 |
# File 'app/models/goldencobra/menue.rb', line 85 def has_children self.has_children? end |
#is_active?(request) ⇒ Boolean
71 72 73 74 |
# File 'app/models/goldencobra/menue.rb', line 71 def is_active?(request) @is_active_result ||= {} @is_active_result[request.path.squeeze("/").chomp("/").split("?")[0]] ||= request.path.squeeze("/").chomp("/").split("?")[0] == self.target.gsub("\"",'') end |
#liquid_description ⇒ String
Render Content of Description with liquid Tags
102 103 104 105 |
# File 'app/models/goldencobra/menue.rb', line 102 def liquid_description template = Liquid::Template.parse(self.description) template.render(Goldencobra::Article::LiquidParser) end |
#mapped_to_article? ⇒ Boolean
89 90 91 92 93 |
# File 'app/models/goldencobra/menue.rb', line 89 def mapped_to_article? # TODO: Anfrage dauert zu lange bei 2000 Artikeln # @mapped_to_article_result ||= Goldencobra::Article.select([:url_name, :startpage, :ancestry, :id]).map{|a| a.public_url}.uniq.include?(self.target) false end |
#navigation_image ⇒ Object
107 108 109 110 111 112 113 114 |
# File 'app/models/goldencobra/menue.rb', line 107 def return {} unless self.image { "alt_text" => self.image.alt_text ? self.image.alt_text : self.image.image_file_name, "src" => self.image.image(:original) } end |