Change to MongoDB

This commit is contained in:
Wen-Tien Chang committed 2010-01-04 15:52:30 +08:00
1 parent fd8f9cace5
commit b17ebfb9b7
8 files changed
+55 -44

No files matched your search

+6 -4
View File
@@ -1,8 +1,10 @@
require 'couch_foo'
class Announcement < CouchFoo::Base
class Announcement
property_i18n :title, String
property_i18n :content, String
include MongoMapper::Document
key :title_en, String
key :content_en, String
key :content_zh_tw, String
def to_liquid
{ "id" => self.id, "title" => self.title, "content" => self.content }
+7 -4
View File
@@ -1,7 +1,10 @@
class Layout < CouchFoo::Base
property :name, String
property_i18n :content, String
class Layout
include MongoMapper::Document
key :name, String
key :content_en, String
key :content_zh_tw, String
validates_presence_of :name
+15 -15
View File
@@ -1,16 +1,18 @@
class Page < CouchFoo::Base
class Page
include MongoMapper::Document
property :name, String
property :parent_page_id, String
key :name, String
key :parent_page_id, String
property_i18n :content, String
property :layout_id, String
property :layout_name, String
property :use_engine, String
property :external_link, String
property :position, Integer
property :is_published, Boolean
key :content_en, String
key :content_zh_tw, String
key :layout_id, String
key :layout_name, String
key :use_engine, String
key :external_link, String
key :position, Integer
key :is_published, Boolean
belongs_to :layout
has_many :children, :class_name => 'Page', :foreign_key => 'parent_page_id'
@@ -20,9 +22,7 @@ class Page < CouchFoo::Base
before_save :setup_layout_id
before_validation :setup_default_value
default_sort :position
def self.find_by_name(page_name)
Page.find(:first, :conditions => { :name => page_name, :is_published => true })
end
@@ -39,7 +39,7 @@ class Page < CouchFoo::Base
def setup_default_value
if self.position.blank?
max_page = Page.last( :use_key => 'position')
max_page = Page.find(:last, :order => 'position')
self.position = (max_page)? max_page.position.to_i + 1 : 1
end
+6 -3
View File
@@ -1,7 +1,10 @@
class Snippet < CouchFoo::Base
class Snippet
property :name, String
property_i18n :content, String
include MongoMapper::Document
key :name, String
key :content_en, String
key :content_zh_tw, String
validates_presence_of :name
+1 -1
View File
@@ -4,7 +4,7 @@ module SnippetFilter
snippet = Snippet.find_by_name(snippet_name)
if snippet
return Liquid::Template.parse( snippet.read_attribute( "content_#{I18n.locale}" ) ).render
return Liquid::Template.parse( snippet.send( "content_#{I18n.locale}" ) ).render
else
return "nothing"
end