Class: Gloo::Objs::Partial

Inherits:
Core::Obj show all
Defined in:
lib/gloo/objs/web_svr/partial.rb

Constant Summary collapse

KEYWORD =
'partial'.freeze
KEYWORD_SHORT =
'part'.freeze
ON_RENDER =

Events

'on_render'.freeze
AFTER_RENDER =
'after_render'.freeze
PARAMS =

Parameters used during render.

'params'.freeze
CONTENT =

Content

'content'.freeze

Constants inherited from Core::Baseo

Core::Baseo::NOT_IMPLEMENTED_ERR

Instance Attribute Summary

Attributes inherited from Core::Obj

#children, #parent, #value

Attributes inherited from Core::Baseo

#name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Core::Obj

#add_child, can_create?, #can_receive_message?, #child_count, #child_index, #contains_child?, #delete_children, #dispatch, #display_value, #find_add_child, #find_child, #find_child_resolve_alias, #find_child_value, help, inherited, #initialize, #is_alias?, #is_function?, #msg_blank?, #msg_contains?, #msg_reload, #msg_unload, #pn, #remove_child, #root?, #send_message, #set_parent, #type_display, #value_display, #value_is_array?, #value_is_blank?, #value_string?

Methods inherited from Core::Baseo

#initialize, #type_display

Constructor Details

This class inherits a constructor from Gloo::Core::Obj

Class Method Details

.messagesObject

Get a list of message names that this object receives.



139
140
141
# File 'lib/gloo/objs/web_svr/partial.rb', line 139

def self.messages
  return super + [ 'render' ]
end

.short_typenameObject

The short name of the object type.



35
36
37
# File 'lib/gloo/objs/web_svr/partial.rb', line 35

def self.short_typename
  return KEYWORD_SHORT
end

.typenameObject

The name of the object type.



28
29
30
# File 'lib/gloo/objs/web_svr/partial.rb', line 28

def self.typename
  return KEYWORD
end

Instance Method Details

#add_children_on_create?Boolean

Does this object have children to add when an object is created in interactive mode? This does not apply during obj load, etc.

Returns:



112
113
114
# File 'lib/gloo/objs/web_svr/partial.rb', line 112

def add_children_on_create?
  return true
end

#add_default_childrenObject

Add children to this object. This is used by containers to add children needed for default configurations.



121
122
123
124
125
126
127
128
129
# File 'lib/gloo/objs/web_svr/partial.rb', line 121

def add_default_children
  fac = @engine.factory

  fac.create_script ON_RENDER, '', self
  fac.create_script AFTER_RENDER, '', self

  fac.create_can PARAMS, self
  fac.create_can CONTENT, self
end

#contentObject

Get the content obj.



57
58
59
# File 'lib/gloo/objs/web_svr/partial.rb', line 57

def content
  return find_child CONTENT
end

#msg_renderObject

Get the expiration date for the certificate.



146
147
148
149
150
# File 'lib/gloo/objs/web_svr/partial.rb', line 146

def msg_render
  part_content = self.render
  @engine.heap.it.set_to part_content 
  return part_content
end

#multiline_value?Boolean

Does this object support multi-line values? Initially only true for scripts.

Returns:



50
51
52
# File 'lib/gloo/objs/web_svr/partial.rb', line 50

def multiline_value?
  return false
end

#params_hashObject

Get the params hash from the child object. Returns nil if there is none.



65
66
67
68
69
70
71
72
73
74
75
# File 'lib/gloo/objs/web_svr/partial.rb', line 65

def params_hash
  params_can = find_child PARAMS
  return nil unless params_can

  h = {}
  params_can.children.each do |o|
    h[ o.name ] = o.value
  end

  return h
end

#render(render_ƒ = :render_html) ⇒ Object

Render the page. Use the specified render function or HTML by default.



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/gloo/objs/web_svr/partial.rb', line 161

def render( render_ƒ = :render_html )
  run_on_render

  part_content = ''
  data = content
  if data.children.empty?
    part_content = data.value
  else
    data.children.each do |e|
      part_content << e.send( render_ƒ )
    end
  end

  # part_content = Page.render_params part_content, params_hash
  part_content = @engine.running_app.obj.embedded_renderer.render part_content, params_hash

  run_after_render
  return part_content
end

#render_layout(head, body) ⇒ Object

Render the layout with the body and head params.



184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/gloo/objs/web_svr/partial.rb', line 184

def render_layout( head, body )
  run_on_render

  part_content = ''
  content.children.each do |e|
    e = Gloo::Objs::Alias.resolve_alias( @engine, e )

    obj = e.find_child CONTENT
    e = obj if obj

    part_content << Element.render_obj( e, :render_html, @engine )
  end

  params = params_hash || {}
  params[ 'head' ] = head
  params[ 'body' ] = body

  # part_content = Page.render_params part_content, params
  part_content = @engine.running_app.obj.embedded_renderer.render part_content, params

  run_after_render
  return part_content
end

#run_after_renderObject

Run the on rendered script if there is one.



95
96
97
98
99
100
# File 'lib/gloo/objs/web_svr/partial.rb', line 95

def run_after_render
  o = find_child AFTER_RENDER
  return unless o

  Gloo::Exec::Dispatch.message( @engine, 'run', o )
end

#run_on_renderObject

Run the on render script if there is one.



85
86
87
88
89
90
# File 'lib/gloo/objs/web_svr/partial.rb', line 85

def run_on_render
  o = find_child ON_RENDER
  return unless o

  Gloo::Exec::Dispatch.message( @engine, 'run', o )
end

#set_value(new_value) ⇒ Object

Set the value with any necessary type conversions.



42
43
44
# File 'lib/gloo/objs/web_svr/partial.rb', line 42

def set_value( new_value )
  self.value = new_value.to_s
end