orbit-4-2/lib/parsers/parser_layout_widget.rb

23 lines
683 B
Ruby
Raw Permalink Normal View History

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