2011-08-08 01:30:44 +00:00
|
|
|
class Layout < DesignFile
|
2011-12-23 10:34:21 +00:00
|
|
|
include ParserLayout
|
2011-09-01 11:08:45 +00:00
|
|
|
|
|
|
|
attr_reader :content
|
2012-03-21 17:51:16 +00:00
|
|
|
|
|
|
|
field :body
|
2011-09-01 11:08:45 +00:00
|
|
|
|
2011-09-01 01:12:41 +00:00
|
|
|
embeds_one :menu
|
2012-10-24 10:40:38 +00:00
|
|
|
belongs_to :design
|
2011-08-18 08:27:04 +00:00
|
|
|
embeds_many :layout_parts
|
2011-09-01 11:08:45 +00:00
|
|
|
|
2012-02-16 11:14:16 +00:00
|
|
|
before_save :parse_layout
|
2012-12-03 09:25:27 +00:00
|
|
|
after_save :save_pages
|
2011-05-18 02:00:00 +00:00
|
|
|
|
2011-08-08 04:29:32 +00:00
|
|
|
def content
|
2011-09-13 06:03:03 +00:00
|
|
|
self.file.read.force_encoding("UTF-8") rescue ''
|
2011-08-08 04:29:32 +00:00
|
|
|
end
|
2011-08-10 09:28:10 +00:00
|
|
|
|
2011-05-18 02:00:00 +00:00
|
|
|
def self.exist_one?
|
|
|
|
Layout.count > 0
|
|
|
|
end
|
2011-08-10 09:28:10 +00:00
|
|
|
|
2012-03-21 17:51:16 +00:00
|
|
|
def parse_layout
|
|
|
|
html = Nokogiri::HTML(self.file.read)
|
|
|
|
self.body = html.at_css("body").inner_html
|
|
|
|
parse_body(self)
|
2011-08-10 09:28:10 +00:00
|
|
|
end
|
2012-12-03 09:25:27 +00:00
|
|
|
|
|
|
|
def save_pages
|
2012-12-03 09:38:55 +00:00
|
|
|
self.design.pages.each(&:generate_parts)
|
2012-12-03 09:25:27 +00:00
|
|
|
end
|
2011-09-01 11:08:45 +00:00
|
|
|
|
2011-03-08 09:25:46 +00:00
|
|
|
end
|