Skip to content

Commit

Permalink
add support for asciidoctor command in place of asciidoc
Browse files Browse the repository at this point in the history
  • Loading branch information
mojavelinux committed Jan 2, 2014
1 parent 6e3ff2a commit fad9ba8
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 42 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
source :rubygems
source 'https://rubygems.org'
gemspec
20 changes: 13 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,30 @@ PATH
nokogiri

GEM
remote: http://rubygems.org/
remote: https://rubygems.org/
specs:
diff-lcs (1.1.3)
asciidoctor (0.1.4)
coderay (1.1.0)
diff-lcs (1.2.4)
grit (2.5.0)
diff-lcs (~> 1.1)
mime-types (~> 1.15)
posix-spawn (~> 0.3.6)
liquid (2.3.0)
mime-types (1.19)
nokogiri (1.5.5)
liquid (2.5.0)
mime-types (1.23)
mini_portile (0.5.1)
nokogiri (1.6.0)
mini_portile (~> 0.5.0)
posix-spawn (0.3.6)
rake (0.9.2)
test-unit (2.3.2)
rake (10.1.0)
test-unit (2.5.5)

PLATFORMS
ruby

DEPENDENCIES
asciidoctor
coderay
git-scribe!
rake
test-unit
8 changes: 5 additions & 3 deletions README.asciidoc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Git Scribe
==========

The git-scribe tool is a simple command line toolset to help you use Git, GitHub and Asciidoc
The git-scribe tool is a simple command line toolset to help you use Git, GitHub and AsciiDoc
to write e-books. This provides tools for setting up the structure, collaborating with co-authors, doing technical and copy-editing, handling translations, taking errata, as well as publishing online, pdf, mobi (Kindle) and epub (iBooks, Nook) versions.

The project is targeted for writing books of any length, but should also be usable for articles and stuff too, though for a while you'll have to just do it as a really short book.
Expand All @@ -18,9 +18,9 @@ Eventually, these are the feature goals for the project:
* Translation workflow tools
* Selling (possibly): Kindle, iBooks, Lulu, Pledgie(?)
The idea is that you use the tool to generate a known structure, write in asciidoc and let the tool handle everything else for you. I want authors to be able to focus on writing and not have to worry about anything else (website, multiple format generation, etc).
The idea is that you use the tool to generate a known structure, write in AsciiDoc and let the tool handle everything else for you. I want authors to be able to focus on writing and not have to worry about anything else (website, multiple format generation, etc).

A good AsciiDoc cheat sheet: http://powerman.name/doc/asciidoc#_text
A good AsciiDoc cheat sheet: http://asciidoctor.org/docs/asciidoc-syntax-quick-reference/

Disclaimer
==========
Expand All @@ -39,8 +39,10 @@ For local generation (eventually pushing to GitHub will handle gen for you), it
* Git
* Ruby
* asciidoc, a2x (8.6.4)
** asciidoctor can be used in place of asciidoc
* xsltproc
* source-highlight (3.1)
** coderay is required when using asciidoctor
* FOP (1.0) - for PDF generation

Usage
Expand Down
2 changes: 2 additions & 0 deletions docbook-xsl/fo.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,6 @@
<xsl:attribute name="keep-together.within-column">auto</xsl:attribute>
</xsl:attribute-set>

<xsl:template name="root.messages"/>

</xsl:stylesheet>
18 changes: 8 additions & 10 deletions docbook-xsl/fo/highlight.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,18 @@
******************************************************************** -->

<xsl:template match='xslthl:keyword' mode="xslthl">
<fo:inline font-weight="bold" color="blue"><xsl:apply-templates mode="xslthl"/></fo:inline>
</xsl:template>

<xsl:template match='xslthl:string' mode="xslthl">
<fo:inline font-weight="bold" font-style="italic"><xsl:apply-templates mode="xslthl"/></fo:inline>
</xsl:template>

<xsl:template match='xslthl:comment' mode="xslthl">
<fo:inline font-style="italic" color="grey"><xsl:apply-templates mode="xslthl"/></fo:inline>
</xsl:template>

<xsl:template match='xslthl:tag' mode="xslthl">
<fo:inline font-weight="bold"><xsl:apply-templates mode="xslthl"/></fo:inline>
</xsl:template>
Expand All @@ -31,14 +39,6 @@
<fo:inline font-weight="bold"><xsl:apply-templates mode="xslthl"/></fo:inline>
</xsl:template>

<xsl:template match='xslthl:keyword' mode="xslthl">
<fo:inline font-weight="bold" color="blue"><xsl:apply-templates mode="xslthl"/></fo:inline>
</xsl:template>

<xsl:template match='xslthl:comment' mode="xslthl">
<fo:inline font-style="italic" color="grey"><xsl:apply-templates mode="xslthl"/></fo:inline>
</xsl:template>

<!--
<xsl:template match='xslthl:html'>
<span style='background:#AFF'><font color='blue'><xsl:apply-templates/></font></span>
Expand Down Expand Up @@ -70,6 +70,4 @@
<fo:inline font-weight="bold"><xsl:apply-templates mode="xslthl"/></fo:inline>
</xsl:template>


</xsl:stylesheet>

3 changes: 3 additions & 0 deletions git-scribe.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ Gem::Specification.new do |s|
s.add_dependency('grit')
s.add_development_dependency("rake")
s.add_development_dependency("test-unit")
# optional
s.add_development_dependency("asciidoctor")
s.add_development_dependency("coderay")

s.executables = %w( git-scribe )

Expand Down
15 changes: 15 additions & 0 deletions lib/git-scribe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@ def initialize
@args = []
@options = {}
@config = YAML::parse(File.open(local('.gitscribe'))).transform rescue {}
unless @config['asciidoc']
if check_can_run('asciidoctor --version')
@config['asciidoc'] = 'asciidoctor'
else
@config['asciidoc'] = 'asciidoc'
end
end

unless @config['source-highlighter']
if @config['asciidoc'] == 'asciidoctor'
@config['source-highlighter'] = 'coderay'
else
@config['source-highlighter'] = 'source-highlight'
end
end
end

## COMMANDS ##
Expand Down
41 changes: 29 additions & 12 deletions lib/git-scribe/check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,21 @@ module Check
def check(args = [])
status = {}

# check for asciidoc
if !check_can_run('asciidoc')
info "asciidoc is not present, please install it for anything to work"
status[:asciidoc] = false
asciidoc_cmd = nil
# check for asciidoc or asciidoctor
if !check_can_run('asciidoctor --version')
if !check_can_run('asciidoc')
info "neither asciidoc or asciidoctor are present, please install one of these for anything to work"
status[:asciidoc] = false
else
info "asciidoc - ok"
status[:asciidoc] = true
asciidoc_cmd = 'asciidoc'
end
else
info "asciidoc - ok"
info "asciidoc (using asciidoctor) - ok"
status[:asciidoc] = true
asciidoc_cmd = 'asciidoctor'
end

# check for xsltproc
Expand All @@ -31,16 +39,25 @@ def check(args = [])
status[:a2x] = true
end

# check for source-highlight
if !check_can_run('source-highlight --version')
info "source-highlight is not present, please install it for source code highlighting"
status[:highlight] = false
# check for source-highlight or coderay
if asciidoc_cmd == 'asciidoctor'
if !check_can_run('coderay --version')
info "coderay is not present, please install it for source code highlighting"
status[:highlight] = false
else
info "highlighting (using CodeRay) - ok"
status[:highlight] = true
end
else
info "highlighting - ok"
status[:highlight] = true
if !check_can_run('source-highlight --version')
info "source-highlight is not present, please install it for source code highlighting"
status[:highlight] = false
else
info "highlighting - ok"
status[:highlight] = true
end
end


# check for fop
if !check_can_run('fop -v -out list')
info "fop is not present, please install for PDF generation"
Expand Down
12 changes: 8 additions & 4 deletions lib/git-scribe/generate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def a2x_wss(type)
def do_docbook
return true if @done['docbook']
info "GENERATING DOCBOOK"
if ex("asciidoc -b docbook #{BOOK_FILE}")
if ex("#{@config['asciidoc']} -b docbook #{BOOK_FILE}")
@done['docbook'] = true
'book.xml'
end
Expand Down Expand Up @@ -96,8 +96,12 @@ def do_html
return true if @done['html']
info "GENERATING HTML"
# TODO: look for custom stylesheets
stylesheet = local('stylesheets') + '/scribe.css'
cmd = "asciidoc -a stylesheet=#{stylesheet} #{BOOK_FILE}"
if @config['asciidoc'] == 'asciidoctor'
cmd = "asciidoctor -a source-highlighter=coderay -a icons=font -a sectanchors #{BOOK_FILE}"
else
stylesheet = local('stylesheets') + '/scribe.css'
cmd = "asciidoc -a stylesheet=#{stylesheet} #{BOOK_FILE}"
end
if ex(cmd)
@done['html'] == true
'book.html'
Expand All @@ -108,7 +112,7 @@ def do_site
info "GENERATING SITE"
# TODO: check if html was already done

ex "asciidoc -b docbook #{BOOK_FILE}"
ex "#{@config['asciidoc']} -b docbook #{BOOK_FILE}"
run_xslt "book.xml #{base('docbook-xsl/xhtml/chunk.xsl')}", "html.stylesheet" => 1

source = File.read('index.html')
Expand Down
6 changes: 3 additions & 3 deletions template/book/book.asc
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ CAUTION: Tread lightly.
If you need to embed source code, you can do so from external files
like this:

[c]
source~~~~
[source,c]
--
include::include/hello.c[]
source~~~~
--

=== Source Code Highlighting

Expand Down
4 changes: 2 additions & 2 deletions template/book/chapter2.asc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This is a second chapter.

For more information and a fairly nice Asciidoc cheat sheet, see:
For more information, and a nice AsciiDoc syntax quick reference, see:

http://powerman.name/doc/asciidoc
http://asciidoctor.org/docs/asciidoc-syntax-quick-reference/

0 comments on commit fad9ba8

Please sign in to comment.