Class: Decorator
- Inherits:
-
Object
- Object
- Decorator
- Defined in:
- lib/decorator.rb
Instance Method Summary collapse
- #docbook ⇒ Object
-
#fop ⇒ Object
TODO better regexp.
-
#initialize ⇒ Decorator
constructor
A new instance of Decorator.
Constructor Details
#initialize ⇒ Decorator
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
#docbook ⇒ Object
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 |
#fop ⇒ Object
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 |