Add Item, Page, Component, Link inheritanced models

This commit is contained in:
Wen-Tien Chang committed 2010-01-14 18:30:53 +08:00
1 parent cd21cadfe7
commit e1440a79d8
38 files changed
+417 -175

No files matched your search

+2 -2
View File
@@ -2,12 +2,12 @@ class Announcement
include MongoMapper::Document
key :entry_name, String, :required => true, :index => true
key :component_name, String, :required => true, :index => true
key_i18n :title, String
key_i18n :content, String
def to_liquid
{ "entry_name" => self.entry_name, "id" => self.id.to_s, "title" => self.title, "content" => self.content }
{ "component_name" => self.entry_name, "id" => self.id.to_s, "title" => self.title, "content" => self.content }
end
end
+8
View File
@@ -0,0 +1,8 @@
class Component < Item
include LayoutSupport
key :engine_name, String
key :layout_name, String, :required => true
end
+34
View File
@@ -0,0 +1,34 @@
class Item
include MongoMapper::Document
key :_type, String
key :name, String, :required => true, :index => true
key :parent_item_name, String, :required => true, :index => true
key_i18n :title, String, :required => true
key :position, Integer, :required => true
key :is_published, Boolean, :required => true, :default => true, :index => true
before_validation :setup_default_value
def self.find_by_name(item_name)
Item.find(:first, :conditions => { :name => item_name, :is_published => true })
end
protected
def setup_default_value
if self.position.blank?
max_page = Page.find(:last, :order => 'position')
self.position = (max_page)? max_page.position.to_i + 1 : 1
end
if self.parent_item_name.blank?
self.parent_item_name = "root"
end
end
end
+9
View File
@@ -0,0 +1,9 @@
class Link < Item
key :url, String, :required => true
def link
ApplicationController.helpers.link_to(self.title, self.url)
end
end
+5 -37
View File
@@ -1,40 +1,8 @@
class Page
include MongoMapper::Document
class Page < Item
include LayoutSupport
key :name, String, :required => true, :index => true
key :parent_page_name, String, :required => true, :index => true
key_i18n :title, String, :required => true
key_i18n :content, String
key :layout_name, String, :required => true
key :external_link, String
key :position, Integer, :required => true
key :is_published, Boolean, :required => true, :default => true, :index => true
key :component_name, String
before_validation :setup_default_value
def self.find_by_name(page_name)
Page.find(:first, :conditions => { :name => page_name, :is_published => true })
end
def layout
Layout.find_by_name(self.layout_name)
end
protected
def setup_default_value
if self.position.blank?
max_page = Page.find(:last, :order => 'position')
self.position = (max_page)? max_page.position.to_i + 1 : 1
end
if self.parent_page_name.blank?
self.parent_page_name = "root"
end
end
key_i18n :content, String
key :layout_name, String, :required => true
end
+2
View File
@@ -3,6 +3,8 @@ class Snippet
include MongoMapper::Document
key :name, String, :required => true, :index => true
key :parent_item_name, String, :required => true, :index => true
key_i18n :content, String
end