Class: Docbook::Services::Formatter
- Inherits:
-
Object
- Object
- Docbook::Services::Formatter
- Defined in:
- lib/docbook/services/formatter.rb
Overview
Formats/prettifies DocBook XML documents.
Instance Method Summary collapse
-
#format ⇒ String
Pretty-printed XML.
-
#initialize(input_path:, resolve_xinclude: false) ⇒ Formatter
constructor
A new instance of Formatter.
Constructor Details
#initialize(input_path:, resolve_xinclude: false) ⇒ Formatter
Returns a new instance of Formatter.
7 8 9 10 |
# File 'lib/docbook/services/formatter.rb', line 7 def initialize(input_path:, resolve_xinclude: false) @input_path = input_path @resolve_xinclude = resolve_xinclude end |
Instance Method Details
#format ⇒ String
Returns pretty-printed XML.
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/docbook/services/formatter.rb', line 13 def format xml_string = File.read(@input_path) if @resolve_xinclude xml_string = Docbook::XIncludeResolver.resolve_string(xml_string, base_path: @input_path).to_xml end parsed = Docbook::Document.from_xml(xml_string) parsed.to_xml(pretty: true, declaration: true, encoding: "utf-8") end |