Modifications for images in html code

This commit is contained in:
chris2tof committed 2011-10-18 11:21:24 +08:00
1 parent 0ca354cfd0
commit 2e86d8081f
10 files changed
+110 -118

No files matched your search

+17 -3
View File
@@ -164,9 +164,11 @@ module Parser
res
end
c.define_tag 'image' do |tag|
asset = Asset.find(tag.attr['id'])
if asset
res = "<img src=#{asset.data.file.url} "
image = page.custom_images.detect{|image| image.name.eql?(tag.attr['name']) }
image = page.design.custom_images.detect{|image| image.name.eql?(tag.attr['name']) } unless image
image = page.design.images.detect{|image| image.name.eql?(tag.attr['name']) } unless image
if image
res = "<img src=#{image.file.url} "
tag.attr.each do |l|
res << "#{l[0]}='#{l[1]}' "
end
@@ -278,8 +280,20 @@ module Parser
c.define_tag 'content' do |tag|
layout.layout_parts.create(:name => tag.attr['name'], :editable => true)
end
c.define_tag 'image' do |tag|
image = layout.design.images.detect{ |i| i.file_filename.eql?(parse_html_image(tag.expand)) }
image.update_attributes(:name => tag.attr['name'], :html_id => tag.attr['id'], :html_class => tag.attr['class'])
end
end
end
def parse_html_image(html)
html.scan(/(?<=\<img)(.*?)(?=\/\>)/){
$1.gsub(' ','').scan(/(?<=src=\")(.*?)(?=\")/){
return File.basename($1).gsub(/[\\\"]/, '')
}
}
end
def self.included(base)
base.send :helper_method, :parse_page if base.respond_to? :helper_method