153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
# 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
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
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
|