Class: HTree::DocType
- Inherits:
-
Object
- Object
- HTree::DocType
- 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
Constant Summary
Constants included from HTree
DefaultContext, ElementContent, ElementExclusions, ElementInclusions, EmptyBindingObject, HTMLContext, NamedCharacters, NamedCharactersPattern, OmittedAttrName
Instance Attribute Summary collapse
-
#public_identifier ⇒ Object
readonly
Returns the value of attribute public_identifier.
-
#root_element_name ⇒ Object
readonly
Returns the value of attribute root_element_name.
-
#system_identifier ⇒ Object
readonly
Returns the value of attribute system_identifier.
Class Method Summary collapse
Instance Method Summary collapse
- #eliminate_raw_string ⇒ Object
-
#generate_content ⇒ Object
:nodoc:.
-
#initialize(root_element_name, public_identifier = nil, system_identifier = nil) ⇒ DocType
constructor
A new instance of DocType.
- #make_exact_equal_object ⇒ Object
- #make_usual_equal_object ⇒ Object
- #node_test_string ⇒ Object
- #output(out, context) ⇒ Object
- #to_rexml_internal(parent, context) ⇒ Object
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, parse_as, parse_pairs, parse_xml, scan, #usual_equal_object, with_frozen_string_hash
Constructor Details
#initialize(root_element_name, public_identifier = nil, system_identifier = nil) ⇒ DocType
Returns a new instance of DocType.
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/htree/leaf.rb', line 25 def initialize(root_element_name, public_identifier=nil, system_identifier=nil) init_raw_string if public_identifier && /\A[ \x0d\x0aa-zA-Z0-9\-'()+,.\/:=?;!*\#@$_%]*\z/ !~ public_identifier raise HTree::Error, "invalid public identifier in document type declaration: #{public_identifier.inspect}" end if system_identifier && /"/ =~ system_identifier && /'/ =~ system_identifier raise HTree::Error, "invalid system identifier in document type declaration: #{system_identifier.inspect}" end @root_element_name = root_element_name @public_identifier = public_identifier @system_identifier = system_identifier end |
Instance Attribute Details
#public_identifier ⇒ Object (readonly)
Returns the value of attribute public_identifier.
38 39 40 |
# File 'lib/htree/leaf.rb', line 38 def public_identifier @public_identifier end |
#root_element_name ⇒ Object (readonly)
Returns the value of attribute root_element_name.
38 39 40 |
# File 'lib/htree/leaf.rb', line 38 def root_element_name @root_element_name end |
#system_identifier ⇒ Object (readonly)
Returns the value of attribute system_identifier.
38 39 40 |
# File 'lib/htree/leaf.rb', line 38 def system_identifier @system_identifier end |
Class Method Details
.parse(raw_string, is_xml, is_html) ⇒ Object
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 |
# File 'lib/htree/parse.rb', line 368 def DocType.parse(raw_string, is_xml, is_html) unless /\A#{Pat::DocType_C}\z/o =~ raw_string raise HTree::Error, "cannot recognize as XML declaration: #{raw_string.inspect}" end root_element_name = $1 public_identifier = $2 || $3 system_identifier = $4 || $5 root_element_name = root_element_name.downcase if !is_xml && is_html result = DocType.new(root_element_name, public_identifier, system_identifier) result.raw_string = raw_string result end |
Instance Method Details
#eliminate_raw_string ⇒ Object
110 111 112 |
# File 'lib/htree/raw_string.rb', line 110 def eliminate_raw_string DocType.new(@root_element_name, @public_identifier, @system_identifier) end |
#generate_content ⇒ Object
:nodoc:
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/htree/output.rb', line 177 def generate_content # :nodoc: result = '' if @public_identifier result << "PUBLIC \"#{@public_identifier}\"" else result << "SYSTEM" end # Although a system identifier is not omissible in XML, # we cannot output it if it is not given. if @system_identifier if /"/ !~ @system_identifier result << " \"#{@system_identifier}\"" else result << " '#{@system_identifier}'" end end result end |
#make_exact_equal_object ⇒ Object
175 176 177 |
# File 'lib/htree/equality.rb', line 175 def make_exact_equal_object [@raw_string, @root_element_name, @system_identifier, @public_identifier] end |
#make_usual_equal_object ⇒ Object
179 180 181 |
# File 'lib/htree/equality.rb', line 179 def make_usual_equal_object [@root_element_name, @system_identifier, @public_identifier] end |
#node_test_string ⇒ Object
95 |
# File 'lib/htree/loc.rb', line 95 def node_test_string() 'doctype()' end |
#output(out, context) ⇒ Object
173 174 175 |
# File 'lib/htree/output.rb', line 173 def output(out, context) out.output_string "<!DOCTYPE #{@root_element_name} #{generate_content}>" end |
#to_rexml_internal(parent, context) ⇒ Object
105 106 107 |
# File 'lib/htree/rexml.rb', line 105 def to_rexml_internal(parent, context) REXML::DocType.new([self.root_element_name, self.generate_content], parent) end |