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.



94
95
96
97
98
# File 'lib/comatose_page.rb', line 94

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



107
108
109
# File 'lib/comatose_page.rb', line 107

def self.record_timestamps
  false
end

.slugize_foreign_leters(title) ⇒ Object



111
112
113
# File 'lib/comatose_page.rb', line 111

def self.slugize_foreign_leters(title)
  title.gsub("æ","ae").gsub("Æ","ae").gsub("å","a").gsub("Å","a").gsub("ø","o").gsub("Ø","o")
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)


75
76
77
78
79
80
# File 'lib/comatose_page.rb', line 75

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…



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

def record_timestamps
  false
end

#to_html(options = {}) ⇒ Object

Returns the page’s content, transformed and filtered…



83
84
85
86
87
88
89
# File 'lib/comatose_page.rb', line 83

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

#uriObject

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



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

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