# This is a mod of the dbtoepub program that doesn't work. Using
# epubber instead is smarter.
module Docbook
  module Adapters
    module Epub

      module Dbtoepub
    
        # initialize the object and set the extensions and output type. Defaults to PDF
        def initialize(args = {})
          super
          @css_stylesheet = "xsl/epub.css"
          
        end
        
        def render
          if RUBY_PLATFORM =~ /(win|w)32$/
            puts "ePub conversion doesn't work on Windows. We're working on a fix."
          else
            super
          end
        end
    
        def xml_cmd
           cmd = "ruby #{self.root}/xsl/epub/bin/dbtoepub -c #{@css_stylesheet} -s #{@xsl_stylesheet} #{self.file}.xml"
        end
    
        def before_render
          xsl_path = @windows ? self.root : self.root.lchop
      
          xml = %Q{<?xml version='1.0'?>

          <!-- DO NOT CHANGE THIS FILE. IT IS AUTOGENERATED BY THE SHORT-ATTENTION-SPAN-DOCBOOK CHAIN -->

          <xsl:stylesheet 
             xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
             xmlns:fo="http://www.w3.org/1999/XSL/Format"
             xmlns:xslthl="http://xslthl.sf.net"
             xmlns:d="http://docbook.org/ns/docbook"
          >
            <!-- Import the original EPUB stylesheets -->
            <xsl:import href="file:///#{xsl_path}/xsl/epub/docbook.xsl"/>
            <xsl:import href="file:///#{xsl_path}/xsl/xhtml-1_1/highlight.xsl"/>
      
            <!-- FOP -->
   
          }
      
          xml << %Q{
            <xsl:param name="show.comments" select="1"></xsl:param>
            <xsl:param name="draft.watermark.image">http://docbook.sourceforge.net/release/images/draft.png</xsl:param>
            <xsl:param name="draft.mode">yes</xsl:param>
          } if @draft
      
          xml << "</xsl:stylesheet>"
      
          File.open("xsl/epub_base.xsl", "w") do |f|
            f << xml
          end
        end
    

      end
    end
  end
end