Class: Docgenerator::Creole::Creole_document

Inherits:
Object
  • Object
show all
Defined in:
lib/docgenerator/creole/document.rb

Overview

Build a document. This is just a little combination of the classes Document and Creole.

For the future: This class could allow features t build one TeX-file and multiple HTML (corresponding to pages).

HTML-pagebreak could be forced with ======== or something similar.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(settings = {}) ⇒ Creole_document

Define a creole document. The settings are forwarded to Document#new()

Some settings are used only directly in Creole_document.

  • :with_toc: Add a table of contents at the beginning of the document.

  • :content: Wiki-text. Same as Creole_document#<<

  • :logname: Name for Creole#log



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/docgenerator/creole/document.rb', line 33

def initialize( settings = {} )
  @with_toc  = settings[:with_toc ]
  settings.delete(:with_toc)  #Avoid error message in Document.new
  settings[:logname] ||= 'CreoleDoc'  #Just a name for easier debugging/logging
  
  @creole = Creole.new( 
      #Get content if available and delete setting to avoid error message in Document.new
      :logname      => settings.delete(:logname), #for logger
      :content  => settings.delete(:content),
      :ignore     => settings.delete(:ignore),
      :targetdir => settings.delete(:targetdir)
  )
  #fixme/ideen parameter
  #preamble -> vor wiki-texten
  #post -> nach wiki-texten

  @doc = Document.new(settings)
  
  @doc.runtex = settings[:runtex] if settings[:runtex]
  
  @log  = @doc.log
  
  @doc.body << creole
  
end

Instance Attribute Details

#creoleObject (readonly)

The related creole-object



61
62
63
# File 'lib/docgenerator/creole/document.rb', line 61

def creole
  @creole
end

#docObject (readonly)

The related document



59
60
61
# File 'lib/docgenerator/creole/document.rb', line 59

def doc
  @doc
end

Instance Method Details

#<<(content) ⇒ Object

Add content to the wiki.



63
64
65
# File 'lib/docgenerator/creole/document.rb', line 63

def << (content)
  @creole << content
end

#runtex=(option) ⇒ Object

Use runtex if available.



86
87
88
# File 'lib/docgenerator/creole/document.rb', line 86

def runtex=(option)
  @doc.runtex = option
end

#save(filename, options = {}) ⇒ Object

Save the creole document.

If requested, the tableofcontents is added. The first Creole_document#save decides, which variant is added (html/tex)



72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/docgenerator/creole/document.rb', line 72

def save( filename, options = {} )
  if @with_toc
      @doc.body.insertbefore(creole, element(:htmlonly,{}, creole.toc(:level => @with_toc )))
      @doc.body.insertbefore(creole, element(:latexonly,{},element(:tableofcontents).cr))
      case @with_toc
        when Numeric
          @doc.head << element(:latexonly,{},"\\setcounter{tocdepth}{#{@with_toc}}\n")
        end 
      @with_toc  = false #Add it only once
  end #@with_toc
  
  @doc.save(filename, options )
end