Orbit/lib/parsers/parser_layout_widget.rb

23 lines
683 B
Ruby
Raw Permalink Normal View History

2012-11-01 12:42:40 +00:00
module ParserLayoutWidget
require 'nokogiri'
def parse_widget_for_images(widget)
2012-11-05 15:04:54 +00:00
content = widget.widget_layout.file.read.force_encoding("UTF-8")
widge = Nokogiri::HTML(content)
a = []
b = []
2012-11-01 12:42:40 +00:00
widge.css('.widget_image').each do |page_image|
image = widget.images.where( file: File.basename(page_image['src']))[0]
2012-11-05 15:04:54 +00:00
a << page_image['src']
b << image.file
2012-11-01 12:42:40 +00:00
image.update_attributes(:html_id => page_image['id'], :html_class => page_image['class'], :in_html => true) if image
end
2012-11-05 15:04:54 +00:00
a.each_with_index do |img,i|
content = content.gsub(img,b[i].to_s)
end
widget.widget_layout.update_attributes(:body => content)
2012-11-01 12:42:40 +00:00
end
end