module WabisabiIndexModule

Public Instance Methods

index_class(classname) click to toggle source
# File vendor/qwik/lib/qwik/wabisabi-index.rb, line 55
def index_class(classname)
  return @klass[classname][0]
end
index_each_tag(element_name) { |e| ... } click to toggle source

Use parent.

# File vendor/qwik/lib/qwik/wabisabi-index.rb, line 60
def index_each_tag(element_name)
  if ! defined?(@tags)
    self.make_index
  end

  tags = @tags[element_name]
  return if tags.nil?
  tags.each {|e|
    result = yield(e)

    parent = e.parent
    new_parent = []
    parent.each_with_index {|child, i|
      if child.object_id == e.object_id
        if result.nil?
          # do nothing.
        else
          new_parent << result
        end
      else
        new_parent << child
      end
    }

    parent.replace(new_parent)
  }
  return nil
end
index_tag(element_name) click to toggle source
# File vendor/qwik/lib/qwik/wabisabi-index.rb, line 51
def index_tag(element_name)
  return @tags[element_name][0]
end
make_index() click to toggle source
# File vendor/qwik/lib/qwik/wabisabi-index.rb, line 34
def make_index
  @tags  = Hash.new {|h, k| h[k] = [] }
  @klass = Hash.new {|h, k| h[k] = [] }

  self.traverse_element {|e|
    classname = e.attr(:class)
    if classname
      @klass[classname] << e
    end

    name = e.element_name
    @tags[name] << e
  }

  self.set_all_parent
end
parent() click to toggle source
# File vendor/qwik/lib/qwik/wabisabi-index.rb, line 15
def parent
  @parent = nil if ! defined?(@parent)
  return @parent
end
set_all_parent() click to toggle source
# File vendor/qwik/lib/qwik/wabisabi-index.rb, line 28
def set_all_parent
  self.traverse_with_parent {|parent, child|
    child.set_parent(parent)
  }
end
set_parent(parent) click to toggle source
# File vendor/qwik/lib/qwik/wabisabi-index.rb, line 10
def set_parent(parent)
  @parent = parent
  return nil
end
traverse_with_parent() { |self, child| ... } click to toggle source
# File vendor/qwik/lib/qwik/wabisabi-index.rb, line 20
def traverse_with_parent(&b)
  self.each {|child|
    next if ! child.is_a?(Array)
    yield(self, child)
    child.traverse_with_parent(&b)    # Recursive.
  }
end