Class: Gloo::Objs::Element

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

Constant Summary collapse

KEYWORD =
'element'.freeze
KEYWORD_SHORT =
'e'.freeze
ID =

Element

'id'.freeze
CLASSES =
'classes'.freeze
ATTRIBUTES =
'attributes'.freeze
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_container?, #is_function?, #msg_blank?, #msg_contains?, #msg_reload, #msg_unload, #pn, #remove_child, #render, #root?, #send_message, #set_parent, #sql_value, #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.



168
169
170
# File 'lib/gloo/objs/web_svr/element.rb', line 168

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

.render_obj(obj, render_ƒ, engine) ⇒ Object

Render an object which might be an element, a container of items, or something else.



219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
# File 'lib/gloo/objs/web_svr/element.rb', line 219

def self.render_obj obj, render_ƒ, engine
  rendered_obj_content = ''
  return nil unless obj

  if obj.children.size > 0
    obj.children.each do |e|

      e = Gloo::Objs::Alias.resolve_alias( engine, e )
      if e.class == Element
        rendered_obj_content << e.send( render_ƒ )
      elsif e
        data = render_thing e, render_ƒ, engine
        ( rendered_obj_content << data ) if data # e.render( render_ƒ )
      end
    end
  else
    rendered_obj_content << obj.value
  end

  return rendered_obj_content
end

.render_thing(e, render_ƒ, engine) ⇒ Object



241
242
243
244
245
246
247
248
# File 'lib/gloo/objs/web_svr/element.rb', line 241

def self.render_thing e, render_ƒ, engine
  begin
    return e.render( render_ƒ )
  rescue => e
    engine.log_exception e
    return ''
  end
end

.short_typenameObject

The short name of the object type.



40
41
42
# File 'lib/gloo/objs/web_svr/element.rb', line 40

def self.short_typename
  return KEYWORD_SHORT
end

.typenameObject

The name of the object type.



33
34
35
# File 'lib/gloo/objs/web_svr/element.rb', line 33

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:



140
141
142
# File 'lib/gloo/objs/web_svr/element.rb', line 140

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.



149
150
151
152
153
154
155
156
157
158
# File 'lib/gloo/objs/web_svr/element.rb', line 149

def add_default_children
  fac = @engine.factory

  # Create attributes with ID and Classes
  attr = fac.create_can ATTRIBUTES, self
  fac.create_string ID, '', attr
  fac.create_string CLASSES, '', attr

  fac.create_can CONTENT, self
end

#attributes_hashObject

Return the array of attributes if there are any.



62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/gloo/objs/web_svr/element.rb', line 62

def attributes_hash
  attr_can = find_child ATTRIBUTES

  if attr_can && attr_can.children.size > 0
    h = {}
    attr_can.children.each do |o|
      h[ o.name ] = o.value
    end
    return h
  end

  return {}
end

#content_childObject

Get all the children elements of the content.



127
128
129
# File 'lib/gloo/objs/web_svr/element.rb', line 127

def content_child
  return find_child CONTENT
end

#msg_renderObject

Get the expiration date for the certificate.



175
176
177
178
179
# File 'lib/gloo/objs/web_svr/element.rb', line 175

def msg_render
  content = self.render_html
  @engine.heap.it.set_to content 
  return content
end

#multiline_value?Boolean

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

Returns:



55
56
57
# File 'lib/gloo/objs/web_svr/element.rb', line 55

def multiline_value?
  return false
end

#render_content(render_ƒ) ⇒ Object

Render the element content using the specified render function. This is a recursive function (through one of the other render functions).



208
209
210
211
212
213
# File 'lib/gloo/objs/web_svr/element.rb', line 208

def render_content render_ƒ
  obj = content_child
  obj = self if obj.nil?

  return Element.render_obj( obj, render_ƒ, @engine )
end

#render_htmlObject

Render the element as HTML.



189
190
191
192
193
# File 'lib/gloo/objs/web_svr/element.rb', line 189

def render_html
  content_text = render_content :render_html

  return "#{tag_open}#{content_text}#{tag_close}"
end

#render_textObject

Render the element as text, without tags.



198
199
200
201
202
# File 'lib/gloo/objs/web_svr/element.rb', line 198

def render_text
  content_text = render_content :render_text

  return "#{content_text}"
end

#set_value(new_value) ⇒ Object

Set the value with any necessary type conversions.



47
48
49
# File 'lib/gloo/objs/web_svr/element.rb', line 47

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

#tagObject

Get the tag. This is the name, up until an ‘_’ char. Because name must be unique in the parent, and with HTML we need a way to have multiple of the same tag at the same level.



100
101
102
103
# File 'lib/gloo/objs/web_svr/element.rb', line 100

def tag
  i = self.name.index( '_' )        
  return i ? self.name[ 0..(i-1) ] : self.name
end

#tag_attributesObject

Get all attributes of the tag.



79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/gloo/objs/web_svr/element.rb', line 79

def tag_attributes
  attr_h = attributes_hash
  return nil unless attr_h && attr_h.size > 0

  attr_str = ''
  attr_h.each do |k,v|
    unless v.blank?
      attr_str << " #{k}=\"#{v}\"" 
    end
  end

  return attr_str
end

#tag_closeObject

Get the closing tag.



120
121
122
# File 'lib/gloo/objs/web_svr/element.rb', line 120

def tag_close
  return "</#{tag}>"
end

#tag_openObject

Get the opening tag.



108
109
110
111
112
113
114
115
# File 'lib/gloo/objs/web_svr/element.rb', line 108

def tag_open
  tag_attributes = self.tag_attributes
  if tag_attributes
    return "<#{tag}#{tag_attributes}>"
  else
    return "<#{tag}>"
  end
end