Module: Slices::Tree::ClassMethods
- Defined in:
- lib/slices/tree.rb
Instance Method Summary collapse
-
#find_by_path(path) ⇒ Page
(also: #f)
Finds a page by it’s path, a Page::NotFound is raised if the page can’t be found.
-
#home ⇒ Page
Get the home page.
-
#path_from_attributes(attributes, parent = nil) ⇒ String
Generate a
pathfrom attributes.
Instance Method Details
#find_by_path(path) ⇒ Page Also known as: f
Finds a page by it’s path, a Page::NotFound is raised if the page can’t be found.
68 69 70 |
# File 'lib/slices/tree.rb', line 68 def find_by_path(path) first(conditions: { path: path }) || (raise Page::NotFound.new(path)) end |
#home ⇒ Page
Get the home page.
59 60 61 |
# File 'lib/slices/tree.rb', line 59 def home find_by_path('/') end |
#path_from_attributes(attributes, parent = nil) ⇒ String
Generate a path from attributes.
83 84 85 86 87 88 89 90 91 |
# File 'lib/slices/tree.rb', line 83 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 |