Class: Comet::Repeater

Inherits:
Class show all
Defined in:
lib/comet-html/parser-repeater.rb

Defined Under Namespace

Classes: Probe

Instance Attribute Summary collapse

Attributes inherited from Class

#anchor_name, #bindings, #children, #el, #event_listeners, #inline_code, #parent, #refs, #repeaters, #slot_plugins, #slots, #superclass, #typename

Instance Method Summary collapse

Methods inherited from Class

#collect_children, #create_reference, #find_class_for, #find_reference_for, #implements_ibindable_view?, #is_root?, #probe_bindings, #probe_bindings_for, #probe_references, #probe_slots_plugins, #probe_subtypes, #recursively_collect_children, #root, #should_skip?

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) ⇒ Repeater

Returns a new instance of Repeater.

Raises:



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/comet-html/parser-repeater.rb', line 19

def initialize el, parent
  super el, parent
  value, bind_mode = extract_bind_mode_from el["repeat.for"].to_s
  parts = value.to_s.match /^\s*(\[([^\]]+)\])?\s*([^\s]+)\s+of\s+\[([^\]]+)\]\s*(.*)$/
  raise ParseError.new(el, "invalid repeater definition: `#{value}`") if parts.nil?
  @typename   = "#{context.classes.first.typename}Repeatable_#{context.repeater_count}"
  @superclass = context.find_cpp_type(el.name, fallback: context.template_base_subtype)

  @repeater_name = "repeater_#{context.repeater_count}"
  @value_type    = parts[2] || "#{parts[4]}::value_type"
  @value_name    = parts[3]
  @list_type     = parts[4]
  @list_name     = parts[5]
  @bind_mode     = bind_mode
  
  unless is_valid_cpp_variable_name?(@value_name)
    raise ParseError.new(el, "invalid variable name `#{@value_name}`") 
  end

  context.repeater_count += 1
end

Instance Attribute Details

#anchorObject (readonly)

Returns the value of attribute anchor.



17
18
19
# File 'lib/comet-html/parser-repeater.rb', line 17

def anchor
  @anchor
end

#bind_modeObject (readonly)

Returns the value of attribute bind_mode.



17
18
19
# File 'lib/comet-html/parser-repeater.rb', line 17

def bind_mode
  @bind_mode
end

#list_nameObject (readonly)

Returns the value of attribute list_name.



17
18
19
# File 'lib/comet-html/parser-repeater.rb', line 17

def list_name
  @list_name
end

#list_typeObject (readonly)

Returns the value of attribute list_type.



17
18
19
# File 'lib/comet-html/parser-repeater.rb', line 17

def list_type
  @list_type
end

#repeater_nameObject (readonly)

Returns the value of attribute repeater_name.



17
18
19
# File 'lib/comet-html/parser-repeater.rb', line 17

def repeater_name
  @repeater_name
end

#value_nameObject (readonly)

Returns the value of attribute value_name.



17
18
19
# File 'lib/comet-html/parser-repeater.rb', line 17

def value_name
  @value_name
end

#value_typeObject (readonly)

Returns the value of attribute value_type.



17
18
19
# File 'lib/comet-html/parser-repeater.rb', line 17

def value_type
  @value_type
end

Instance Method Details

#blocks_remote_references?Boolean

Returns:

  • (Boolean)


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

def blocks_remote_references?
  true
end

#constructor_declObject



41
42
43
# File 'lib/comet-html/parser-repeater.rb', line 41

def constructor_decl
  "#{@typename}(#{parent.typename}*, #{@value_type});"
end

#is_anchorable?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/comet-html/parser-repeater.rb', line 45

def is_anchorable?
  true
end

#probeObject



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

def probe
  super
  probe_bindings_for el
end