Class: Comatose::Page

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/comatose/page.rb

Overview

  • created_at

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#new_root_pageObject

Returns the value of attribute new_root_page.



20
21
22
# File 'app/models/comatose/page.rb', line 20

def new_root_page
  @new_root_page
end

Class Method Details

.create_root(attrs) ⇒ Object



65
66
67
# File 'app/models/comatose/page.rb', line 65

def create_root(attrs)
  Page.create(attrs)
end

.find_by_path(path) ⇒ Object

Returns a Page with a matching path.



113
114
115
116
117
118
119
120
121
122
123
124
# File 'app/models/comatose/page.rb', line 113

def self.find_by_path(path)
  Comatose.logger.debug "looking for Page with path: #{path}"
  if path.blank?
    Comatose.logger.debug "could not find Page with path: #{path}"
  else
   path = path.split('.')[0] # Will ignore file extension...
   if path.length > 1
     path = path[1..-1] if path.starts_with? "/"
   end
  end
  find( :first, :conditions=>[ 'full_path = ?', path ] )
end

.method_added(what) ⇒ Object



70
71
72
# File 'app/models/comatose/page.rb', line 70

def method_added(what)
  Comatose.logger.debug "method added: #{what.to_s}"
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)


92
93
94
95
96
97
# File 'app/models/comatose/page.rb', line 92

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

#to_html(options = {}) ⇒ Object Also known as: to_comatose_html

Returns the page’s content, transformed and filtered…



100
101
102
103
104
105
106
107
108
# File 'app/models/comatose/page.rb', line 100

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

#uriObject

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



78
79
80
81
82
83
84
85
86
87
88
# File 'app/models/comatose/page.rb', line 78

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