Class: CortexReaver::Page
- Inherits:
-
Object
- Object
- CortexReaver::Page
show all
- Includes:
- Model::Renderer
- Defined in:
- lib/cortex_reaver/model/page.rb
Class Method Summary
collapse
Instance Method Summary
collapse
#bluecloth, #erubis_filter, #macro, #render_comment, #sanitize_html, #syntax_highlight
#attr_h, #errors_list, #errors_on, #form_for, #form_p, #form_submit
#delete_attachment, included
#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
ids.inject(nil) do |page, name|
parent_id = page ? page.id : nil
self[:page_id => parent_id, :name => name]
end
end
|
.recent ⇒ Object
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 = []
if filter(canonical_name_attr => proper, :page_id => page_id).exclude(:id => id).limit(1).count > 0
similar << proper
similar += filter(canonical_name_attr.like(/^#{proper}\-[0-9]+$/)).filter(:page_id => page_id).map(canonical_name_attr)
end
similar
end
|
.url ⇒ Object
73
74
75
|
# File 'lib/cortex_reaver/model/page.rb', line 73
def self.url
'/'
end
|
Instance Method Details
#atom_url ⇒ Object
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_s ⇒ Object
85
86
87
|
# File 'lib/cortex_reaver/model/page.rb', line 85
def to_s
title || name
end
|
#url ⇒ Object
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
|
#validate ⇒ Object
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.
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
|