Class: Nesta::Page
Constant Summary
Constants inherited
from FileModel
FileModel::FORMATS
Instance Attribute Summary
Attributes inherited from FileModel
#filename, #mtime
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from FileModel
#abspath, #description, find_file_for_path, #flagged_as?, #index_page?, #initialize, #keywords, #last_modified, #layout, load, menu_items, #metadata, needs_loading?, #parse_metadata, #path, #permalink, purge_cache, #template, #to_html
Class Method Details
.find_all ⇒ Object
199
200
201
|
# File 'lib/nesta/models.rb', line 199
def self.find_all
super.select { |p| ! p.hidden? }
end
|
.find_articles ⇒ Object
203
204
205
206
207
|
# File 'lib/nesta/models.rb', line 203
def self.find_articles
find_all.select do |page|
page.date && page.date < DateTime.now
end.sort { |x, y| y.date <=> x.date }
end
|
.find_by_path(path) ⇒ Object
194
195
196
197
|
# File 'lib/nesta/models.rb', line 194
def self.find_by_path(path)
page = load(path)
page && page.hidden? ? nil : page
end
|
.model_path(basename = nil) ⇒ Object
190
191
192
|
# File 'lib/nesta/models.rb', line 190
def self.model_path(basename = nil)
Nesta::Config.page_path(basename)
end
|
Instance Method Details
#==(other) ⇒ Object
209
210
211
|
# File 'lib/nesta/models.rb', line 209
def ==(other)
other.respond_to?(:path) && (self.path == other.path)
end
|
#articles ⇒ Object
330
331
332
|
# File 'lib/nesta/models.rb', line 330
def articles
Page.find_articles.select { |article| article.categories.include?(self) }
end
|
#atom_id ⇒ Object
257
258
259
|
# File 'lib/nesta/models.rb', line 257
def atom_id
metadata('atom id')
end
|
#body(scope = nil) ⇒ Object
283
284
285
|
# File 'lib/nesta/models.rb', line 283
def body(scope = nil)
convert_to_html(@format, scope, body_markup)
end
|
#body_markup ⇒ Object
272
273
274
275
276
277
278
279
280
281
|
# File 'lib/nesta/models.rb', line 272
def body_markup
case @format
when :mdown
markup.sub(/^#[^#].*$\r?\n(\r?\n)?/, '')
when :haml
markup.sub(/^\s*%h1\s+.*$\r?\n(\r?\n)?/, '')
when :textile
markup.sub(/^\s*h1\.\s+.*$\r?\n(\r?\n)?/, '')
end
end
|
#categories ⇒ Object
287
288
289
290
291
292
293
|
# File 'lib/nesta/models.rb', line 287
def categories
paths = category_strings.map { |specifier| specifier.sub(/:-?\d+$/, '') }
pages = valid_paths(paths).map { |p| Page.find_by_path(p) }
pages.sort do |x, y|
x.link_text.downcase <=> y.link_text.downcase
end
end
|
#date(format = nil) ⇒ Object
247
248
249
250
251
252
253
254
255
|
# File 'lib/nesta/models.rb', line 247
def date(format = nil)
@date ||= if metadata("date")
if format == :xmlschema
Time.parse(metadata("date")).xmlschema
else
DateTime.parse(metadata("date"))
end
end
end
|
#draft? ⇒ Boolean
213
214
215
|
# File 'lib/nesta/models.rb', line 213
def draft?
flagged_as?('draft')
end
|
#heading ⇒ Object
221
222
223
224
225
226
227
228
229
230
231
232
|
# File 'lib/nesta/models.rb', line 221
def heading
regex = case @format
when :mdown
/^#\s*(.*?)(\s*#+|$)/
when :haml
/^\s*%h1\s+(.*)/
when :textile
/^\s*h1\.\s+(.*)/
end
markup =~ regex
Regexp.last_match(1) or raise HeadingNotSet, "#{abspath} needs a heading"
end
|
#hidden? ⇒ Boolean
217
218
219
|
# File 'lib/nesta/models.rb', line 217
def hidden?
draft? && Nesta::App.production?
end
|
#link_text ⇒ Object
234
235
236
237
238
|
# File 'lib/nesta/models.rb', line 234
def link_text
metadata('link text') || heading
rescue HeadingNotSet
raise LinkTextNotSet, "Need to link to '#{abspath}' but can't get link text"
end
|
#pages ⇒ Object
316
317
318
319
320
321
322
323
324
325
326
327
328
|
# File 'lib/nesta/models.rb', line 316
def pages
in_category = Page.find_all.select do |page|
page.date.nil? && page.categories.include?(self)
end
in_category.sort do |x, y|
by_priority = y.priority(path) <=> x.priority(path)
if by_priority == 0
x.link_text.downcase <=> y.link_text.downcase
else
by_priority
end
end
end
|
#parent ⇒ Object
302
303
304
305
306
307
308
309
310
311
312
313
314
|
# File 'lib/nesta/models.rb', line 302
def parent
if abspath == '/'
nil
else
parent_path = File.dirname(path)
while parent_path != '.' do
parent = Page.load(parent_path)
return parent unless parent.nil?
parent_path = File.dirname(parent_path)
end
Page.load('index')
end
end
|
#priority(category) ⇒ Object
295
296
297
298
299
300
|
# File 'lib/nesta/models.rb', line 295
def priority(category)
category_string = category_strings.detect do |string|
string =~ /^#{category}([,:\s]|$)/
end
category_string && category_string.split(':', 2)[-1].to_i
end
|
#read_more ⇒ Object
261
262
263
|
# File 'lib/nesta/models.rb', line 261
def read_more
metadata('read more') || Nesta::Config.read_more
end
|
334
335
336
|
# File 'lib/nesta/models.rb', line 334
def
! date.nil?
end
|
#summary ⇒ Object
265
266
267
268
269
270
|
# File 'lib/nesta/models.rb', line 265
def summary
if summary_text = metadata("summary")
summary_text.gsub!('\n', "\n")
convert_to_html(@format, nil, summary_text)
end
end
|
#title ⇒ Object
240
241
242
243
244
245
|
# File 'lib/nesta/models.rb', line 240
def title
metadata('title') || link_text
rescue LinkTextNotSet
return Nesta::Config.title if abspath == '/'
raise
end
|