forked from refinery/refinerycms
/
page_part.rb
33 lines (24 loc) · 813 Bytes
/
page_part.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
module Refinery
class PagePart < Refinery::Core::BaseModel
attr_accessible :title, :content, :position, :body, :created_at,
:updated_at, :refinery_page_id
belongs_to :page, :foreign_key => :refinery_page_id
validates :title, :presence => true
alias_attribute :content, :body
translates :body if respond_to?(:translates)
def to_param
"page_part_#{title.downcase.gsub(/\W/, '_')}"
end
def body=(value)
super
normalise_text_fields
end
self.translation_class.send :attr_accessible, :locale if self.respond_to?(:translation_class)
protected
def normalise_text_fields
if body.present? && body !~ %r{^<}
self.body = "<p>#{body.gsub("\r\n\r\n", "</p><p>").gsub("\r\n", "<br/>")}</p>"
end
end
end
end