Class: HTree::Comment

Inherits:
Object
  • Object
show all
Includes:
Trav, Leaf
Defined in:
lib/htree/loc.rb,
lib/htree/leaf.rb,
lib/htree/rexml.rb,
lib/htree/output.rb,
lib/htree/modules.rb,
lib/htree/modules.rb,
lib/htree/modules.rb,
lib/htree/equality.rb,
lib/htree/raw_string.rb

Defined Under Namespace

Modules: Trav Classes: Loc

Constant Summary

Constants included from HTree

DefaultContext, ElementContent, ElementExclusions, ElementInclusions, EmptyBindingObject, HTMLContext, NamedCharacters, NamedCharactersPattern, OmittedAttrName

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Leaf::Trav

#traverse_all_element, #traverse_some_element, #traverse_text_internal

Methods included from Traverse

#bogusetag?, #comment?, #doc?, #doctype?, #elem?, #get_subnode, #procins?, #text?, #traverse_text, #xmldecl?

Methods included from Leaf

#extract_text, #init_raw_string, #pretty_print, #raw_string=, #raw_string_internal

Methods included from Node

#display_html, #display_xml, #extract_text, #generate_xml_output_code, #make_loc, #raw_string, #subst, #subst_internal, #to_node, #to_rexml

Methods included from HTree

#==, build_node, #check_equality, compile_template, #exact_equal?, #exact_equal_object, expand_template, fix_element, fix_structure_list, frozen_string, #hash, #make_usual_equal_object, parse_as, parse_pairs, parse_xml, scan, with_frozen_string_hash

Constructor Details

#initialize(content) ⇒ Comment

:notnew:



76
77
78
79
80
81
82
# File 'lib/htree/leaf.rb', line 76

def initialize(content) # :notnew:
  init_raw_string
  if /--/ =~ content || /-\z/ =~ content
    raise HTree::Error, "invalid comment content: #{content.inspect}"
  end
  @content = content
end

Instance Attribute Details

#contentObject (readonly) Also known as: usual_equal_object

Returns the value of attribute content.



83
84
85
# File 'lib/htree/leaf.rb', line 83

def content
  @content
end

Class Method Details

.new(content) ⇒ Object

:startdoc:



71
72
73
74
# File 'lib/htree/leaf.rb', line 71

def Comment.new(content)
  content = content.gsub(/-(-+)/) { '-' + ' -' * $1.length }.sub(/-\z/, '- ')
  new! content
end

.new!Object



67
# File 'lib/htree/leaf.rb', line 67

alias new! new

.parse(raw_string) ⇒ Object



397
398
399
400
401
402
403
404
405
406
407
# File 'lib/htree/parse.rb', line 397

def Comment.parse(raw_string)
  unless /\A#{Pat::Comment_C}\z/o =~ raw_string
    raise HTree::Error, "cannot recognize as comment: #{raw_string.inspect}"
  end

  content = $1

  result = Comment.new(content)
  result.raw_string = raw_string
  result
end

Instance Method Details

#eliminate_raw_stringObject



122
123
124
# File 'lib/htree/raw_string.rb', line 122

def eliminate_raw_string
  Comment.new(@content)
end

#make_exact_equal_objectObject



195
196
197
# File 'lib/htree/equality.rb', line 195

def make_exact_equal_object
  [@raw_string, @content]
end

#node_test_stringObject



97
# File 'lib/htree/loc.rb', line 97

def node_test_string() 'comment()' end

#output(out, context) ⇒ Object



206
207
208
# File 'lib/htree/output.rb', line 206

def output(out, context)
  out.output_string "<!--#{@content}-->"
end

#to_rexml_internal(parent, context) ⇒ Object



119
120
121
# File 'lib/htree/rexml.rb', line 119

def to_rexml_internal(parent, context)
  REXML::Comment.new(self.content, parent)
end