Sha256: 589c3fec94f683be5fc0485812d200e887f024f761834f8c20ac02ae9444aab6

Contents?: true

Size: 1.25 KB

Versions: 7

Compression:

Stored size: 1.25 KB

Contents

require 'pycall'
require 'iruby'

module PyCall
  module IRubyHelper
    private

    def check_python_object_respond_to_format_method(obj, method_name)
      return false unless obj.kind_of? PyObjectWrapper
      return false unless obj.respond_to? method_name
      true
    end

    def register_python_object_formatter(format_name, mime, priority_value=0)
      method_name = :"_repr_#{format_name}_"
      match do |obj|
        check_python_object_respond_to_format_method(obj, method_name)
      end
      priority priority_value
      format mime, &method_name
    end
  end
end

::IRuby::Display::Registry.module_eval do
  extend PyCall::IRubyHelper

  register_python_object_formatter :html, 'text/html', 1
  register_python_object_formatter :markdown, 'text/markdown', 1
  register_python_object_formatter :svg, 'image/svg+xml', 1
  register_python_object_formatter :png, 'image/png', 1
  register_python_object_formatter :jpeg, 'image/jpeg', 1
  register_python_object_formatter :latex, 'text/latex', 1
  register_python_object_formatter :json, 'application/json', 1
  register_python_object_formatter :javascript, 'application/javascript', 1
  register_python_object_formatter :pdf, 'application/pdf', 1
  register_python_object_formatter :pretty, 'text/plain', -1000
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
pycall-1.2.0 lib/pycall/iruby_helper.rb
pycall-1.2.0.beta1 lib/pycall/iruby_helper.rb
pycall-1.1.0.rc1 lib/pycall/iruby_helper.rb
pycall-1.0.3 lib/pycall/iruby_helper.rb
pycall-1.0.2-x86-mingw32 lib/pycall/iruby_helper.rb
pycall-1.0.2-x64-mingw32 lib/pycall/iruby_helper.rb
pycall-1.0.2 lib/pycall/iruby_helper.rb