Class: Nesta::Page

Inherits:
FileModel show all
Defined in:
lib/nesta/models.rb

Constant Summary

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

Constructor Details

This class inherits a constructor from Nesta::FileModel

Class Method Details

+ (Object) find_all



199
200
201
# File 'lib/nesta/models.rb', line 199

def self.find_all
  super.select { |p| ! p.hidden? }
end

+ (Object) find_articles



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

+ (Object) find_by_path(path)



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

+ (Object) model_path(basename = nil)



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

- (Object) ==(other)



209
210
211
# File 'lib/nesta/models.rb', line 209

def ==(other)
  other.respond_to?(:path) && (self.path == other.path)
end

- (Object) articles



330
331
332
# File 'lib/nesta/models.rb', line 330

def articles
  Page.find_articles.select { |article| article.categories.include?(self) }
end

- (Object) atom_id



257
258
259
# File 'lib/nesta/models.rb', line 257

def atom_id
  ('atom id')
end

- (Object) body(scope = nil)



283
284
285
# File 'lib/nesta/models.rb', line 283

def body(scope = nil)
  convert_to_html(@format, scope, body_markup)
end

- (Object) body_markup



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

- (Object) categories



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

- (Object) date(format = nil)



247
248
249
250
251
252
253
254
255
# File 'lib/nesta/models.rb', line 247

def date(format = nil)
  @date ||= if ("date")
    if format == :xmlschema
      Time.parse(("date")).xmlschema
    else
      DateTime.parse(("date"))
    end
  end
end

- (Boolean) draft?



213
214
215
# File 'lib/nesta/models.rb', line 213

def draft?
  flagged_as?('draft')
end

- (Object) heading



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

- (Boolean) hidden?



217
218
219
# File 'lib/nesta/models.rb', line 217

def hidden?
  draft? && Nesta::App.production?
end


234
235
236
237
238
# File 'lib/nesta/models.rb', line 234

def link_text
  ('link text') || heading
rescue HeadingNotSet
  raise LinkTextNotSet, "Need to link to '#{abspath}' but can't get link text"
end

- (Object) pages



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

- (Object) parent



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

- (Object) priority(category)



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

- (Object) read_more



261
262
263
# File 'lib/nesta/models.rb', line 261

def read_more
  ('read more') || Nesta::Config.read_more
end

- (Boolean) receives_comments?



334
335
336
# File 'lib/nesta/models.rb', line 334

def receives_comments?
  ! date.nil?
end

- (Object) summary



265
266
267
268
269
270
# File 'lib/nesta/models.rb', line 265

def summary
  if summary_text = ("summary")
    summary_text.gsub!('\n', "\n")
    convert_to_html(@format, nil, summary_text)
  end
end

- (Object) title



240
241
242
243
244
245
# File 'lib/nesta/models.rb', line 240

def title
  ('title') || link_text
rescue LinkTextNotSet
  return Nesta::Config.title if abspath == '/'
  raise
end