class Seiten::Page
Attributes
data[RW]
html_options[RW]
id[RW]
layout[W]
parent_id[RW]
refer[RW]
slug[RW]
title[RW]
Public Class Methods
new(options={})
click to toggle source
initialize Page
object with attributes
# File lib/seiten/page.rb, line 9 def initialize(options={}) @navigation_id = options[:navigation_id] @id = options[:id] @parent_id = options[:parent_id] @title = options[:title] @slug = options[:slug] @refer = options[:refer] @layout = options[:layout] @data = options[:data].each_with_object({}){|(k,v), h| h[k.to_sym] = v} if options[:data] @data ||= {} @html_options = options[:html].each_with_object({}){|(k,v), h| h[k.to_sym] = v} if options[:html] @html_options ||= {} end
Public Instance Methods
active?(current_page)
click to toggle source
true if page is equal current_page or parent of current_page
# File lib/seiten/page.rb, line 96 def active?(current_page) if current_page if id == current_page.id true elsif parent_of?(current_page) true else false end end end
ancestors()
click to toggle source
# File lib/seiten/page.rb, line 41 def ancestors return @ancestors unless @ancestors.nil? @ancestors = [] return @ancestors unless parent? ancestor = parent loop do @ancestors << ancestor ancestor = ancestor.parent break if ancestor.nil? end @ancestors end
children()
click to toggle source
get children of page
# File lib/seiten/page.rb, line 75 def children navigation.pages.where(parent_id: id) end
children?()
click to toggle source
# File lib/seiten/page.rb, line 79 def children? navigation.pages.find_by(parent_id: id).present? end
external?()
click to toggle source
returns true if slug starts with http:// or https://
# File lib/seiten/page.rb, line 28 def external? !!(slug.match(/^https?:\/\/.+/)) end
layout()
click to toggle source
# File lib/seiten/page.rb, line 126 def layout @layout || Seiten.config[:default_layout] end
parent()
click to toggle source
get parent of page
# File lib/seiten/page.rb, line 33 def parent navigation.pages.find(parent_id) end
parent?()
click to toggle source
# File lib/seiten/page.rb, line 37 def parent? parent.present? end
parent_of?(child)
click to toggle source
true if child is children of page
# File lib/seiten/page.rb, line 84 def parent_of?(child) page = self if child if page.id == child.parent_id true else child.parent.nil? ? false : page.parent_of?(child.parent) end end end
path()
click to toggle source
# File lib/seiten/page.rb, line 116 def path return refer if refer return '#' if slug.nil? return slug if external? navigation_name = navigation.name == 'application' ? nil : navigation.name [:seiten, navigation_name.try(:to_sym), :page, { slug: slug }] end
root()
click to toggle source
get root page of current page branch
# File lib/seiten/page.rb, line 66 def root if self.parent? self.parent.root else self end end
self_and_ancestors()
click to toggle source
# File lib/seiten/page.rb, line 57 def self_and_ancestors @self_and_ancestors ||= ancestors.insert(0, self) end
template_path()
click to toggle source
# File lib/seiten/page.rb, line 108 def template_path [ navigation_id.gsub(/\./, '/'), slug.present? ? slug : Seiten.config[:root_page] ].join('/') end
Also aliased as: to_s