Skip to content

Commit fad9ba8

Browse files
committed
add support for asciidoctor command in place of asciidoc
1 parent 6e3ff2a commit fad9ba8

File tree

11 files changed

+89
-42
lines changed

11 files changed

+89
-42
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: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,30 @@ 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 (0.1.4)
13+
coderay (1.1.0)
14+
diff-lcs (1.2.4)
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)
19+
liquid (2.5.0)
20+
mime-types (1.23)
21+
mini_portile (0.5.1)
22+
nokogiri (1.6.0)
23+
mini_portile (~> 0.5.0)
2024
posix-spawn (0.3.6)
21-
rake (0.9.2)
22-
test-unit (2.3.2)
25+
rake (10.1.0)
26+
test-unit (2.5.5)
2327

2428
PLATFORMS
2529
ruby
2630

2731
DEPENDENCIES
32+
asciidoctor
33+
coderay
2834
git-scribe!
2935
rake
3036
test-unit

README.asciidoc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Git Scribe
22
==========
33

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

77
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.
@@ -18,9 +18,9 @@ Eventually, these are the feature goals for the project:
1818
* Translation workflow tools
1919
* Selling (possibly): Kindle, iBooks, Lulu, Pledgie(?)
2020
21-
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).
21+
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).
2222

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

2525
Disclaimer
2626
==========
@@ -39,8 +39,10 @@ For local generation (eventually pushing to GitHub will handle gen for you), it
3939
* Git
4040
* Ruby
4141
* asciidoc, a2x (8.6.4)
42+
** asciidoctor can be used in place of asciidoc
4243
* xsltproc
4344
* source-highlight (3.1)
45+
** coderay is required when using asciidoctor
4446
* FOP (1.0) - for PDF generation
4547

4648
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-

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')

template/book/book.asc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ CAUTION: Tread lightly.
3636
If you need to embed source code, you can do so from external files
3737
like this:
3838

39-
[c]
40-
source~~~~
39+
[source,c]
40+
--
4141
include::include/hello.c[]
42-
source~~~~
42+
--
4343

4444
=== Source Code Highlighting
4545

0 commit comments

Comments
 (0)