Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/dom.rb

Instance Method Summary collapse

Instance Method Details

#dom(*tags, mounted: nil, **attr) ⇒ Object



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
		#!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) ⇒ Object



176
# File 'lib/dom.rb', line 176

def jsonml tag, attr = nil; [*Dom.json_format(attr), *self] end