Class: Domle::Element

Inherits:
Rexle::Element
  • Object
show all
Defined in:
lib/domle.rb

Direct Known Subclasses

Script, Style

Defined Under Namespace

Classes: ClassList

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = , value: nil, attributes: {}, rexle: nil) ⇒ Element

Returns a new instance of Element.



82
83
84
85
86
87
88
89
# File 'lib/domle.rb', line 82

def initialize(name=self.class.to_s.downcase[/\w+$/], value: nil, \
                      attributes: {}, rexle: nil)

  attributes.merge!(style: '') unless attributes.has_key? :style
  super(name, value: value, attributes: VisualAttributes.new(attributes),
        rexle: rexle)

end

Instance Attribute Details

#attr_mapObject (readonly)

Returns the value of attribute attr_map.



80
81
82
# File 'lib/domle.rb', line 80

def attr_map
  @attr_map
end

Class Method Details

.attr2_accessor(*a) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/domle.rb', line 91

def self.attr2_accessor(*a)

  a.concat %i(id transform)
  # DOM events
  a.concat %i(onload onmousemove onmousedown onmouseenter
  onmouseleave onclick onscroll onkeydown onkeyup)

  a.each do |attribute|

    class_eval do

      define_method attribute.to_s.gsub('-','_').to_sym do
        attributes[attribute]
      end

      define_method (attribute.to_s + '=').to_sym do |val|
        attributes[attribute] = val
        rexle().refresh if rexle?
        attr_update(attribute, val)
        val
      end

    end
  end

  def rexle?()
    not @rexle.nil?
  end

  def rexle()
    @rexle
  end

end

.attr_mapper(h) ⇒ Object



126
127
128
# File 'lib/domle.rb', line 126

def self.attr_mapper(h)
  @attr_map = h
end

Instance Method Details

#active=(v) ⇒ Object



134
135
136
# File 'lib/domle.rb', line 134

def active=(v)
  @active = v
end

#active?Boolean

Returns:

  • (Boolean)


130
131
132
# File 'lib/domle.rb', line 130

def active?()
  @active
end

#classlistObject



138
139
140
141
142
143
144
145
146
147
# File 'lib/domle.rb', line 138

def classlist()

  a = attributes[:class]
  cl = ClassList.new(a, @rexle, self)




  return cl
end

#hotspot?(x, y) ⇒ Boolean

Returns:

  • (Boolean)


154
155
156
157
158
159
160
# File 'lib/domle.rb', line 154

def hotspot?(x,y)

  (boundary.first.is_a?(Array) ? boundary : [boundary]).all? do |box|
    x1, y1, x2, y2 = box
    (x1..x2).include? x and (y1..y2).include? y
  end
end

#objObject



166
167
168
# File 'lib/domle.rb', line 166

def obj()
  @obj
end

#obj=(v) ⇒ Object



162
163
164
# File 'lib/domle.rb', line 162

def obj=(v)
  @obj = v
end

#rexleObject



120
121
122
# File 'lib/domle.rb', line 120

def rexle()
  @rexle
end

#rexle?Boolean

Returns:

  • (Boolean)


116
117
118
# File 'lib/domle.rb', line 116

def rexle?()
  not @rexle.nil?
end

#styleObject



149
150
151
# File 'lib/domle.rb', line 149

def style()
  attributes.style(@rexle)
end