lib/brief/document/transformer.rb in brief-1.12.8 vs lib/brief/document/transformer.rb in brief-1.12.9
- old
+ new
@@ -10,31 +10,51 @@
@document = document
end
def all
transform_dynamic_links
+ include_images
inline_svg_content
end
def briefcase
@briefcase ||= document.briefcase
end
def inline_svg_content
- inline_svg_images.each do |img|
+ process_image_paths(inline_svg_images)
+ end
+
+ def include_images
+ process_image_paths(inline_image_tags)
+ end
+
+ def process_image_paths(set_of_tags)
+ set_of_tags.each do |img|
src = img['src'].to_s
if src.match(/=/)
_, value = img['src'].to_s.split("=")
else
value = src
end
begin
- if asset = briefcase.find_asset(value)
+ asset = briefcase.find_asset(value)
+
+ if !asset
+
+ end
+
+ if asset && asset.extname == ".svg"
img.replace("<div class='svg-wrapper'>#{ asset.read }</div>")
end
+
+ if asset && %w(.gif .jpg .jpeg .png).include?(asset.extname.to_s.downcase)
+ src = briefcase.get_external_url_for(asset)
+ img['src'] = src
+ end
rescue
nil
end
end
end
@@ -82,9 +102,13 @@
rescue
nil
end
private
+
+ def inline_image_tags
+ fragment.css('img[alt="include"]')
+ end
def inline_svg_images
fragment.css('img[alt="inline:svg"]')
end