Skip to content

Commit

Permalink
better links, better xhtml
Browse files Browse the repository at this point in the history
  • Loading branch information
schacon committed Jan 28, 2011
1 parent 935caac commit 38fcb16
Show file tree
Hide file tree
Showing 4 changed files with 268 additions and 5 deletions.
87 changes: 87 additions & 0 deletions docbook-xsl/common.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<!--
Inlcuded in xhtml.xsl, xhtml.chunked.xsl, htmlhelp.xsl.
Contains common XSL stylesheets parameters.
Output documents styled by docbook.css.
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:param name="html.stylesheet" select="'docbook-xsl.css'"/>

<xsl:param name="htmlhelp.chm" select="'htmlhelp.chm'"/>
<xsl:param name="htmlhelp.hhc.section.depth" select="5"/>

<xsl:param name="section.autolabel">
<xsl:choose>
<xsl:when test="/processing-instruction('asciidoc-numbered')">1</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:param>

<xsl:param name="suppress.navigation" select="0"/>
<xsl:param name="navig.graphics.extension" select="'.png'"/>
<xsl:param name="navig.graphics" select="0"/>
<xsl:param name="navig.graphics.path">images/icons/</xsl:param>
<xsl:param name="navig.showtitles">0</xsl:param>

<xsl:param name="shade.verbatim" select="0"/>
<xsl:attribute-set name="shade.verbatim.style">
<xsl:attribute name="border">0</xsl:attribute>
<xsl:attribute name="background-color">#E0E0E0</xsl:attribute>
</xsl:attribute-set>

<xsl:param name="admon.graphics" select="1"/>
<xsl:param name="admon.graphics.path">images/icons/</xsl:param>
<xsl:param name="admon.graphics.extension" select="'.png'"/>
<xsl:param name="admon.style">
<xsl:text>margin-left: 0; margin-right: 10%;</xsl:text>
</xsl:param>
<xsl:param name="admon.textlabel" select="1"/>

<xsl:param name="callout.defaultcolumn" select="'60'"/>
<xsl:param name="callout.graphics.extension" select="'.png'"/>
<xsl:param name="callout.graphics" select="'1'"/>
<xsl:param name="callout.graphics.number.limit" select="'10'"/>
<xsl:param name="callout.graphics.path" select="'images/icons/callouts/'"/>
<xsl:param name="callout.list.table" select="'1'"/>

<xsl:param name="chunk.first.sections" select="0"/>
<xsl:param name="chunk.quietly" select="0"/>
<xsl:param name="chunk.section.depth" select="1"/>
<xsl:param name="chunk.toc" select="''"/>
<xsl:param name="chunk.tocs.and.lots" select="0"/>

<xsl:param name="html.cellpadding" select="'4px'"/>
<xsl:param name="html.cellspacing" select="''"/>

<xsl:param name="table.borders.with.css" select="1"/>
<xsl:param name="table.cell.border.color" select="'#527bbd'"/>

<xsl:param name="table.cell.border.style" select="'solid'"/>
<xsl:param name="table.cell.border.thickness" select="'1px'"/>
<xsl:param name="table.footnote.number.format" select="'a'"/>
<xsl:param name="table.footnote.number.symbols" select="''"/>
<xsl:param name="table.frame.border.color" select="'#527bbd'"/>
<xsl:param name="table.frame.border.style" select="'solid'"/>
<xsl:param name="table.frame.border.thickness" select="'3px'"/>
<xsl:param name="tablecolumns.extension" select="'1'"/>

<xsl:param name="highlight.source" select="1"/>

<xsl:param name="section.label.includes.component.label" select="1"/>

<!--
Table of contents inserted by <?asciidoc-toc?> processing instruction.
-->
<xsl:param name="generate.toc">
<xsl:choose>
<xsl:when test="/processing-instruction('asciidoc-toc')">
article toc,title
book toc,title,figure,table,example,equation
</xsl:when>
<xsl:otherwise>
article nop
book nop
</xsl:otherwise>
</xsl:choose>
</xsl:param>

</xsl:stylesheet>
152 changes: 152 additions & 0 deletions docbook-xsl/fo.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
<!--
Generates single FO document from DocBook XML source using DocBook XSL
stylesheets.
See xsl-stylesheets/fo/param.xsl for all parameters.
NOTE: The URL reference to the current DocBook XSL stylesheets is
rewritten to point to the copy on the local disk drive by the XML catalog
rewrite directives so it doesn't need to go out to the Internet for the
stylesheets. This means you don't need to edit the <xsl:import> elements on
a machine by machine basis.
-->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:import href="http://docbook.sourceforge.net/release/xsl/current/fo/docbook.xsl"/>
<xsl:import href="common.xsl"/>

<xsl:param name="fop1.extensions" select="1" />
<xsl:param name="variablelist.as.blocks" select="1" />

<xsl:param name="paper.type" select="'A4'"/>
<!--
<xsl:param name="paper.type" select="'USletter'"/>
-->
<xsl:param name="hyphenate">false</xsl:param>
<!-- justify, left or right -->
<xsl:param name="alignment">left</xsl:param>

<xsl:param name="body.font.family" select="'serif'"/>
<xsl:param name="body.font.master">12</xsl:param>
<xsl:param name="body.font.size">
<xsl:value-of select="$body.font.master"/><xsl:text>pt</xsl:text>
</xsl:param>

<xsl:param name="body.margin.bottom" select="'0.5in'"/>
<xsl:param name="body.margin.top" select="'0.5in'"/>
<xsl:param name="bridgehead.in.toc" select="0"/>

<!-- overide setting in common.xsl -->
<xsl:param name="table.frame.border.thickness" select="'2px'"/>

<!-- Default fetches image from Internet (long timeouts) -->
<xsl:param name="draft.watermark.image" select="''"/>

<!-- Line break -->
<xsl:template match="processing-instruction('asciidoc-br')">
<fo:block/>
</xsl:template>

<!-- Horizontal ruler -->
<xsl:template match="processing-instruction('asciidoc-hr')">
<fo:block space-after="1em">
<fo:leader leader-pattern="rule" rule-thickness="0.5pt" rule-style="solid" leader-length.minimum="100%"/>
</fo:block>
</xsl:template>

<!-- Hard page break -->
<xsl:template match="processing-instruction('asciidoc-pagebreak')">
<fo:block break-after='page'/>
</xsl:template>

<!-- Sets title to body text indent -->
<xsl:param name="body.start.indent">
<xsl:choose>
<xsl:when test="$fop.extensions != 0">0pt</xsl:when>
<xsl:when test="$passivetex.extensions != 0">0pt</xsl:when>
<xsl:otherwise>1pc</xsl:otherwise>
</xsl:choose>
</xsl:param>
<xsl:param name="title.margin.left">
<xsl:choose>
<xsl:when test="$fop.extensions != 0">-1pc</xsl:when>
<xsl:when test="$passivetex.extensions != 0">0pt</xsl:when>
<xsl:otherwise>0pt</xsl:otherwise>
</xsl:choose>
</xsl:param>
<xsl:param name="page.margin.bottom" select="'0.25in'"/>
<xsl:param name="page.margin.inner">
<xsl:choose>
<xsl:when test="$double.sided != 0">0.75in</xsl:when>
<xsl:otherwise>0.75in</xsl:otherwise>
</xsl:choose>
</xsl:param>
<xsl:param name="page.margin.outer">
<xsl:choose>
<xsl:when test="$double.sided != 0">0.5in</xsl:when>
<xsl:otherwise>0.5in</xsl:otherwise>
</xsl:choose>
</xsl:param>

<xsl:param name="page.margin.top" select="'0.5in'"/>
<xsl:param name="page.orientation" select="'portrait'"/>
<xsl:param name="page.width">
<xsl:choose>
<xsl:when test="$page.orientation = 'portrait'">
<xsl:value-of select="$page.width.portrait"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$page.height.portrait"/>
</xsl:otherwise>
</xsl:choose>
</xsl:param>

<xsl:attribute-set name="monospace.properties">
<xsl:attribute name="font-size">10pt</xsl:attribute>
</xsl:attribute-set>

<xsl:attribute-set name="admonition.title.properties">
<xsl:attribute name="font-size">14pt</xsl:attribute>
<xsl:attribute name="font-weight">bold</xsl:attribute>
<xsl:attribute name="hyphenate">false</xsl:attribute>
<xsl:attribute name="keep-with-next.within-column">always</xsl:attribute>
</xsl:attribute-set>

<xsl:attribute-set name="sidebar.properties" use-attribute-sets="formal.object.properties">
<xsl:attribute name="border-style">solid</xsl:attribute>
<xsl:attribute name="border-width">1pt</xsl:attribute>
<xsl:attribute name="border-color">silver</xsl:attribute>
<xsl:attribute name="background-color">#ffffee</xsl:attribute>
<xsl:attribute name="padding-left">12pt</xsl:attribute>
<xsl:attribute name="padding-right">12pt</xsl:attribute>
<xsl:attribute name="padding-top">6pt</xsl:attribute>
<xsl:attribute name="padding-bottom">6pt</xsl:attribute>
<xsl:attribute name="margin-left">0pt</xsl:attribute>
<xsl:attribute name="margin-right">12pt</xsl:attribute>
<xsl:attribute name="margin-top">6pt</xsl:attribute>
<xsl:attribute name="margin-bottom">6pt</xsl:attribute>
</xsl:attribute-set>

<xsl:param name="callout.graphics" select="'1'"/>

<!-- Only shade programlisting and screen verbatim elements -->
<xsl:param name="shade.verbatim" select="1"/>
<xsl:attribute-set name="shade.verbatim.style">
<xsl:attribute name="background-color">
<xsl:choose>
<xsl:when test="self::programlisting|self::screen">#E0E0E0</xsl:when>
<xsl:otherwise>inherit</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</xsl:attribute-set>

<!--
Force XSL Stylesheets 1.72 default table breaks to be the same as the current
version (1.74) default which (for tables) is keep-together="auto".
-->
<xsl:attribute-set name="table.properties">
<xsl:attribute name="keep-together.within-column">auto</xsl:attribute>
</xsl:attribute-set>

</xsl:stylesheet>
24 changes: 21 additions & 3 deletions lib/git-scribe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,30 @@ def a2x_wss(type)
def do_pdf
puts "GENERATING PDF"
# TODO: syntax highlighting (fop?)
`#{a2x('pdf')} --dblatex-opts "-P latex.output.revhistory=0" #{BOOK_FILE}`
puts `asciidoc -b docbook #{BOOK_FILE}`
strparams = {'callout.graphics' => 0,
'navig.graphics' => 0,
'admon.textlabel' => 1,
'admon.graphics' => 0}
param = strparams.map { |k, v| "--stringparam #{k} #{v}" }.join(' ')
puts cmd = "xsltproc --nonet #{param} --output #{local('book.fo')} #{base('docbook-xsl/fo.xsl')} #{local('book.xml')}"
puts `#{cmd}`
cmd = "fop -fo #{local('book.fo')} -pdf #{local('book.pdf')}"
puts `#{cmd}`
#puts `#{a2x('pdf')} -v --fop #{BOOK_FILE}`
if $?.exitstatus == 0
'book.pdf'
end
end

def local(file)
File.expand_path(File.join(Dir.pwd, file))
end

def base(file)
File.expand_path(File.join(File.dirname(__FILE__), '..', '..', file))
end

def do_epub
puts "GENERATING EPUB"
# TODO: look for custom stylesheets
Expand All @@ -107,7 +125,7 @@ def do_html
puts "GENERATING HTML"
# TODO: look for custom stylesheets
#puts `#{a2x_wss('xhtml')} -v #{BOOK_FILE}`
styledir = File.expand_path(File.join(Dir.pwd, 'stylesheets'))
styledir = local('stylesheets')
puts cmd = "asciidoc -a stylesdir=#{styledir} -a theme=handbookish #{BOOK_FILE}"
`#{cmd}`
puts 'exit status', $?.exitstatus
Expand All @@ -118,7 +136,7 @@ def do_site
puts "GENERATING SITE"
# TODO: check if html was already done
puts `asciidoc -b docbook #{BOOK_FILE}`
xsldir = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'docbook-xsl', 'xhtml'))
xsldir = base('docbook-xsl/xhtml')
`xsltproc --stringparam html.stylesheet stylesheets/handbookish.css --nonet #{xsldir}/chunk.xsl book.xml`

source = File.read('index.html')
Expand Down
10 changes: 8 additions & 2 deletions site/default/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
<title>{{book_title}}</title>
</head>
<body>
Mobi (Kindle) |
<a href="book.epub">Epub (iBooks)</a> |
<a href="book.html">Single Page</a> |
<a href="book.pdf">PDF</a>
<hr/>
<div class="content">
<h1>{{book_title}}</h1>
<hr/>
Expand All @@ -30,8 +35,9 @@ <h2><a href="{{ section.link }}">{{section.title}}</a></h2>
</div>
</div>
<hr/>
<a href="book.mobi">Mobi</a>
<a href="book.epub">Epub</a>
Mobi (Kindle) |
<a href="book.epub">Epub (iBooks)</a> |
<a href="book.html">Single Page</a> |
<a href="book.pdf">PDF</a>
</body>
</html>

0 comments on commit 38fcb16

Please sign in to comment.