Class: Wee::RootComponent

Inherits:
Component show all
Defined in:
lib/wee/root_component.rb

Overview

A RootComponent has a special instanciate class method that makes it more comfortable for root components.

Direct Known Subclasses

HelloWorld

Constant Summary

Constants inherited from Component

Component::NO_CHILDREN

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Component

#add_decoration, #children, #choose_from, #confirm, #decoration, #decoration=, depends, #each_decoration, #find_decoration, #inform, #initialize, #process_callbacks, #remove_decoration, #remove_decoration_if, #render, #state

Methods inherited from Presenter

#process_callbacks, #render, #render!, #renderer_class, #state

Constructor Details

This class inherits a constructor from Wee::Component

Class Method Details

.external_resourcesObject

Returns an array of ExternalResource objects required for this RootComponent.



24
25
26
27
# File 'lib/wee/root_component.rb', line 24

def self.external_resources
  self.depends.flatten.select {|cls| cls <= Wee::ExternalResource }.uniq.
    map {|cls| cls.new }
end

.instanciate(*args, &block) ⇒ Object



37
38
39
40
41
# File 'lib/wee/root_component.rb', line 37

def self.instanciate(*args, &block)
  obj = new(*args, &block)
  obj.add_decoration Wee::PageDecoration.new(obj.title, obj.stylesheets, obj.javascripts)
  return obj
end

.run(*params, &block) ⇒ Object



12
13
14
# File 'lib/wee/root_component.rb', line 12

def self.run(*params, &block)
  Wee.run(self, *params, &block)
end

Instance Method Details

#javascriptsObject



33
34
35
# File 'lib/wee/root_component.rb', line 33

def javascripts
  self.class.external_resources.map {|ext_res| ext_res.javascripts}.flatten
end

#stylesheetsObject



29
30
31
# File 'lib/wee/root_component.rb', line 29

def stylesheets
  self.class.external_resources.map {|ext_res| ext_res.stylesheets}.flatten
end

#titleObject



16
17
18
# File 'lib/wee/root_component.rb', line 16

def title
  self.class.name.to_s
end