Class: CmsPage
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- CmsPage
- Includes:
- ActsAsTree
- Defined in:
- app/models/cms_page.rb
Class Method Summary collapse
Instance Method Summary collapse
- #article_date_day ⇒ Object
- #article_date_mon ⇒ Object
- #article_date_month ⇒ Object
- #article_date_year ⇒ Object
- #article_date_yr ⇒ Object
- #compute_and_store_path ⇒ Object
- #html_head=(value) ⇒ Object
- #name=(value) ⇒ Object
- #set_parent_id!(new_id) ⇒ Object
- #set_versions ⇒ Object
- #tags_as_css_classes ⇒ Object
- #update_index ⇒ Object
Class Method Details
.index_all ⇒ Object
49 50 51 52 |
# File 'app/models/cms_page.rb', line 49 def self.index_all CmsPage.find(:all, :conditions => [ 'search_index is null' ]).each { |pg| pg.update_index ; pg.save_without_revision } true end |
.reindex_all ⇒ Object
54 55 56 57 |
# File 'app/models/cms_page.rb', line 54 def self.reindex_all CmsPage.find(:all).each { |pg| pg.update_index ; pg.save_without_revision } true end |
Instance Method Details
#article_date_day ⇒ Object
102 |
# File 'app/models/cms_page.rb', line 102 def article_date_day ; article_date.strftime("%d").to_i ; end |
#article_date_mon ⇒ Object
101 |
# File 'app/models/cms_page.rb', line 101 def article_date_mon ; article_date.strftime("%b") ; end |
#article_date_month ⇒ Object
100 |
# File 'app/models/cms_page.rb', line 100 def article_date_month ; article_date.strftime("%B") ; end |
#article_date_year ⇒ Object
103 |
# File 'app/models/cms_page.rb', line 103 def article_date_year ; article_date.strftime("%Y").to_i ; end |
#article_date_yr ⇒ Object
104 |
# File 'app/models/cms_page.rb', line 104 def article_date_yr ; article_date.strftime("%y").to_i ; end |
#compute_and_store_path ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/models/cms_page.rb', line 24 def compute_and_store_path if self.parent if self.parent.path != '' self.path = "#{self.parent.path}/#{self.name}" else self.path = self.name end else self.path = '' end end |
#html_head=(value) ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'app/models/cms_page.rb', line 69 def html_head=(value) if value && value.is_a?(String) # filter suspicious content... go overboard for now, fine-tune later perhaps value.gsub!(/<(%.*?(exec|system)\s?\(.*?\s*%)>/, '<\1>') value.gsub!(/<(%.*?\%x\s?\[.*?\s*%)>/, '<\1>') value.gsub!(/<(%.*?`.*?\s*%)>/, '<\1>') end super(value) end |
#name=(value) ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'app/models/cms_page.rb', line 59 def name=(value) if value && value.is_a?(String) # filter suspicious content... go overboard for now, fine-tune later perhaps value.gsub!(/<(%.*?(exec|system)\s?\(.*?\s*%)>/, '<\1>') value.gsub!(/<(%.*?\%x\s?\[.*?\s*%)>/, '<\1>') value.gsub!(/<(%.*?`.*?\s*%)>/, '<\1>') end super(value) end |
#set_parent_id!(new_id) ⇒ Object
92 93 94 95 96 97 |
# File 'app/models/cms_page.rb', line 92 def set_parent_id!(new_id) self.parent_id = new_id self.save_without_revision pg.children.each { |subpg| subpg.save_without_revision } self.valid? end |
#set_versions ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'app/models/cms_page.rb', line 36 def set_versions if self.template self.cms_template_version ||= self.template.version end self.published_version ||= -1 self.published_date ||= self.created_on || Time.now end |
#tags_as_css_classes ⇒ Object
45 46 47 |
# File 'app/models/cms_page.rb', line 45 def self..map { |t| t.name.downcase.gsub(/[^\w]+/, '-') }.join(' ') end |
#update_index ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'app/models/cms_page.rb', line 79 def update_index content = '' if self.published_version.to_i >= 0 idx_version = self.published_version.to_i == 0 ? self.version : self.published_version self.objects.find(:all, :conditions => [ "cms_page_version = ? and (obj_type = 'text' or obj_type = 'string')", idx_version ]).each do |obj| content << obj.content << "\n" end end self.search_index = sanitize_index(content) end |