module HTree::Container
Public Instance Methods
apply(data)
click to toggle source
# File vendor/qwik/lib/qwik/htree-template.rb, line 50 def apply(data) replace {|e| eid = e.get_attr('id') next e if eid.nil? eid = eid.intern d = data[eid] next nil if d.nil? next e if d == true if d.is_a? HTree::Attr next e.clone_with(d) elsif d.is_a? Array next e.clone_with(d.flatten) end e.clone_with(d) } end
each_class(klass)
click to toggle source
# File vendor/qwik/lib/qwik/htree-get.rb, line 72 def each_class(klass) # obsolete return each_has_attr('class', klass, &b) end
each_has_attr(attr, value) { |to_node| ... }
click to toggle source
# File vendor/qwik/lib/qwik/htree-get.rb, line 80 def each_has_attr(attr, value) make_loc.traverse_element {|l| if l.to_node.get_attr(attr) == value yield(l.to_node) end } end
each_in_class(klass) { |l| ... }
click to toggle source
# File vendor/qwik/lib/qwik/htree-get.rb, line 38 def each_in_class(klass) klass, knum = split_name_num(klass) k = 1 klass_path = nil make_loc.traverse_element {|l| if klass_path.nil? if l.to_node.get_attr('class') == klass if k == knum klass_path = l.path else k += 1 end end elsif l.path.include?(klass_path) yield l end } return nil end
find_nth_element(num=1, *names)
click to toggle source
# File vendor/qwik/lib/qwik/htree-get.rb, line 23 def find_nth_element(num=1, *names) i = 1 traverse_element(*names) {|e| return e if i == num i += 1 } return nil end
get_a_path(path)
click to toggle source
# File vendor/qwik/lib/qwik/htree-get.rb, line 95 def get_a_path(path) if /\A(.*)\[(.+)\]\z/ =~ path tag = $1 select = $2 if /\A@([a-z]+)='([a-z]+)'\z/ =~ select attr = $1 value = $2 # if attr == 'class' # return get_class(cont) # end return get_has_attr(attr, value) end end return get_tag(path) end
get_class(klass)
click to toggle source
# File vendor/qwik/lib/qwik/htree-get.rb, line 76 def get_class(klass) # obsolete return get_has_attr('class', klass) end
get_class_tag(klass, tag)
click to toggle source
# File vendor/qwik/lib/qwik/htree-get.rb, line 58 def get_class_tag(klass, tag) tag, num = split_name_num(tag) i = 1 each_in_class(klass) {|l| ar = l.path.split('/') e = ar.last if e == tag return l.to_node if i == num i += 1 end } return nil end
get_has_attr(attr, value)
click to toggle source
# File vendor/qwik/lib/qwik/htree-get.rb, line 88 def get_has_attr(attr, value) each_has_attr(attr, value) {|l| return l.to_node } return nil end
get_path(path)
click to toggle source
# File vendor/qwik/lib/qwik/htree-get.rb, line 112 def get_path(path) xml = self path.split('/').each {|pa| if 0 < pa.length return nil if xml.nil? xml = xml.get_a_path(pa) end } return xml end
get_tag(tag)
click to toggle source
# File vendor/qwik/lib/qwik/htree-get.rb, line 32 def get_tag(tag) tag, num = split_name_num(tag) names = html_tags(tag) return find_nth_element(num, *names) end
replace(*otags) { |descendant| ... }
click to toggle source
# File vendor/qwik/lib/qwik/htree-template.rb, line 26 def replace(*otags, &block) tags = html_tags(*otags) subst = {} each_child_with_index {|descendant, i| if ! descendant.elem? subst[i] = descendant next end if tags.length == 0 || tags.include?(descendant.name) y = yield(descendant) if !(y === descendant) subst[i] = y next end end subst[i] = descendant.replace(*tags, &block) } return to_node.subst_subnode(subst) end
Also aliased as: each_tag
split_name_num(name)
click to toggle source
# File vendor/qwik/lib/qwik/htree-get.rb, line 13 def split_name_num(name) name = name.sub(%r|(^//)|, '') if /^(\w+)\[(\d+)\]$/ =~ name return [$1, $2.to_i] end return [name, 1] end