Class: Page
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Page
- Defined in:
- app/models/page.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.find_by_path(path) ⇒ Object
8 9 10 11 12 13 14 |
# File 'app/models/page.rb', line 8 def find_by_path(path) return unless page = root page.walk(path) do |last, part| last.children.find_by_permalink(part) if last end end |
.update_content(path, content = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/models/page.rb', line 16 def update_content(path, content = {}) page = root || Page.create(permalink: '') page = page.walk(path) do |last, part| last.children.find_or_create_by_permalink(part) end page.update_attributes(content: content) page end |
Instance Method Details
#path ⇒ Object
29 30 31 32 33 34 35 |
# File 'app/models/page.rb', line 29 def path if parent Pathname.new(parent.path) + permalink else Pathname.new("/") end.to_s end |
#walk(path, &block) ⇒ Object
37 38 39 40 41 |
# File 'app/models/page.rb', line 37 def walk(path, &block) parts = Pathname.new(path.to_s).each_filename parts.reduce(self, &block) end |