module Slices::Tree::ClassMethods
Public Instance Methods
find_by_path(path)
click to toggle source
Finds a page by it's path, a {Page::NotFound} is raised if the page can't be found.
@return [Page]
# File lib/slices/tree.rb, line 68 def find_by_path(path) find_by(path: path) rescue Mongoid::Errors::DocumentNotFound raise Page::NotFound.new(path) end
Also aliased as: f
home()
click to toggle source
Get the home page.
@return [Page]
# File lib/slices/tree.rb, line 59 def home find_by_path('/') end
path_from_attributes(attributes, parent = nil)
click to toggle source
Generate a path
from attributes.
@param [Hash] attributes @option attributes [String] :parent_path Path to parent page @option attributes [Page] :parent Parent page @option attributes [String] :name Page name @option attributes [String] :permalink Permalink @param [Page] parent @return [String]
# File lib/slices/tree.rb, line 85 def path_from_attributes(attributes, parent = nil) parent_path = if parent parent.path else attributes[:parent_path] || attributes[:parent].try(:path).to_s end permalink = attributes.delete(:permalink) || attributes[:name] File.join(parent_path, permalink.to_url) end