module IRuby::Display::Registry

Constants

SUPPORTED_MIMES

Public Instance Methods

format(mime = nil, &block) click to toggle source
# File lib/iruby/display.rb, line 154
def format(mime = nil, &block)
  renderer << Renderer.new(@match, mime, block, @priority)
  renderer.sort_by! {|r| -r.priority }

  # Decrease priority implicitly for all formats
  # which are added later for a type.
  # Overwrite with the `priority` method!
  @priority -= 1
  nil
end
match(&block) click to toggle source
# File lib/iruby/display.rb, line 127
def match(&block)
  @match = block
  priority 0
  nil
end
priority(p) click to toggle source
# File lib/iruby/display.rb, line 149
def priority(p)
  @priority = p
  nil
end
renderer() click to toggle source
# File lib/iruby/display.rb, line 113
def renderer
  @renderer ||= []
end
respond_to(name) click to toggle source
# File lib/iruby/display.rb, line 133
def respond_to(name)
  match {|obj| obj.respond_to?(name) }
end
type(&block) click to toggle source
# File lib/iruby/display.rb, line 137
def type(&block)
  match do |obj|
    begin
      block.call === obj
    # We have to rescue all exceptions since constant autoloading could fail with a different error
    rescue Exception
    rescue #NameError
      false
    end
  end
end