Sha256: 7a8f651faefaba3fa581b2f758782e137930dcb92dfab3061066963a25d6b4cd
Contents?: true
Size: 1.79 KB
Versions: 1
Compression:
Stored size: 1.79 KB
Contents
module Seiten class Page attr_accessor :id, :parent_id, :title, :children, :slug, :redirect, :layout # initialize Page object with attributes def initialize(options={}) @id = options[:id] @parent_id = options[:parent_id] @title = options[:title] @slug = options[:slug] @redirect = options[:redirect] @layout = options[:layout] end def self.all page_store = PageStore.new page_store.load_pages end # find page by id def self.find(id) Page.all.select { |page| page.id == id }.first end # find all pages by parent_id def self.find_by_parent_id(parent_id) Page.all.select { |page| page.parent_id == parent_id } end # find a page by slug def self.find_by_slug(slug) Page.all.select { |page| page.slug == slug }.first end # get breadcrumb of given page (reversed) def self.get_breadcrumb(page) pages ||= [] pages << page if page.parent pages << Page.get_breadcrumb(page.parent) end pages.flatten end # get parent of page def parent Page.find(parent_id) end # get children of page def children Page.all.select { |page| page.parent_id == id } end # true if child is children of page 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 # true if page is equal current_page or parent of current_page def active?(current_page) if current_page if id == current_page.id true elsif parent_of?(current_page) true else false end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
seiten-0.0.5 | lib/seiten/page.rb |