This repository has been archived on 2024-03-16. You can view files and clone it, but cannot push or open issues or pull requests.
2011-05-18 02:00:00 +00:00
|
|
|
class PagePart
|
|
|
|
|
|
|
|
include Mongoid::Document
|
|
|
|
include Mongoid::Timestamps
|
|
|
|
|
|
|
|
field :name
|
|
|
|
field :content
|
2011-05-25 08:27:17 +00:00
|
|
|
field :kind
|
2011-05-27 03:27:54 +00:00
|
|
|
field :i18n_variable_id, :type => BSON::ObjectId
|
2011-05-18 02:00:00 +00:00
|
|
|
|
|
|
|
belongs_to :page
|
2011-05-27 03:27:54 +00:00
|
|
|
|
|
|
|
# Get the i18n_variable
|
|
|
|
def i18n_variable
|
|
|
|
@i18n_variable ||= I18nVariable.find(self.i18n_variable_id) rescue nil
|
|
|
|
end
|
|
|
|
|
|
|
|
# Update or create the i18n_variable record
|
|
|
|
def i18n_variable=(attr)
|
|
|
|
if self.i18n_variable_id
|
|
|
|
self.i18n_variable.update_attributes(attr)
|
|
|
|
else
|
|
|
|
var = I18nVariable.new(attr.merge({:key => self.key, :document_class => self.class, :parent_id => self.page.i18n_variable_id}))
|
|
|
|
var.save
|
|
|
|
self.i18n_variable_id = var.id
|
|
|
|
end
|
|
|
|
end
|
2011-06-01 02:24:14 +00:00
|
|
|
|
2011-06-01 04:00:41 +00:00
|
|
|
def destroy_i18n_variable
|
|
|
|
self.i18n_variable.destroy rescue nil
|
|
|
|
end
|
|
|
|
|
2011-06-01 02:24:14 +00:00
|
|
|
# Build the content from the i18n_variable
|
|
|
|
def build_content(locales)
|
|
|
|
res = ''
|
|
|
|
res << "<r:multi_lang i18n_id='#{i18n_variable.id}'>"
|
|
|
|
locales.each do |locale|
|
|
|
|
res << "<r:lang name='#{locale.to_s}'>"
|
|
|
|
res << i18n_variable[locale.to_s]
|
|
|
|
res << "</r:lang>"
|
|
|
|
end
|
|
|
|
res << "</r:multi_lang>"
|
|
|
|
self.content = res
|
|
|
|
end
|
2011-05-18 02:00:00 +00:00
|
|
|
|
|
|
|
end
|