Module: Rabbit::Parser::Ext::Image
- Included in:
- RD::Ext::Image
- Defined in:
- lib/rabbit/parser/ext/image.rb
Defined Under Namespace
Modules: Private
Class Method Summary collapse
- .make_image(canvas, uri_str, prop = {}, body: nil) ⇒ Object
- .make_image_from_file(canvas, source, extension: nil, **options) ⇒ Object
Class Method Details
.make_image(canvas, uri_str, prop = {}, body: nil) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/rabbit/parser/ext/image.rb', line 30 def make_image(canvas, uri_str, prop={}, body: nil) path = Private.uri_string_to_image_filename(canvas, uri_str) begin image = Element::Image.new(path, prop, canvas: canvas) rescue Error canvas.logger.warn($!.) nil else if prop["align"] == "right" and body if body["background-image"] raise ParseError, _("multiple right aligns aren't supported.") end prop.each do |name, value| name = name.gsub(/_/, "-") next if name == "src" property_name = "background-image-#{name}" body[property_name] = value end body["background-image"] = uri_str :no_element else image end end end |
.make_image_from_file(canvas, source, extension: nil, **options) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/rabbit/parser/ext/image.rb', line 57 def make_image_from_file(canvas, source, extension: nil, **) src_basename = "rabbit-image-source" src_basename = [src_basename, extension] if extension src_file = Tempfile.new(src_basename) src_file.open src_file.print(source) src_file.close image_file = prop = nil begin image_file, prop = yield(src_file) rescue ImageLoadError canvas.logger.warn($!.) end return nil if image_file.nil? image = make_image(canvas, "file://#{image_file.path}", prop, **) # Protect image from GC case image when Element::Image image["_src"] = image_file when :no_element [:body]["_background-image-src"] = image_file end image end |