orbit-basic/lib/parsers/parser_layout.rb

32 lines
1.1 KiB
Ruby
Raw Permalink Normal View History

2011-12-23 10:34:21 +00:00
module ParserLayout
2012-03-21 17:51:16 +00:00
require 'nokogiri'
2011-12-23 10:34:21 +00:00
2012-03-21 17:51:16 +00:00
def parse_body(layout)
body = Nokogiri::HTML(layout.body)
body.css('.page_content').each do |content|
layout.layout_parts.build(:name => content['name']) unless layout.layout_parts.detect{|layout_part| layout_part.name.eql?(content['name'])}
2012-03-21 17:51:16 +00:00
end
2011-12-23 10:34:21 +00:00
2012-03-21 17:51:16 +00:00
body.css('.page_menu').each do |menu|
layout.build_menu(:levels => 0, :values => {}) unless layout.menu
layout.menu.levels = i = menu['level'].to_i
layout.menu.values.merge!({'home' => menu['home']}) if i == 1
layout.menu.values.merge!({"id_#{i}" => menu['id'], "class_#{i}" => menu['class'], "li_class_#{i}" => menu['li_class'], "li_incremental_#{i}" => menu['li_incremental']})
2011-12-23 10:34:21 +00:00
end
2012-03-21 17:51:16 +00:00
2011-12-23 10:34:21 +00:00
end
2012-03-21 17:51:16 +00:00
def parse_body_for_images(design)
body = Nokogiri::HTML(design.layout.body)
body.css('.page_image').each do |page_image|
image = design.images.where( file: File.basename(page_image['src']))[0]
2012-10-24 10:40:38 +00:00
image.update_attributes(:html_id => page_image['id'], :html_class => page_image['class'], :in_html => true) if image
end
end
2012-03-21 17:51:16 +00:00
2011-12-23 10:34:21 +00:00
end