Class: DTC::Utils::Text::HTML::Writer
Instance Method Summary
collapse
Methods inherited from LineWriter
#begin_capture, #current_indent, #end_capture, #lines, #pop_indent, #push, #push_indent, #push_raw, #to_s
Instance Method Details
#add(sym, *args) ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/dtc/utils/text/html.rb', line 27
def add sym, *args
if self.respond_to?(sym)
self.__send__(sym, *args)
else
attrs = args.last.is_a?(Hash) ? args.pop : {}
if attrs && attrs.delete(:no_indent) {
! NOINDENT_TAGS.index(sym.to_s.downcase).nil?
}
push(DTC::Utils::Text::HTML::tag(sym, :open, attrs))
unindented *args
push(DTC::Utils::Text::HTML::tag(sym, :close, attrs))
else
push(DTC::Utils::Text::HTML::tag(sym, args, attrs))
end
end
end
|
#enter(sym, *args) ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/dtc/utils/text/html.rb', line 8
def enter sym, *args
attrs = args.last.is_a?(Hash) ? args.pop : {}
no_indent = attrs && attrs.delete(:no_indent) {
! NOINDENT_TAGS.index(sym.to_s.downcase).nil?
}
push DTC::Utils::Text::HTML::tag(sym, :open, attrs)
(@stack ||= []) << sym.to_s.split(".").first
push_indent(" " + (current_indent || []).join(""))
if no_indent
unindented *args
else
text *args
end
true
end
|
#leave ⇒ Object
23
24
25
26
|
# File 'lib/dtc/utils/text/html.rb', line 23
def leave
pop_indent
push(DTC::Utils::Text::HTML::tag(@stack.pop.to_sym, :close))
end
|
#text(*str) ⇒ Object
43
44
45
|
# File 'lib/dtc/utils/text/html.rb', line 43
def text *str
push(*str.flatten.map { |s| CGI::escapeHTML(s) })
end
|
#unindented(*str) ⇒ Object
46
47
48
|
# File 'lib/dtc/utils/text/html.rb', line 46
def unindented *str
push_indent("") { text *str }
end
|