Class: CortexReaver::Page

Inherits:
Object
  • Object
show all
Includes:
Model::Renderer
Defined in:
lib/cortex_reaver/model/page.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Model::Renderer

#bluecloth, #erubis_filter, #macro, #render_comment, #sanitize_html, #syntax_highlight

Methods included from Ramaze::Helper::Form

#attr_h, #errors_list, #errors_on, #form_for, #form_p, #form_submit

Methods included from Ramaze::Helper::Attachments

#delete_attachment, included

Methods included from Ramaze::Helper::Pages

#page_navigation, #page_navigation_helper, #page_select, #subpage_navigation

Class Method Details

.get(ids) ⇒ Object

get(‘foo’, ‘bar’, ‘baz’) get(‘foo/bar/baz’)



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/cortex_reaver/model/page.rb', line 61

def self.get(ids)
  unless ids.is_a? Array
    ids = ids.split('/')
  end

  # Look up ids by nested names.
  ids.inject(nil) do |page, name|
    parent_id = page ? page.id : nil
    self[:page_id => parent_id, :name => name]
  end
end

.recentObject



77
78
79
# File 'lib/cortex_reaver/model/page.rb', line 77

def self.recent
  reverse_order(:updated_on).limit(16)
end

.similar_canonical_names(proper, opts = {}) ⇒ Object

Canonicalize only in the context of our parent’s namespace. Arguments:

  • A proper canonical name to check for conflicts with

  • :id => An optional id to ignore conflicts with

  • :page_id => A parent page_id to use as the namespace for conflict checking.



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/cortex_reaver/model/page.rb', line 45

def self.similar_canonical_names(proper, opts={})
  id = opts[:id]
  page_id = opts[:page_id]

  similar = []
  # Get parent page id for the current context.
  if filter(canonical_name_attr => proper, :page_id => page_id).exclude(:id => id).limit(1).count > 0
    # This name already exists, and it's not ours.
    similar << proper
    similar += filter(canonical_name_attr.like(/^#{proper}\-[0-9]+$/)).filter(:page_id => page_id).map(canonical_name_attr)
  end
  similar
end

.urlObject



73
74
75
# File 'lib/cortex_reaver/model/page.rb', line 73

def self.url
  '/'
end

Instance Method Details

#atom_urlObject



81
82
83
# File 'lib/cortex_reaver/model/page.rb', line 81

def atom_url
  '/pages/atom/' + id.to_s
end

#render(text) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/cortex_reaver/model/page.rb', line 28

def render(text)
  bluecloth(
    macro(
      erubis_filter(
        syntax_highlight(
          text
        )
      )
    ), false, false
  )
end

#to_sObject



85
86
87
# File 'lib/cortex_reaver/model/page.rb', line 85

def to_s
  title || name
end

#urlObject



89
90
91
92
93
94
95
# File 'lib/cortex_reaver/model/page.rb', line 89

def url
  if page
    page.url + '/' + name
  else
    '/' + name
  end
end

#validateObject



97
98
99
100
101
102
103
# File 'lib/cortex_reaver/model/page.rb', line 97

def validate
  validates_unique :name
  validates_presence :name
  validates_max_length 255, :name
  validates_presence :title
  validates_max_length 255, :title
end

#within?(other) ⇒ Boolean

Returns true if this page is located underneath another page. within?(self) => true.

Returns:

  • (Boolean)


107
108
109
110
111
112
113
# File 'lib/cortex_reaver/model/page.rb', line 107

def within?(other)
  if parent = page
    self == other or parent.within?(other)
  else
    self == other
  end
end