Class: DocBookPrinter
Instance Attribute Summary collapse
-
#output_dir ⇒ Object
Returns the value of attribute output_dir.
Instance Method Summary collapse
- #do_finish ⇒ Object
- #do_prepare ⇒ Object
-
#initialize ⇒ DocBookPrinter
constructor
A new instance of DocBookPrinter.
- #print_body(body) ⇒ Object
- #print_contents(contents) ⇒ Object
- #print_host(host) ⇒ Object
- #print_parameter(parameter) ⇒ Object
- #print_request(request) ⇒ Object
- #print_result(result) ⇒ Object
- #print_section(section) ⇒ Object
- #print_text(text) ⇒ Object
- #print_version(version) ⇒ Object
- #print_xml_links(xmlname, schema) ⇒ Object
- #print_xmlbody(body) ⇒ Object
- #print_xmlresult(result) ⇒ Object
- #replace_html_tags(text) ⇒ Object
Methods inherited from Printer
#do_print, #method_missing, #print, #print_document
Constructor Details
#initialize ⇒ DocBookPrinter
Returns a new instance of DocBookPrinter.
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/doc_book_printer.rb', line 9 def initialize super() @output_dir = "docbook" @xml_examples = Hash.new @xml_schemas = Hash.new @section = 0 @html_tag_mapping = { "tt" => nil, "em" => "emphasis", "b" => "emphasis", } end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Printer
Instance Attribute Details
#output_dir ⇒ Object
Returns the value of attribute output_dir.
7 8 9 |
# File 'lib/doc_book_printer.rb', line 7 def output_dir @output_dir end |
Instance Method Details
#do_finish ⇒ Object
42 43 44 45 46 |
# File 'lib/doc_book_printer.rb', line 42 def do_finish @xml << "</appendix>\n" puts "Written #{@index.path}" @index.close end |
#do_prepare ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/doc_book_printer.rb', line 23 def do_prepare unless File.exists? @output_dir Dir.mkdir @output_dir end @index = File.new @output_dir + "/rest_api_appendix.xml", "w" @xml = Builder::XmlMarkup.new :target => @index, :indent => 2 @xml.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8" @xml.declare! :DOCTYPE, :appendix, :PUBLIC, "-//Novell//DTD NovDoc XML V1.0//EN", "novdocx.dtd" do |x| x.declare! :ENTITY, :%, :'NOVDOC.DEACTIVATE.IDREF', "IGNORE" x.declare! :ENTITY, :%, :entities, :SYSTEM, "entity-decl.ent" x << " %entities;\n" end @xml.comment! "This file was generated by restility at #{Time.now}" @xml << "<appendix xml:base=\"rest_api_appendix.xml\" id=\"app.rest_api_doc\">\n" end |
#print_body(body) ⇒ Object
122 123 124 |
# File 'lib/doc_book_printer.rb', line 122 def print_body body @xml.para "Body: #{body.name}" end |
#print_contents(contents) ⇒ Object
149 150 151 152 |
# File 'lib/doc_book_printer.rb', line 149 def print_contents contents # empty, the content is generated by docbook itself @xml.para end |
#print_host(host) ⇒ Object
114 115 116 |
# File 'lib/doc_book_printer.rb', line 114 def print_host host @xml.para "Host: " + host.name end |
#print_parameter(parameter) ⇒ Object
111 112 |
# File 'lib/doc_book_printer.rb', line 111 def print_parameter parameter end |
#print_request(request) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/doc_book_printer.rb', line 68 def print_request request @xml.variablelist do @xml.varlistentry do @xml.term do @xml.literal request.to_s end @xml.listitem do request.parameters.each do |p| @xml.para do @xml.emphasis p.name @xml << " (optional)" if p.optional @xml << " - #{p.description}" if p.description && !p.description.empty? end end request.print_children self end end end end |
#print_result(result) ⇒ Object
118 119 120 |
# File 'lib/doc_book_printer.rb', line 118 def print_result result @xml.para "Result: #{result.name}" end |
#print_section(section) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/doc_book_printer.rb', line 48 def print_section section if !section.root? level = section.level - 1 if level.zero? @xml.title section @xml.para section.print_children self else @xml.tag! "sect#{level}", "id" => "app.rest_api_doc.sect#{level}.#{@section}" do @section += 1 @xml.title section section.print_children self end end else section.print_children self end end |
#print_text(text) ⇒ Object
102 103 104 105 106 107 108 109 |
# File 'lib/doc_book_printer.rb', line 102 def print_text text @xml.para do |p| text.text.each do |t| t p << t << "\n" end end end |
#print_version(version) ⇒ Object
154 155 156 |
# File 'lib/doc_book_printer.rb', line 154 def print_version version @xml.para "API Version: #{version}" end |
#print_xml_links(xmlname, schema) ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/doc_book_printer.rb', line 134 def print_xml_links xmlname, schema example = xmlname + ".xml" if !schema || schema.empty? schema = xmlname + ".xsd" end if XmlFile.exist? example @xml.screen File.read(XmlFile.find_file example) end if XmlFile.exist? schema @xml.screen File.read(XmlFile.find_file schema) end end |
#print_xmlbody(body) ⇒ Object
130 131 132 |
# File 'lib/doc_book_printer.rb', line 130 def print_xmlbody body print_xml_links body.name, body.schema end |
#print_xmlresult(result) ⇒ Object
126 127 128 |
# File 'lib/doc_book_printer.rb', line 126 def print_xmlresult result print_xml_links result.name, result.schema end |
#replace_html_tags(text) ⇒ Object
91 92 93 94 95 96 97 98 99 100 |
# File 'lib/doc_book_printer.rb', line 91 def text @html_tag_mapping.each do |html, docbook| if docbook.nil? text.gsub! "<#{html}>", "" else text.gsub! "<#{html}>", "<#{docbook}>" text.gsub! "</#{html}>", "</#{docbook}>" end end end |