Class: Comet::Class

Inherits:
Context show all
Defined in:
lib/comet-html/parser-class.rb

Direct Known Subclasses

Repeater, SlotBase

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Context

#context, element_base_type, find_cpp_type, generate_new_ref_name, has_cpp_type?, load_global_element_types, reset, template_base_subtype, template_base_type, use_cpp_type

Constructor Details

#initialize(el, parent = nil) ⇒ Class

Returns a new instance of Class.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/comet-html/parser-class.rb', line 10

def initialize el, parent = nil
  context.classes << self
  parent.children << self unless parent.nil?
  el["_cheerp_class"] = self if el.class != Nokogiri::XML::NodeSet
  @el              = el
  @superclass      = if is_root? then context.template_base_type else context.template_base_subtype end
  @parent          = parent
  @refs            = []
  @bindings        = []
  @slots           = []
  @slot_plugins    = []
  @repeaters       = []
  @event_listeners = []
  @children        = []
end

Instance Attribute Details

#anchor_nameObject

Returns the value of attribute anchor_name.



7
8
9
# File 'lib/comet-html/parser-class.rb', line 7

def anchor_name
  @anchor_name
end

#bindingsObject (readonly)

Returns the value of attribute bindings.



8
9
10
# File 'lib/comet-html/parser-class.rb', line 8

def bindings
  @bindings
end

#childrenObject (readonly)

Returns the value of attribute children.



8
9
10
# File 'lib/comet-html/parser-class.rb', line 8

def children
  @children
end

#elObject (readonly)

Returns the value of attribute el.



8
9
10
# File 'lib/comet-html/parser-class.rb', line 8

def el
  @el
end

#event_listenersObject (readonly)

Returns the value of attribute event_listeners.



8
9
10
# File 'lib/comet-html/parser-class.rb', line 8

def event_listeners
  @event_listeners
end

#inline_codeObject

Returns the value of attribute inline_code.



7
8
9
# File 'lib/comet-html/parser-class.rb', line 7

def inline_code
  @inline_code
end

#parentObject (readonly)

Returns the value of attribute parent.



8
9
10
# File 'lib/comet-html/parser-class.rb', line 8

def parent
  @parent
end

#refsObject (readonly)

Returns the value of attribute refs.



8
9
10
# File 'lib/comet-html/parser-class.rb', line 8

def refs
  @refs
end

#repeatersObject (readonly)

Returns the value of attribute repeaters.



8
9
10
# File 'lib/comet-html/parser-class.rb', line 8

def repeaters
  @repeaters
end

#slot_pluginsObject (readonly)

Returns the value of attribute slot_plugins.



8
9
10
# File 'lib/comet-html/parser-class.rb', line 8

def slot_plugins
  @slot_plugins
end

#slotsObject (readonly)

Returns the value of attribute slots.



8
9
10
# File 'lib/comet-html/parser-class.rb', line 8

def slots
  @slots
end

#superclassObject

Returns the value of attribute superclass.



7
8
9
# File 'lib/comet-html/parser-class.rb', line 7

def superclass
  @superclass
end

#typenameObject

Returns the value of attribute typename.



7
8
9
# File 'lib/comet-html/parser-class.rb', line 7

def typename
  @typename
end

Instance Method Details

#blocks_remote_references?Boolean

Returns:

  • (Boolean)


125
126
127
# File 'lib/comet-html/parser-class.rb', line 125

def blocks_remote_references?
  false
end

#collect_childrenObject



61
62
63
64
65
66
67
# File 'lib/comet-html/parser-class.rb', line 61

def collect_children
  children = []
  context.classes.each do |object|
    children << object if object.parent == self
  end
  children
end

#constructor_declObject



30
31
32
# File 'lib/comet-html/parser-class.rb', line 30

def constructor_decl
  "#{@typename}(#{if parent.nil? then "" else "#{parent.typename}*" end});"
end

#create_reference(el, mode) ⇒ Object



121
122
123
# File 'lib/comet-html/parser-class.rb', line 121

def create_reference el, mode
  @refs << Reference.new(el, self, mode)
end

#find_class_for(el) ⇒ Object



42
43
44
45
46
47
# File 'lib/comet-html/parser-class.rb', line 42

def find_class_for el
  collect_children.each do |child|
    return child if child.el == el
  end
  nil
end

#find_reference_for(el) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/comet-html/parser-class.rb', line 34

def find_reference_for el
  @refs.each do |ref|
    return ref if ref.el == el
  end
  return ThisReference.new if el == @el
  nil
end

#implements_ibindable_view?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/comet-html/parser-class.rb', line 26

def implements_ibindable_view?
  false
end

#is_anchorable?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/comet-html/parser-class.rb', line 53

def is_anchorable?
  false
end

#is_root?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/comet-html/parser-class.rb', line 49

def is_root?
  @parent.nil?
end

#probeObject



84
85
86
87
88
89
# File 'lib/comet-html/parser-class.rb', line 84

def probe
  probe_subtypes
  probe_slots_plugins
  probe_references
  probe_bindings
end

#probe_bindings(root = nil) ⇒ Object



129
130
131
132
133
134
135
136
# File 'lib/comet-html/parser-class.rb', line 129

def probe_bindings root = nil
  root = @el if root.nil?
  root.children.each do |el|
    next unless el["_cheerp_class"].nil?
    probe_bindings_for el
    probe_bindings el unless context.has_cpp_type?(el)
  end
end

#probe_bindings_for(el) ⇒ Object



138
139
140
141
142
143
144
145
146
# File 'lib/comet-html/parser-class.rb', line 138

def probe_bindings_for el
  el.attributes.each do |key, value|
    if key.end_with? ".trigger"
      @event_listeners << EventListener.new(el, self, key, value)
    elsif key.end_with? ".bind"
      @bindings << Binding.new(el, self, key, value)
    end
  end
end

#probe_references(root = nil) ⇒ Object



107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/comet-html/parser-class.rb', line 107

def probe_references root = nil
  root = @el if root.nil?
  root.children.each do |el|
    next unless el["_cheerp_class"].nil?
    next unless find_reference_for(el).nil?
    if !(el["ref"].nil?)
      create_reference(el, :explicit)
    elsif context.has_cpp_type?(el)
      create_reference(el, :implicit)
    end
    probe_references el unless context.has_cpp_type?(el)
  end
end

#probe_slots_plugins(root = nil) ⇒ Object



148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/comet-html/parser-class.rb', line 148

def probe_slots_plugins root = nil
  root = @el if root.nil?
  root.children.each do |el|
    next unless el["_cheerp_class"].nil?
    if context.has_cpp_type?(el)
      el.children.each do |candidate|
        unless candidate["slot"].nil?
          @slot_plugins << (SlotPlugin.new candidate, self, el)
          @slot_plugins.last.probe
        else
          candidate.remove # Non-slot children for cpp custom elements must be ignored
        end
      end
    else
      probe_slots_plugins el
    end
  end
end

#probe_subtypes(root = nil) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/comet-html/parser-class.rb', line 91

def probe_subtypes root = nil
  root = @el if root.nil?
  root.children.each do |el|
    context.use_cpp_type el.name if context.has_cpp_type?(el)
    if Slot::Probe.matches? el
      @slots << Slot.new(el, self)
      @slots.last.probe
    elsif Repeater::Probe.matches? el
      @repeaters << Repeater.new(el, self)
      @repeaters.last.probe
    else
      probe_subtypes el unless context.has_cpp_type?(el)
    end
  end
end

#recursively_collect_childrenObject



69
70
71
72
73
74
75
76
# File 'lib/comet-html/parser-class.rb', line 69

def recursively_collect_children
  children = collect_children
  descendants = []
  children.each do |child|
    descendants += child.recursively_collect_children
  end
  children + descendants
end

#rootObject



78
79
80
81
82
# File 'lib/comet-html/parser-class.rb', line 78

def root
  current_class = @parent
  current_class = current_class.parent until current_class.parent.nil?
  current_class
end

#should_skip?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/comet-html/parser-class.rb', line 57

def should_skip?
  false
end