Skip to content

Commit e811f1c

Browse files
committed
add support for asciidoctor command in place of asciidoc
1 parent 41424bb commit e811f1c

File tree

12 files changed

+95
-47
lines changed

12 files changed

+95
-47
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
source :rubygems
1+
source 'https://rubygems.org'
22
gemspec

Gemfile.lock

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,32 @@ PATH
77
nokogiri
88

99
GEM
10-
remote: http://rubygems.org/
10+
remote: https://rubygems.org/
1111
specs:
12-
diff-lcs (1.1.3)
12+
asciidoctor (1.5.2)
13+
coderay (1.1.0)
14+
diff-lcs (1.2.5)
1315
grit (2.5.0)
1416
diff-lcs (~> 1.1)
1517
mime-types (~> 1.15)
1618
posix-spawn (~> 0.3.6)
17-
liquid (2.3.0)
18-
mime-types (1.19)
19-
nokogiri (1.5.5)
20-
posix-spawn (0.3.6)
21-
rake (0.9.2)
22-
test-unit (2.3.2)
19+
liquid (3.0.2)
20+
mime-types (1.25.1)
21+
mini_portile (0.6.2)
22+
nokogiri (1.6.6.2)
23+
mini_portile (~> 0.6.0)
24+
posix-spawn (0.3.11)
25+
power_assert (0.2.3)
26+
rake (10.4.2)
27+
test-unit (3.0.9)
28+
power_assert
2329

2430
PLATFORMS
2531
ruby
2632

2733
DEPENDENCIES
34+
asciidoctor
35+
coderay
2836
git-scribe!
2937
rake
3038
test-unit

README.asciidoc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ Git Scribe
33

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

6-
The git-scribe tool is a simple command line toolset to help you use Git, GitHub and Asciidoc
7-
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.
6+
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.
87

98
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.
109

@@ -20,9 +19,9 @@ Eventually, these are the feature goals for the project:
2019
* Translation workflow tools
2120
* Selling (possibly): Kindle, iBooks, Lulu, Pledgie(?)
2221
23-
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).
22+
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).
2423

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

2726
Disclaimer
2827
==========
@@ -41,8 +40,10 @@ For local generation (eventually pushing to GitHub will handle gen for you), it
4140
* Git
4241
* Ruby
4342
* asciidoc, a2x (8.6.4)
43+
** asciidoctor can be used in place of asciidoc
4444
* xsltproc
4545
* source-highlight (3.1)
46+
** coderay is required when using asciidoctor
4647
* FOP (1.0) - for PDF generation
4748

4849
Usage

docbook-xsl/fo.xsl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,6 @@
155155
<xsl:attribute name="keep-together.within-column">auto</xsl:attribute>
156156
</xsl:attribute-set>
157157

158+
<xsl:template name="root.messages"/>
159+
158160
</xsl:stylesheet>

docbook-xsl/fo/highlight.xsl

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,18 @@
1515
1616
******************************************************************** -->
1717

18+
<xsl:template match='xslthl:keyword' mode="xslthl">
19+
<fo:inline font-weight="bold" color="blue"><xsl:apply-templates mode="xslthl"/></fo:inline>
20+
</xsl:template>
21+
1822
<xsl:template match='xslthl:string' mode="xslthl">
1923
<fo:inline font-weight="bold" font-style="italic"><xsl:apply-templates mode="xslthl"/></fo:inline>
2024
</xsl:template>
2125

26+
<xsl:template match='xslthl:comment' mode="xslthl">
27+
<fo:inline font-style="italic" color="grey"><xsl:apply-templates mode="xslthl"/></fo:inline>
28+
</xsl:template>
29+
2230
<xsl:template match='xslthl:tag' mode="xslthl">
2331
<fo:inline font-weight="bold"><xsl:apply-templates mode="xslthl"/></fo:inline>
2432
</xsl:template>
@@ -31,14 +39,6 @@
3139
<fo:inline font-weight="bold"><xsl:apply-templates mode="xslthl"/></fo:inline>
3240
</xsl:template>
3341

34-
<xsl:template match='xslthl:keyword' mode="xslthl">
35-
<fo:inline font-weight="bold" color="blue"><xsl:apply-templates mode="xslthl"/></fo:inline>
36-
</xsl:template>
37-
38-
<xsl:template match='xslthl:comment' mode="xslthl">
39-
<fo:inline font-style="italic" color="grey"><xsl:apply-templates mode="xslthl"/></fo:inline>
40-
</xsl:template>
41-
4242
<!--
4343
<xsl:template match='xslthl:html'>
4444
<span style='background:#AFF'><font color='blue'><xsl:apply-templates/></font></span>
@@ -70,6 +70,4 @@
7070
<fo:inline font-weight="bold"><xsl:apply-templates mode="xslthl"/></fo:inline>
7171
</xsl:template>
7272

73-
7473
</xsl:stylesheet>
75-

example/book/book.asc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ WARNING: This is a warning.
5151

5252
CAUTION: Tread lightly.
5353

54-
[c]
55-
source~~~~
54+
[source,c]
55+
----
5656
include::include/hello.c[]
57-
source~~~~
57+
----
5858

5959
== Source Code Highlighting
6060

git-scribe.gemspec

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ Gem::Specification.new do |s|
2323
s.add_dependency('grit')
2424
s.add_development_dependency("rake")
2525
s.add_development_dependency("test-unit")
26+
# optional
27+
s.add_development_dependency("asciidoctor")
28+
s.add_development_dependency("coderay")
2629

2730
s.executables = %w( git-scribe )
2831

lib/git-scribe.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,21 @@ def initialize
2929
@args = []
3030
@options = {}
3131
@config = YAML::parse(File.open(local('.gitscribe'))).transform rescue {}
32+
unless @config['asciidoc']
33+
if check_can_run('asciidoctor --version')
34+
@config['asciidoc'] = 'asciidoctor'
35+
else
36+
@config['asciidoc'] = 'asciidoc'
37+
end
38+
end
39+
40+
unless @config['source-highlighter']
41+
if @config['asciidoc'] == 'asciidoctor'
42+
@config['source-highlighter'] = 'coderay'
43+
else
44+
@config['source-highlighter'] = 'source-highlight'
45+
end
46+
end
3247
end
3348

3449
## COMMANDS ##

lib/git-scribe/check.rb

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,21 @@ module Check
44
def check(args = [])
55
status = {}
66

7-
# check for asciidoc
8-
if !check_can_run('asciidoc')
9-
info "asciidoc is not present, please install it for anything to work"
10-
status[:asciidoc] = false
7+
asciidoc_cmd = nil
8+
# check for asciidoc or asciidoctor
9+
if !check_can_run('asciidoctor --version')
10+
if !check_can_run('asciidoc')
11+
info "neither asciidoc or asciidoctor are present, please install one of these for anything to work"
12+
status[:asciidoc] = false
13+
else
14+
info "asciidoc - ok"
15+
status[:asciidoc] = true
16+
asciidoc_cmd = 'asciidoc'
17+
end
1118
else
12-
info "asciidoc - ok"
19+
info "asciidoc (using asciidoctor) - ok"
1320
status[:asciidoc] = true
21+
asciidoc_cmd = 'asciidoctor'
1422
end
1523

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

34-
# check for source-highlight
35-
if !check_can_run('source-highlight --version')
36-
info "source-highlight is not present, please install it for source code highlighting"
37-
status[:highlight] = false
42+
# check for source-highlight or coderay
43+
if asciidoc_cmd == 'asciidoctor'
44+
if !check_can_run('coderay --version')
45+
info "coderay is not present, please install it for source code highlighting"
46+
status[:highlight] = false
47+
else
48+
info "highlighting (using CodeRay) - ok"
49+
status[:highlight] = true
50+
end
3851
else
39-
info "highlighting - ok"
40-
status[:highlight] = true
52+
if !check_can_run('source-highlight --version')
53+
info "source-highlight is not present, please install it for source code highlighting"
54+
status[:highlight] = false
55+
else
56+
info "highlighting - ok"
57+
status[:highlight] = true
58+
end
4159
end
4260

43-
4461
# check for fop
4562
if !check_can_run('fop -v -out list')
4663
info "fop is not present, please install for PDF generation"

lib/git-scribe/generate.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def a2x_wss(type)
4848
def do_docbook
4949
return true if @done['docbook']
5050
info "GENERATING DOCBOOK"
51-
if ex("asciidoc -b docbook #{BOOK_FILE}")
51+
if ex("#{@config['asciidoc']} -b docbook #{BOOK_FILE}")
5252
@done['docbook'] = true
5353
'book.xml'
5454
end
@@ -96,8 +96,12 @@ def do_html
9696
return true if @done['html']
9797
info "GENERATING HTML"
9898
# TODO: look for custom stylesheets
99-
stylesheet = local('stylesheets') + '/scribe.css'
100-
cmd = "asciidoc -a stylesheet=#{stylesheet} #{BOOK_FILE}"
99+
if @config['asciidoc'] == 'asciidoctor'
100+
cmd = "asciidoctor -a source-highlighter=coderay -a icons=font -a sectanchors #{BOOK_FILE}"
101+
else
102+
stylesheet = local('stylesheets') + '/scribe.css'
103+
cmd = "asciidoc -a stylesheet=#{stylesheet} #{BOOK_FILE}"
104+
end
101105
if ex(cmd)
102106
@done['html'] == true
103107
'book.html'
@@ -108,7 +112,7 @@ def do_site
108112
info "GENERATING SITE"
109113
# TODO: check if html was already done
110114

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

114118
source = File.read('index.html')

0 commit comments

Comments
 (0)