class MetaRuby::GUI::HTML::Collection

Base class providing functionality to first rendering a collection of object, and then render one item in the collection when the user clicks on the collection element

Rendering is delegated to other objects through a {RenderingManager}. The main interface to the manager is {#register_type}

Attributes

manager[R]

@return [RenderingManager] the object that manages the rendering

objects, i.e. the objects that convert the element collections
into HTML
object_id_to_object[R]

@return [{Integer=>Object}] mapping from an element's object_id to

the corresponding object
page[R]

@return [#push] the page on which we publish the HTML

registered_exceptions[R]

@return [<Exception>] exceptions caught during element rendering

Public Class Methods

new(page) click to toggle source

Create a collection that acts on a page

Calls superclass method
# File lib/metaruby/gui/html/collection.rb, line 27
def initialize(page)
    super()
    @page = page
    @manager = RenderingManager.new(page)

    @object_id_to_object = Hash.new
    @registered_exceptions = Array.new
end

Public Instance Methods

clear() click to toggle source

Clear the current view

# File lib/metaruby/gui/html/collection.rb, line 54
def clear
    @object_id_to_object.clear
    registered_exceptions.clear
    manager.clear
end
disable() click to toggle source

(see RenderingManager#disable)

# File lib/metaruby/gui/html/collection.rb, line 48
def disable
    disconnect(page, SIGNAL('linkClicked(const QUrl&)'), self, SLOT('linkClickedHandler(const QUrl&)'))
    manager.disable
end
enable() click to toggle source

(see RenderingManager#enable)

# File lib/metaruby/gui/html/collection.rb, line 42
def enable
    connect(page, SIGNAL('linkClicked(const QUrl&)'), self, SLOT('linkClickedHandler(const QUrl&)'))
    manager.enable
end
linkClickedHandler(url) click to toggle source

@api private

Handler called when a link is clicked on the page. It renders an object when the link is a link to an object of the collection, or passes the URL to the linkClicked signal otherwise.

Calls superclass method
# File lib/metaruby/gui/html/collection.rb, line 105
def linkClickedHandler(url)
    if url.host == "metaruby" && url.path =~ /^\/#{Regexp.quote(namespace)}(\d+)/
        object = object_id_to_object[Integer($1)]
        render_element(object)
    else
        super
    end
end
namespace() click to toggle source

The namespace used on URIs generated by the collection

# File lib/metaruby/gui/html/collection.rb, line 61
def namespace
    object_id.to_s + "/"
end
register_type(type, rendering_class, render_options = Hash.new) click to toggle source

(see RenderingManager#register_type)

# File lib/metaruby/gui/html/collection.rb, line 37
def register_type(type, rendering_class, render_options = Hash.new)
    manager.register_type(type, rendering_class, render_options)
end
render_all_elements(all, options) click to toggle source
# File lib/metaruby/gui/html/collection.rb, line 91
def render_all_elements(all, options)
    all.each do |element|
        object_id = element.object.object_id
        page.push(nil, "<h1 id=#{object_id}>#{element.format % element.text}</h1>")

        render_element(element.object, options.merge(element.rendering_options))
    end
end
render_element(object, options = Hash.new) click to toggle source
# File lib/metaruby/gui/html/collection.rb, line 116
def render_element(object, options = Hash.new)
    page.restore
    registered_exceptions.clear
    options = Hash[id: "#{namespace}/currently_rendered_element"].merge(options)
    begin
        manager.render(object, options)
    rescue ::Exception => e
        registered_exceptions << e
    end
    emit updated
    page.page.current_frame.scrollToAnchor(options[:id])
end