Top Level Namespace

Defined Under Namespace

Modules: Comet, Guard Classes: String

Instance Method Summary collapse

Instance Method Details

#anchor_symbol_to_enum(anchor_name) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/comet-html/utils.rb', line 38

def anchor_symbol_to_enum anchor_name
  "Comet::" + case anchor_name
  when :append   then "AppendAnchor"
  when :prepend  then "PrependAnchor"
  when :children then "ChildrenAnchor"
  end
end

#extract_bind_mode_from(value) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/comet-html/utils.rb', line 65

def extract_bind_mode_from value
  bind_mode_match = value.to_s.match(/\s*&\s*(throttle|signal):([a-zA-Z0-9_-]+)$/)
  if bind_mode_match.nil?
    bind_mode = ""
  else
    value = value.to_s.delete_suffix bind_mode_match[0]
    bind_mode_enum = case bind_mode_match[1]
                     when 'signal' then "SignalBind"
                     when 'throttle' then "ThrottleBind"
                     else "StaticBind"
                     end
    bind_mode = ".use_mode(Comet::Bindable::#{bind_mode_enum}, \"#{bind_mode_match[2]}\")"
  end
  [value, bind_mode]
end

#find_anchorable_anchor(el) ⇒ Object

module Comet



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/comet-html/utils.rb', line 16

def find_anchorable_anchor el
  it = el
  loop do
    it = it.previous
    break if it.nil? || it.name != "text" || it.name == "comment"
  end
  unless it.nil?
    { el: it, mode: :append }
  else
    it = el
    loop do
      it = it.next
      break if it.nil? || it.name != "text" || it.name == "comment"
    end
    unless it.nil?
      { el: it, mode: :prepend }
    else
      { el: el.parent, mode: :children }
    end
  end
end

#has_trigger_attributes?(el) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
49
50
51
52
# File 'lib/comet-html/utils.rb', line 46

def has_trigger_attributes? el
  result = false
  el.attributes.each do |key,value|
    result = true if key.end_with?(".trigger")
  end
  result
end

#is_valid_cpp_variable_name?(value) ⇒ Boolean

Returns:

  • (Boolean)


81
82
83
84
85
86
87
# File 'lib/comet-html/utils.rb', line 81

def is_valid_cpp_variable_name? value
  if value.length <= 255
    not (value.match(/^[a-zA-Z_][a-zA-Z0-9_]*$/).nil?)
  else
    false
  end
end

#make_attr_from_el(el) ⇒ Object



54
55
56
57
58
59
60
61
62
63
# File 'lib/comet-html/utils.rb', line 54

def make_attr_from_el el
  hard_attributes  = []
  el.attributes.each do |key, value|
    reserved_keywords = ["ref", "slot", "_cheerp_class", "_cheerp_ref"]
    if !reserved_keywords.include?(key) && !(key.end_with? ".bind") && !(key.end_with? ".trigger") && !(key.end_with? ".for")
      hard_attributes << "{\"#{key}\",\"#{value}\"}"
    end
  end
  hard_attributes
end