Module: IRuby::Display::Registry

Extended by:
Registry
Included in:
Registry
Defined in:
lib/iruby/display.rb

Constant Summary collapse

SUPPORTED_MIMES =
%w(
text/plain
text/html
text/latex
application/json
application/javascript
image/png
image/jpeg
image/svg+xml)

Instance Method Summary collapse

Instance Method Details

#format(mime = nil, &block) ⇒ Object



154
155
156
157
158
159
160
161
162
163
# 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) ⇒ Object



127
128
129
130
131
# File 'lib/iruby/display.rb', line 127

def match(&block)
  @match = block
  priority 0
  nil
end

#priority(p) ⇒ Object



149
150
151
152
# File 'lib/iruby/display.rb', line 149

def priority(p)
  @priority = p
  nil
end

#rendererObject



113
114
115
# File 'lib/iruby/display.rb', line 113

def renderer
  @renderer ||= []
end

#respond_to(name) ⇒ Object



133
134
135
# File 'lib/iruby/display.rb', line 133

def respond_to(name)
  match {|obj| obj.respond_to?(name) }
end

#type(&block) ⇒ Object



137
138
139
140
141
142
143
144
145
146
147
# 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