module WabisabiBasicModule

Public Instance Methods

attr(k=nil) click to toggle source
# File vendor/qwik/lib/qwik/wabisabi-basic.rb, line 8
def attr(k=nil)
  attr = self[1]
  return nil unless attr.is_a?(Hash)
  return attr[k] if k
  return attr
end
children() click to toggle source
# File vendor/qwik/lib/qwik/wabisabi-basic.rb, line 41
def children
  children = []
  self.each_child {|child|
    children << child
  }
  return children
end
each_child() { |e| ... } click to toggle source
# File vendor/qwik/lib/qwik/wabisabi-basic.rb, line 34
def each_child
  self.each {|e|
    next if e.is_a?(Symbol) || e.is_a?(Hash)
    yield(e)
  }
end
each_child_with_index() { |e, i| ... } click to toggle source
# File vendor/qwik/lib/qwik/wabisabi-basic.rb, line 49
def each_child_with_index
  i = 0
  self.each_child {|e|
    yield(e, i)
    i += 1
  }
end
each_element(elementname) { |e| ... } click to toggle source
# File vendor/qwik/lib/qwik/wabisabi-basic.rb, line 90
def each_element(elementname)
  self.each {|e|
    if e.is_a?(Array) && e[0] == elementname
      yield(e)
    end
  }
end
element_name() click to toggle source
# File vendor/qwik/lib/qwik/wabisabi-basic.rb, line 25
def element_name
  return self[0] if self[0].is_a?(Symbol)
  return nil
end
get_single() click to toggle source
# File vendor/qwik/lib/qwik/wabisabi-basic.rb, line 83
def get_single
  if self.length == 1 && self.first.is_a?(Array)
    return self.first.get_single
  end
  return self
end
inside() click to toggle source
# File vendor/qwik/lib/qwik/wabisabi-basic.rb, line 30
def inside
  self.reject {|x| x.is_a?(Symbol) || x.is_a?(Hash) }
end
set_attr(new_attr) click to toggle source
# File vendor/qwik/lib/qwik/wabisabi-basic.rb, line 15
def set_attr(new_attr)
  attr = self.attr
  if attr
    attr.update(new_attr)
  else
    self.insert(1, new_attr)
  end
  return self         # For chain method.
end
text() click to toggle source
# File vendor/qwik/lib/qwik/wabisabi-basic.rb, line 57
def text
  i = 0
  while true
    x = self[i]
    if x.is_a?(Symbol) || x.is_a?(Hash)
      i += 1
      next
    else
      break
    end
  end

  (i...self.length).map {|i|
    x = self[i]
    if x.is_a?(String)
      x
    elsif x.is_a?(Array)
      if x[0] != :"!--"
        x.text
      end
    else
      nil
    end
  }.join
end