File: transformer/document-into-docbook/overview.rb

Overview
Module Structure
Code

Overview

Module Structure

  module: <Toplevel Module>
  module: TmDoc#14
  module: Transformer
  module: DocumentIntoDocBook#16
  module: Overview#18
has properties
function: transform / 4 #22
function: transform_source_structure / 4 #126

Code

   1  # $Id: overview.rb,v 1.9 2012/04/17 02:19:08 machan Exp $
   2 
   3  require 'tmdoc/tmstd'
   4  require 'tmdoc/tmstd/docbook'
   5  require 'tmdoc/constant'
   6  require 'tmdoc/model/document'
   7  require 'tmdoc/model/docbook'
   8  require 'tmdoc/transformer/document-into-docbook/id'
   9  require 'tmdoc/transformer/document-into-docbook/link'
  10  require 'tmdoc/transformer/document-into-docbook/node'
  11  require 'tmdoc/transformer/localizable-string'
  12 
  13 
  14  module TmDoc
  15 
  16  module Transformer::DocumentIntoDocBook
  17 
  18  module Overview
  19 
  20  module_function
  21 
  22      def transform(overview, ov_title, ov_id, show_code)
  23          ASSERT.kind_of overview,    MDO::Overview
  24          ASSERT.kind_of ov_title,    String
  25          ASSERT.kind_of ov_id,       String
  26          ASSERT.boolean show_code
  27 
  28          md_module_structure = overview.a_module_structure
  29          md_class_hierarchy  = overview.a_class_hierarchy
  30          md_source_structure = overview.a_source_structure
  31 
  32          transforms = [
  33              if md_module_structure
  34                  [
  35                      lambda { |title, id|
  36                          MBD::Leaf.new(
  37                              id,
  38                              Node.transform_logical_structure(
  39                                  md_module_structure,
  40                                  title,
  41                                  id,
  42                                  Id::DIV_NAME_OF_M_STRUCTURE,
  43                                  :show_type_label => true
  44                              )
  45                          )
  46                      },
  47 
  48                      TLS::DIV_M_STRUCTURE,
  49 
  50                      Id::DIV_OV_M_STRUCTURE
  51                  ]
  52              else
  53                  nil
  54              end,
  55 
  56              if md_class_hierarchy
  57                  [
  58                      lambda { |title, id|
  59                          MBD::Leaf.new(
  60                              id,
  61                              Node.transform_logical_structure(
  62                                  md_class_hierarchy,
  63                                  title,
  64                                  id,
  65                                  Id::DIV_NAME_OF_C_HIERARCHY,
  66                                  :show_above_link => true
  67                              )
  68                          )
  69                      },
  70 
  71                      TLS::DIV_C_HIERARCHY,
  72 
  73                      Id::DIV_OV_C_HIERARCHY
  74                  ]
  75              else
  76                  nil
  77              end,
  78 
  79              if show_code && md_source_structure
  80                  [
  81                      lambda { |title, id|
  82                          transform_source_structure(
  83                              md_source_structure, title, id, show_code
  84                          )
  85                      },
  86 
  87                      TLS::DIV_S_STRUCTURE,
  88 
  89                      Id::DIV_OV_S_STRUCTURE
  90                  ]
  91              else
  92                  nil
  93              end
  94          ].compact
  95          return nil if transforms.empty?
  96 
  97          mb_array_of_document = transforms.map { |transform|
  98              ASSERT.tuple_of transform, [Proc, String, String]
  99              fun, title, id = transform
 100 
 101              LOG::Progress.log "\t%s", title
 102 
 103              fun.call(title, id)
 104          }.compact
 105          return nil if mb_array_of_document.empty?
 106 
 107          mb_documents = MBD::SeqOfDocument.new mb_array_of_document
 108 
 109          MBD::Node.new(
 110              ov_id, DBOOK.chapter(:id => ov_id) {
 111                  [
 112                      DBOOK.chapter_info {
 113                          [ DBOOK.title(ov_title) ]
 114                      }
 115                  ] + mb_documents.map { |mb_document|
 116                      ASSERT.kind_of mb_document, MBD::Leaf
 117 
 118                      DBOOK.include(mb_document.name, OUTPUT_FILE_SUFFIX)
 119                  }
 120              },
 121              mb_documents
 122          )
 123      end
 124 
 125 
 126      def transform_source_structure(
 127          md_source_structure, title, id, show_code
 128      )
 129          ASSERT.kind_of md_source_structure, MDN::SourceStructure
 130          ASSERT.kind_of title,               String
 131          ASSERT.kind_of id,                  String
 132          ASSERT.boolean show_code
 133 
 134          md_files = md_source_structure.files
 135          return nil if md_files.empty?
 136 
 137          contents = [
 138              DBOOK.itemized_list {
 139                  md_files.map { |md_file|
 140                      ASSERT.kind_of md_file, MDN::File
 141 
 142                      DBOOK.list_item {
 143                          [
 144                              DBOOK.text(TLS::FILE + ':'),
 145 
 146                              Link.transform_file(
 147                                  md_file.a_link_to_file, show_code
 148                              )
 149                          ]
 150                      }
 151                  }
 152              }
 153          ]
 154 
 155          MBD::Leaf.new(
 156              id,
 157 
 158              DBOOK.section(:id => id) {
 159                  [
 160                      DBOOK.section_info {
 161                          [ DBOOK.title(title) ]
 162                      }
 163                  ] + contents
 164              }
 165          )
 166      end
 167  end
 168 
 169  end # TmDoc::Transformer::DocumentIntoDocBook
 170 
 171  end # TmDoc