Module: Inlay::IRubyIntegration
- Defined in:
- lib/inlay/iruby.rb
Defined Under Namespace
Modules: MimeBundle
Class Method Summary collapse
- .html(object) ⇒ Object
- .install ⇒ Object
- .mimebundle(object, include: []) ⇒ Object
- .png(object) ⇒ Object
- .svg(object) ⇒ Object
Class Method Details
.html(object) ⇒ Object
33 34 35 36 37 |
# File 'lib/inlay/iruby.rb', line 33 def html(object) animation_html(Inlay.normalize(object)) rescue StandardError nil end |
.install ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/inlay/iruby.rb', line 20 def install unless @registered registry = IRuby::Display::Registry registry.match { |object| Inlay.displayable?(object) } registry.format("text/html") { |object| html(object) } registry.format("image/svg+xml") { |object| svg(object) } registry.format("image/png") { |object| png(object) } @registered = true end install_mimebundle true end |
.mimebundle(object, include: []) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/inlay/iruby.rb', line 51 def mimebundle(object, include: []) normalized = Inlay.normalize(object) formats = {} formats["text/html"] = animation_html(normalized) if normalized.frames formats["image/svg+xml"] = normalized.svg if normalized.svg png_bytes = png_content(normalized) formats["image/png"] = Base64.strict_encode64(png_bytes) if png_bytes formats.select! { |mime, _| include.empty? || include.include?(mime) } [formats, {}] rescue StandardError [{}, {}] end |
.png(object) ⇒ Object
45 46 47 48 49 |
# File 'lib/inlay/iruby.rb', line 45 def png(object) png_content(Inlay.normalize(object)) rescue LoadError, StandardError nil end |
.svg(object) ⇒ Object
39 40 41 42 43 |
# File 'lib/inlay/iruby.rb', line 39 def svg(object) Inlay.normalize(object).svg rescue StandardError nil end |