class Array

Public Instance Methods

dom(*tags, mounted: nil, **attr) click to toggle source
# File lib/dom.rb, line 153
def dom *tags, mounted: nil, **attr
        *recurse, tag = tags
        a = self
        a = block_given? ? map(&Proc.new) : flatten if recurse.empty?
        if recurse.length <= 1
                #!index: Using `index` instead of `find` to be able to detect `nil`.
                #   (Which turned out irrelevant.)
                if i = a.index{|e| e.kind_of?(String).! and e.kind_of?(Array).! and e.nil?.!}
                        raise ArgumentError
                        .new("Expecting all array elements to be a string: `#{a[i].class}:#{a[i].inspect}'")
                end
        else
                #!index:
                if i = a.index{|e| e.kind_of?(Array).!}
                        raise ArgumentError
                        .new("Cannot apply tag `#{recurse[-2].inspect}' to `#{a[i].class}:#{a[i].inspect}'")
                end
        end
        a = a.map{|e| e.dom(*recurse, &(Proc.new if block_given?))} unless recurse.empty?
        s = Dom.join(a, tag)
        s = "<%s>%s</%s>" % Dom.format(tag, attr).insert(1, s) unless tag.nil?
        s.dom_escaped.mounted_set(*a.map(&:mounted), mounted)
end
jsonml(tag, attr = nil;) click to toggle source
# File lib/dom.rb, line 176
def jsonml tag, attr = nil; [*Dom.json_format(attr), *self] end