Class: ComatosePage

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

Overview

ComatosePage attributes

- parent_id
- title
- full_path
- slug
- keywords
- body
- author
- filter_type
- position
- version
- updated_on
- created_on

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find_by_path(path) ⇒ Object

Returns a Page with a matching path.



92
93
94
95
96
# File 'lib/comatose_page.rb', line 92

def self.find_by_path( path )
   path = path.split('.')[0] unless path.empty? # Will ignore file extension...
   path = path[1..-1] if path.starts_with? "/"
   find( :first, :conditions=>[ 'full_path = ?', path ] )
end

.record_timestampsObject



104
105
106
# File 'lib/comatose_page.rb', line 104

def self.record_timestamps
  false
end

Instance Method Details

#has_keyword?(keyword) ⇒ Boolean

Check if a page has a selected keyword… NOT case sensitive. So the keyword McCray is the same as mccray

Returns:

  • (Boolean)


73
74
75
76
77
78
# File 'lib/comatose_page.rb', line 73

def has_keyword?(keyword)
  @key_list ||= (self.keywords || '').downcase.split(',').map {|k| k.strip }
  @key_list.include? keyword.to_s.downcase
rescue
  false
end

#record_timestampsObject

I don’t want the AR magic timestamping support for this class…



101
102
103
# File 'lib/comatose_page.rb', line 101

def record_timestamps
  false
end

#to_html(options = {}) ⇒ Object

Returns the page’s content, transformed and filtered…



81
82
83
84
85
86
87
# File 'lib/comatose_page.rb', line 81

def to_html(options={})
  #version = options.delete(:version)
  text = self.body
  binding = Comatose::ProcessingContext.new(self, options)
  filter_type = self.filter_type || '[No Filter]'
  TextFilters.transform(text, binding, filter_type, Comatose.config.default_processor)
end

#uriObject

Returns a pages URI dynamically, based on the active mount point



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/comatose_page.rb', line 59

def uri
  if full_path == ''
    active_mount_info[:root]
  else
    page_path = (full_path || '').split('/')
    idx_path = active_mount_info[:index].split('/')
    uri_root = active_mount_info[:root].split('/')
    uri_path = ( uri_root + (page_path - idx_path) ).flatten.delete_if {|i| i == "" }
    ['',uri_path].join('/')
  end
end