class Tr8n::SiteMapSection
Attributes
data[RW]
key[RW]
parent[RW]
Public Class Methods
new(section_data = {}, parent_section = nil)
click to toggle source
# File lib/tr8n/site_map_section.rb, line 28 def initialize(section_data = {}, parent_section = nil) @data = section_data @parent = parent_section @key = Tr8n::TranslationKey.generate_key(data[:label], data[:description]) @parent.children << self if @parent end
Public Instance Methods
children()
click to toggle source
# File lib/tr8n/site_map_section.rb, line 40 def children @children ||= [] end
description()
click to toggle source
# File lib/tr8n/site_map_section.rb, line 57 def description data[:description] || '' end
enabled?()
click to toggle source
# File lib/tr8n/site_map_section.rb, line 35 def enabled? return true if data[:enabled] == nil data[:enabled] end
label()
click to toggle source
# File lib/tr8n/site_map_section.rb, line 53 def label data[:label] || '' end
link(params)
click to toggle source
# File lib/tr8n/site_map_section.rb, line 61 def link(params) return data[:link] if data[:link] return "/" unless source lnk = "/#{source}" unless source.first == '/' return "#{lnk}?#{object[:param]}=#{params[object[:param]]}" if object lnk end
object()
click to toggle source
# File lib/tr8n/site_map_section.rb, line 69 def object data[:object] end
parents()
click to toggle source
# File lib/tr8n/site_map_section.rb, line 86 def parents @parents ||= begin path = [self] node = self.parent while node path << node node = node.parent end path.reverse end end
source()
click to toggle source
# File lib/tr8n/site_map_section.rb, line 48 def source return "" if sources.blank? or sources.empty? sources.first end
sources()
click to toggle source
# File lib/tr8n/site_map_section.rb, line 44 def sources data[:sources] end
title(params = {})
click to toggle source
# File lib/tr8n/site_map_section.rb, line 73 def title(params = {}) if object cls = object[:class].constantize.find(params[object[:param]]) return ERB::Util.html_escape(cls.send(object[:method])) end # has to be smart about the objects label.translate(description) end
to_hash(deep=true)
click to toggle source
# File lib/tr8n/site_map_section.rb, line 98 def to_hash(deep=true) hash = { :label => label, :description => description, :sources => sources } hash[:sources] = sources if sources hash[:sections] = children.collect{|child| child.to_hash} if deep hash end
to_s()
click to toggle source
# File lib/tr8n/site_map_section.rb, line 82 def to_s label end