Class: MetaRuby::GUI::HTML::Collection
- Inherits:
- 
      Qt::Object
      
        - Object
- Qt::Object
- MetaRuby::GUI::HTML::Collection
 
- Defined in:
- lib/metaruby/gui/html/collection.rb
Overview
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
Defined Under Namespace
Classes: Element
Instance Attribute Summary collapse
- 
  
    
      #manager  ⇒ RenderingManager 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    The object that manages the rendering objects, i.e. 
- 
  
    
      #object_id_to_object  ⇒ {Integer=>Object} 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Mapping from an element’s object_id to the corresponding object. 
- 
  
    
      #page  ⇒ #push 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    The page on which we publish the HTML. 
- 
  
    
      #registered_exceptions  ⇒ <Exception> 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Exceptions caught during element rendering. 
Instance Method Summary collapse
- 
  
    
      #clear  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Clear the current view. 
- 
  
    
      #disable  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Disable the current renderer. 
- #element_link_target(object, interactive) ⇒ Object
- 
  
    
      #enable  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Enable the current renderer. 
- 
  
    
      #initialize(page)  ⇒ Collection 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    Create a collection that acts on a page. 
- 
  
    
      #linkClickedHandler(url)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  private
  
    Handler called when a link is clicked on the page. 
- 
  
    
      #namespace  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    The namespace used on URIs generated by the collection. 
- 
  
    
      #register_type(type, rendering_class, render_options = Hash.new)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Registers a certain kind of model as well as the information needed to display it. 
- #render_all_elements(all, options) ⇒ Object
- #render_element(object, options = Hash.new) ⇒ Object
- 
  
    
      #render_links(title, links, push_options = Hash.new)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Render a list of Element. 
Constructor Details
#initialize(page) ⇒ Collection
Create a collection that acts on a page
| 27 28 29 30 31 32 33 34 | # 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 | 
Instance Attribute Details
#manager ⇒ RenderingManager (readonly)
Returns the object that manages the rendering objects, i.e. the objects that convert the element collections into HTML.
| 15 16 17 | # File 'lib/metaruby/gui/html/collection.rb', line 15 def manager @manager end | 
#object_id_to_object ⇒ {Integer=>Object} (readonly)
Returns mapping from an element’s object_id to the corresponding object.
| 18 19 20 | # File 'lib/metaruby/gui/html/collection.rb', line 18 def object_id_to_object @object_id_to_object end | 
#page ⇒ #push (readonly)
Returns the page on which we publish the HTML.
| 11 12 13 | # File 'lib/metaruby/gui/html/collection.rb', line 11 def page @page end | 
#registered_exceptions ⇒ <Exception> (readonly)
Returns exceptions caught during element rendering.
| 20 21 22 | # File 'lib/metaruby/gui/html/collection.rb', line 20 def registered_exceptions @registered_exceptions end | 
Instance Method Details
#clear ⇒ Object
Clear the current view
| 54 55 56 57 58 | # File 'lib/metaruby/gui/html/collection.rb', line 54 def clear @object_id_to_object.clear registered_exceptions.clear manager.clear end | 
#disable ⇒ Object
Disable the current renderer
| 48 49 50 51 | # 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 | 
#element_link_target(object, interactive) ⇒ Object
| 65 66 67 68 69 70 71 | # File 'lib/metaruby/gui/html/collection.rb', line 65 def element_link_target(object, interactive) if interactive id = "link://metaruby/#{namespace}#{object.object_id}" else id = "##{object.object_id}" end end | 
#enable ⇒ Object
Enable the current renderer
| 42 43 44 45 | # 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) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
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.
| 105 106 107 108 109 110 111 112 | # 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 ⇒ Object
The namespace used on URIs generated by the collection
| 61 62 63 | # 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) ⇒ Object
Registers a certain kind of model as well as the information needed to display it
It registers the given type on the model browser so that it gets displayed there.
| 37 38 39 | # File 'lib/metaruby/gui/html/collection.rb', line 37 def register_type(type, rendering_class, = Hash.new) manager.register_type(type, rendering_class, ) end | 
#render_all_elements(all, options) ⇒ Object
| 91 92 93 94 95 96 97 98 | # File 'lib/metaruby/gui/html/collection.rb', line 91 def render_all_elements(all, ) 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, .merge(element.)) end end | 
#render_element(object, options = Hash.new) ⇒ Object
| 116 117 118 119 120 121 122 123 124 125 126 127 | # File 'lib/metaruby/gui/html/collection.rb', line 116 def render_element(object, = Hash.new) page.restore registered_exceptions.clear = Hash[id: "#{namespace}/currently_rendered_element"].merge() begin manager.render(object, ) rescue ::Exception => e registered_exceptions << e end emit updated page.page.current_frame.scrollToAnchor([:id]) end | 
#render_links(title, links, push_options = Hash.new) ⇒ Object
Render a list of Element
| 79 80 81 82 83 84 85 86 87 88 89 | # File 'lib/metaruby/gui/html/collection.rb', line 79 def render_links(title, links, = Hash.new) links.each do |el| object_id_to_object[el.object.object_id] = el.object end links = links.map do |el| a_node = el.format % ["<a href=\"#{el.url}\">#{el.text}</a>"] [a_node, el.attributes || Hash.new] end page.render_list(title, links, ) end |