Class: Manuscript::Page

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/manuscript/page.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find_by_path(path) ⇒ Object

Raises:

  • (ActiveRecord::RecordNotFound)


16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/manuscript/page.rb', line 16

def self.find_by_path(path)
  page_names = path.split("/")
  LOGGER.info("manuscript --> path: " + path.to_s)
  LOGGER.info("manuscript --> page_names: " + page_names.inspect)
  @page = self.main_pages.find_by_name(page_names.delete_at(0))
  raise ActiveRecord::RecordNotFound unless @page
  unless page_names.blank?
    page_names.each do |page_name|
      @page = @page.child_pages.find_by_name(page_name)
      raise ActiveRecord::RecordNotFound unless @page
    end
  end
  @page
end

Instance Method Details

#parent_urlObject



39
40
41
42
43
44
45
# File 'lib/manuscript/page.rb', line 39

def parent_url
  if parent
    parent.url
  else
    ""
  end
end

#to_html(user = nil) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/manuscript/page.rb', line 47

def to_html(user = nil)
  if template
    template.render({'current_user' => user, 'contents' => RDiscount.new(contents).to_html})
  else  
    RDiscount.new(contents).to_html
  end
end

#urlObject



31
32
33
34
35
36
37
# File 'lib/manuscript/page.rb', line 31

def url
  if parent
    "#{parent.url}/#{name}"
  else
    "/#{name}"
  end
end