Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for asciidoctor command in place of asciidoc #56

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
24 changes: 16 additions & 8 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,32 @@ PATH
nokogiri

GEM
remote: http://rubygems.org/
remote: https://rubygems.org/
specs:
diff-lcs (1.1.3)
asciidoctor (1.5.2)
coderay (1.1.0)
diff-lcs (1.2.5)
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)
posix-spawn (0.3.6)
rake (0.9.2)
test-unit (2.3.2)
liquid (3.0.2)
mime-types (1.25.1)
mini_portile (0.6.2)
nokogiri (1.6.6.2)
mini_portile (~> 0.6.0)
posix-spawn (0.3.11)
power_assert (0.2.3)
rake (10.4.2)
test-unit (3.0.9)
power_assert

PLATFORMS
ruby

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

image::https://travis-ci.org/schacon/git-scribe.png[Build Status,link="https://travis-ci.org/schacon/git-scribe"]

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 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 @@ -20,9 +19,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 @@ -41,8 +40,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>

6 changes: 3 additions & 3 deletions example/book/book.asc
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ WARNING: This is a warning.

CAUTION: Tread lightly.

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

== Source Code Highlighting

Expand Down
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
18 changes: 11 additions & 7 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 Expand Up @@ -354,12 +358,12 @@ def classpath_delimiter
end

def run_xslt(jar_arguments, java_options)
# xslthl config must be passed as an xsl param (highlight.xslthl.config), not a system property (xslthl.config)
ex <<-SH
java -cp "#{base('vendor/saxon.jar')}#{classpath_delimiter}#{base('vendor/xslthl-2.0.2.jar')}" \
-Dxslthl.config=file://"#{base('docbook-xsl/highlighting/xslthl-config.xml')}" \
#{java_options.map { |k, v| "-D#{k}=#{v}" }.join(' ')} \
com.icl.saxon.StyleSheet \
#{jar_arguments}
com.icl.saxon.StyleSheet #{jar_arguments} \
highlight.xslthl.config="file://#{base('docbook-xsl/highlighting/xslthl-config.xml')}"
SH
end
end
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/

2 changes: 1 addition & 1 deletion test/check_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# see http://svn.apache.org/repos/asf/xmlgraphics/fop/trunk/src/java/org/apache/fop/cli/CommandLineOptions.java
test "scribe should correctly check fop availability" do
assert_equal @scribe.check_can_run('fop -v -out list'), true
assert_equal @scribe.check_can_run('fop -v'), false
assert_equal @scribe.check_can_run('fop -version'), true
assert_equal @scribe.check_can_run('fop -failboat'), false
end
end