Class: Comment

Inherits:
SGMLObject show all
Defined in:
lib/rwd/xml.rb,
lib/rwd/sgml.rb

Instance Attribute Summary

Attributes inherited from TreeObject

#children, #closed, #level, #parent, #subtype, #text, #upordown, #visible

Instance Method Summary collapse

Methods inherited from SGMLObject

#to_h, #to_s, #to_x

Methods inherited from TreeObject

#inspect, #previous

Methods included from ParseTree

#parsetree

Methods included from TextArray

#textarray

Constructor Details

#initialize(text) ⇒ Comment

Returns a new instance of Comment.


39
40
41
42
# File 'lib/rwd/sgml.rb', line 39

def initialize(text)
  super()
  @text = text
end

Instance Method Details

#prechildren_to_sgml(res) ⇒ Object


44
45
46
# File 'lib/rwd/sgml.rb', line 44

def prechildren_to_sgml(res)
  res << "#{@text}"
end

#prechildren_to_x(res, closetags) ⇒ Object


20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rwd/xml.rb', line 20

def prechildren_to_x(res, closetags)
  res << "\n"	if not previous([], [Text]).kind_of?(Comment)
  lines	= @text.gsub(/(<!--|-->)/, "").lf.split(/\n/)
  if lines.length == 1
    res << "  "*(@level-1) + "<!-- " + lines[0].strip + " -->" + "\n"
  else
    res << "  "*(@level-1) + "<!--" + "\n"
    res << lines.collect{|s| "  "*(@level-1) + s.strip}.delete_if{|s| s.compress.empty?}.join("\n")
    res << "\n"
    res << "  "*(@level-1) + "-->" + "\n"
    res << "\n"
  end
end