orbit-basic/lib/parsers/parser_layout.rb

35 lines
1.1 KiB
Ruby
Raw 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'])
end
2011-12-23 10:34:21 +00:00
2012-03-21 17:51:16 +00:00
body.css('.page_image').each do |image|
image = layout.design.images.detect{ |i| i.file_identifier.eql?(parse_html_image(image.to_html)) }
image.update_attributes(:name => image['name'], :html_id => image['id'], :html_class => image['class']) if image
end
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_html_image(html)
html.scan(/(?<=\<img)(.*?)(?=\/\>)/){
$1.gsub(' ','').scan(/(?<=src=\")(.*?)(?=\")/){
return File.basename($1).gsub(/[\\\"]/, '')
}
}
end
2012-03-21 17:51:16 +00:00
2011-12-23 10:34:21 +00:00
end