Class: Ruta::Context
- Inherits:
-
Object
- Object
- Ruta::Context
- Defined in:
- lib/ruta/context.rb
Constant Summary collapse
- DOM =
::Kernel.method(:DOM)
Class Attribute Summary collapse
-
.collection ⇒ {ref => Context}
readonly
Hash of all Contexts created.
-
.current_context ⇒ Symbol
The reference to the current context being rendered.
-
.renderer ⇒ Proc
readonly
The renderer used to render and or mount components on to the DOM.
Instance Attribute Summary collapse
-
#elements ⇒ {ref => Route}
readonly
List of all routes attached to this context.
-
#handlers ⇒ {ref => Proc}
List of route handlers attached to this context.
-
#ref ⇒ {ref => Route}
readonly
List of all routes attached to this context.
-
#routes ⇒ {ref => Route}
List of all routes attached to this context.
-
#sub_contexts ⇒ Object
Returns the value of attribute sub_contexts.
Class Method Summary collapse
-
.define(ref) { ... } ⇒ Object
used to define a context’s page composition.
-
.handle_render {|object, element_id| ... } ⇒ Object
Used to tell the router how to render components to the DOM.
-
.render(context, id = nil) ⇒ Object
used to render a composition to the screen.
-
.wipe(id = nil) ⇒ Object
used to wipe clear an element’s content.
Instance Method Summary collapse
-
#component(id, attribs = {}) { ... } ⇒ Object
define a component of the composition.
-
#initialize(ref, block) ⇒ Context
constructor
A new instance of Context.
-
#sub_context(id, ref, attribs = {}) ⇒ Object
mount a context as a sub context here.
Constructor Details
#initialize(ref, block) ⇒ Context
Returns a new instance of Context.
22 23 24 25 26 27 28 29 |
# File 'lib/ruta/context.rb', line 22 def initialize ref,block @ref = ref @elements = {} @handlers = {} @routes = {} @sub_contexts = [] instance_exec(&block) if block end |
Class Attribute Details
.collection ⇒ {ref => Context} (readonly)
Returns Hash of all Contexts created.
|
|
# File 'lib/ruta/context.rb', line 61
|
.current_context ⇒ Symbol
Returns The reference to the current context being rendered.
|
|
# File 'lib/ruta/context.rb', line 67
|
.renderer ⇒ Proc (readonly)
Returns the renderer used to render and or mount components on to the DOM.
|
|
# File 'lib/ruta/context.rb', line 64
|
Instance Attribute Details
#elements ⇒ {ref => Route} (readonly)
Returns list of all routes attached to this context.
|
|
# File 'lib/ruta/context.rb', line 5
|
#handlers ⇒ {ref => Proc}
Returns list of route handlers attached to this context.
|
|
# File 'lib/ruta/context.rb', line 11
|
#ref ⇒ {ref => Route} (readonly)
Returns list of all routes attached to this context.
|
|
# File 'lib/ruta/context.rb', line 8
|
#routes ⇒ {ref => Route}
Returns list of all routes attached to this context.
17 |
# File 'lib/ruta/context.rb', line 17 attr_reader :elements, :ref |
#sub_contexts ⇒ Object
Returns the value of attribute sub_contexts.
18 19 20 |
# File 'lib/ruta/context.rb', line 18 def sub_contexts @sub_contexts end |
Class Method Details
.define(ref) { ... } ⇒ Object
used to define a context’s page composition
103 104 105 |
# File 'lib/ruta/context.rb', line 103 def define ref, &block @collection[ref] = new(ref,block) end |
.handle_render {|object, element_id| ... } ⇒ Object
Used to tell the router how to render components to the DOM
83 84 85 |
# File 'lib/ruta/context.rb', line 83 def handle_render &block @renderer = block end |
.render(context, id = nil) ⇒ Object
used to render a composition to the screen
122 123 124 125 126 127 |
# File 'lib/ruta/context.rb', line 122 def render context, id=nil this = id ? $document[id]: $document.body context_to_render = @collection[context] render_context_elements context_to_render,context, this render_element_contents context_to_render,context end |
.wipe(id = nil) ⇒ Object
used to wipe clear an element’s content
110 111 112 113 114 115 116 |
# File 'lib/ruta/context.rb', line 110 def wipe id=nil if id $document[id].clear else $document.body.clear end end |
Instance Method Details
#component(id, attribs = {}) { ... } ⇒ Object
define a component of the composition
37 38 39 40 41 42 43 |
# File 'lib/ruta/context.rb', line 37 def component id,attribs={}, &block self.elements[id] = { attributes: attribs, type: :element, content: block } end |
#sub_context(id, ref, attribs = {}) ⇒ Object
mount a context as a sub context here
50 51 52 53 54 55 56 57 |
# File 'lib/ruta/context.rb', line 50 def sub_context id,ref,attribs={} @sub_contexts << ref self.elements[id] = { attributes: attribs, type: :sub_context, content: ref, } end |