File: display.rb

package info (click to toggle)
ruby-htree 0.8%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 520 kB
  • sloc: ruby: 5,928; makefile: 23
file content (46 lines) | stat: -rw-r--r-- 1,543 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
require 'htree/output'

module HTree
  module Node
    # HTree::Node#display_xml prints the node as XML.
    #
    # The first optional argument, <i>out</i>,
    # specifies output target.
    # It should respond to <tt><<</tt>.
    # If it is not specified, $stdout is used.
    #
    # The second optional argument, <i>encoding</i>,
    # specifies output MIME charset (character encoding).
    # If it is not specified, HTree::Encoder.internal_charset is used.
    #
    # HTree::Node#display_xml returns <i>out</i>.
    def display_xml(out=$stdout, encoding=HTree::Encoder.internal_charset)
      encoder = HTree::Encoder.new(encoding)
      self.output(encoder, HTree::DefaultContext)
      # don't call finish_with_xmldecl because self already has a xml decl.
      out << encoder.finish
      out
    end

    # HTree::Node#display_html prints the node as HTML.
    #
    # The first optional argument, <i>out</i>,
    # specifies output target.
    # It should respond to <tt><<</tt>.
    # If it is not specified, $stdout is used.
    #
    # The second optional argument, <i>encoding</i>,
    # specifies output MIME charset (character encoding).
    # If it is not specified, HTree::Encoder.internal_charset is used.
    #
    # HTree::Node#display_html returns <i>out</i>.
    def display_html(out=$stdout, encoding=HTree::Encoder.internal_charset)
      encoder = HTree::Encoder.new(encoding)
      encoder.html_output = true
      self.output(encoder, HTree::HTMLContext)
      out << encoder.finish
      out
    end

  end
end