Class: Decorator

Inherits:
Object
  • Object
show all
Defined in:
lib/decorator.rb

Instance Method Summary collapse

Constructor Details

#initializeDecorator

Returns a new instance of Decorator.



4
5
6
7
8
# File 'lib/decorator.rb', line 4

def initialize
  @dir = Dir.pwd
  @docbook = "#{@dir}/output/book.xml"
  @fop = "#{@dir}/output/book.fo"
end

Instance Method Details

#docbookObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/decorator.rb', line 10

def docbook
  xml = File.read(@docbook)

  xml.gsub!(
    /<programlisting(.+?)language="(\w+)"(.*?)>(.+?)<\/programlisting>/m
  ) { |m|
      %Q|<programlisting#{$1}language="#{$2}"#{$3}>| +
        %Q|//:::#{$2}:::\n#{$4}| +
      %Q|</programlisting>|
    }

  # File.write("#{@docbook}.tmp", xml)
  File.write(@docbook, xml)
end

#fopObject

TODO better regexp. Mono font?



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/decorator.rb', line 26

def fop
  xml = File.read(@fop)

  xml.gsub!(
    /<fo:block(.+?)>\/\/:::(\w+):::\n(.+?)(<\/fo:block>)/m
  ) { |m|

      language = $2
      code = $3

      %Q|<fo:block#{$1}>| +
        highlight_fo(code, language) +
      %Q|#{$4}|
    }

  File.write("#{@fop}", xml)
end