Skip to content

Commit 397b39a

Browse files
authored
Merge pull request #37 from progit/rework-files
Rework files for automatic build of PDF and epub
2 parents 2a4da75 + 0f19ead commit 397b39a

File tree

294 files changed

+901
-608
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

294 files changed

+901
-608
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ progit.pdfmarks
88
progit.epub
99
progit-kf8.epub
1010
progit.mobi
11-
/images/
11+

.travis.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
language: ruby
2+
sudo: false
3+
git:
4+
depth: false
5+
cache: bundler
6+
before_install:
7+
- wget https://raw.githubusercontent.com/progit/progit2-pub/master/bootstrap.sh
8+
- sh bootstrap.sh
9+
script: bundle exec rake book:build
10+
after_success: bundle exec rake book:tag
11+
deploy:
12+
provider: releases
13+
file_glob: true
14+
file:
15+
- progit*.epub
16+
- progit*.mobi
17+
- progit*.pdf
18+
skip_cleanup: true
19+
on:
20+
tags: true
21+
api-key: $GITHUB_API_TOKEN
22+
branches:
23+
only:
24+
- master
25+
- /^2\.1(\.\d+)+$/
26+
27+
addons:
28+
apt:
29+
packages:
30+
- epubcheck
31+
notifications:
32+
email:
33+
on_success: never
34+
on_failure: always

book/A-git-in-other-environments/1-git-other-environments.asc renamed to A-git-in-other-environments.asc

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
[#A-git-in-other-environments]
12
[appendix]
23
== Git in Other Environments
34

@@ -6,18 +7,18 @@ You can work with local files, connect your repository to others over a network,
67
But the story doesn't end there; Git is usually used as part of a larger ecosystem, and the terminal isn't always the best way to work with it.
78
Now we'll take a look at some of the other kinds of environments where Git can be useful, and how other applications (including yours) work alongside Git.
89

9-
include::sections/guis.asc[]
10+
include::book/A-git-in-other-environments/sections/guis.asc[]
1011

11-
include::sections/visualstudio.asc[]
12+
include::book/A-git-in-other-environments/sections/visualstudio.asc[]
1213

13-
include::sections/eclipse.asc[]
14+
include::book/A-git-in-other-environments/sections/eclipse.asc[]
1415

1516

16-
include::sections/bash.asc[]
17+
include::book/A-git-in-other-environments/sections/bash.asc[]
1718

18-
include::sections/zsh.asc[]
19+
include::book/A-git-in-other-environments/sections/zsh.asc[]
1920

20-
include::sections/powershell.asc[]
21+
include::book/A-git-in-other-environments/sections/powershell.asc[]
2122

2223
=== Summary
2324

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
[#B-embedding-git]
12
[appendix]
23
== Embedding Git in your Applications
34

@@ -6,8 +7,8 @@ Even non-developer applications, such as document editors, could potentially ben
67

78
If you need to integrate Git with your application, you have essentially three choices: spawning a shell and using the Git command-line tool; Libgit2; and JGit.
89

9-
include::sections/command-line.asc[]
10+
include::book/B-embedding-git/sections/command-line.asc[]
1011

11-
include::sections/libgit2.asc[]
12+
include::book/B-embedding-git/sections/libgit2.asc[]
1213

13-
include::sections/jgit.asc[]
14+
include::book/B-embedding-git/sections/jgit.asc[]
Lines changed: 119 additions & 118 deletions
Large diffs are not rendered by default.

Gemfile

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
source 'https://rubygems.org'
22

33
gem 'rake'
4-
gem 'asciidoctor', '1.5.0'
4+
gem 'asciidoctor', '1.5.6.1'
55

66
gem 'json'
77
gem 'awesome_print'
88

9-
gem 'asciidoctor-epub3', '1.0.0.alpha.2'
10-
gem 'asciidoctor-pdf', '1.5.0.alpha.5'
9+
gem 'asciidoctor-epub3', :git => 'https://github.com/asciidoctor/asciidoctor-epub3'
10+
gem 'asciidoctor-pdf', '1.5.0.alpha.16'
11+
gem 'asciidoctor-pdf-cjk', '~> 0.1.3'
12+
gem 'asciidoctor-pdf-cjk-kai_gen_gothic', '~> 0.1.1'
1113

1214
gem 'coderay'
1315
gem 'pygments.rb'
1416
gem 'thread_safe'
15-
gem 'epubcheck'
17+
gem 'epubcheck-ruby'
1618
gem 'kindlegen'
19+
20+
gem 'octokit'
21+
gem 'github_changelog_generator', github: 'Furtif/github-changelog-generator'

README.asc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
image::https://travis-ci.org/progit/progit2-zh-tw.svg?branch=master[]
12
= Pro Git, 繁體中文第二版
23

34
歡迎您來到 Pro Git 繁體中文第二版
@@ -32,7 +33,7 @@
3233

3334
----
3435
$ bundle install
35-
$ bundle exec rake book:build
36+
$ TRAVIS_REPO_SLUG="progit/progit2-zh-tw" bundle exec rake book:build
3637
Converting to HTML...
3738
-- HTML output at progit.html
3839
Converting to EPub...

Rakefile

Lines changed: 226 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,240 @@
1-
namespace :book do
2-
desc 'prepare build'
3-
task :prebuild do
4-
Dir.mkdir 'images' unless Dir.exists? 'images'
5-
Dir.glob("book/*/images/*").each do |image|
6-
FileUtils.copy(image, "images/" + File.basename(image))
7-
end
1+
# coding: utf-8
2+
require 'octokit'
3+
require 'github_changelog_generator'
4+
5+
def exec_or_raise(command)
6+
puts `#{command}`
7+
if (! $?.success?)
8+
raise "'#{command}' failed"
9+
end
10+
end
11+
12+
module GitHubChangelogGenerator
13+
14+
#OPTIONS = %w[ user project token date_format output
15+
# bug_prefix enhancement_prefix issue_prefix
16+
# header merge_prefix issues
17+
# add_issues_wo_labels add_pr_wo_labels
18+
# pulls filter_issues_by_milestone author
19+
# unreleased_only unreleased unreleased_label
20+
# compare_link include_labels exclude_labels
21+
# bug_labels enhancement_labels
22+
# between_tags exclude_tags exclude_tags_regex since_tag max_issues
23+
# github_site github_endpoint simple_list
24+
# future_release release_branch verbose release_url
25+
# base configure_sections add_sections]
26+
27+
def get_log(&task_block)
28+
options = Parser.default_options
29+
yield(options) if task_block
30+
31+
options[:user],options[:project] = ENV['TRAVIS_REPO_SLUG'].split('/')
32+
options[:token] = ENV['GITHUB_API_TOKEN']
33+
options[:unreleased] = false
34+
35+
generator = Generator.new options
36+
generator.compound_changelog
837
end
938

39+
module_function :get_log
40+
end
41+
42+
namespace :book do
1043
desc 'build basic book formats'
11-
task :build => :prebuild do
44+
task :build do
45+
46+
puts "Generating contributors list"
47+
exec_or_raise("git shortlog -s --all| grep -v -E '(Straub|Chacon)' | cut -f 2- | column -c 120 > book/contributors.txt")
48+
49+
# detect if the deployment is using glob
50+
travis = File.read(".travis.yml")
51+
version_string = ENV['TRAVIS_TAG'] || '0'
52+
if travis.match(/file_glob/)
53+
progit_v = "progit_v#{version_string}"
54+
else
55+
progit_v = "progit"
56+
end
57+
text = File.read('progit.asc')
58+
new_contents = text.gsub("$$VERSION$$", version_string).gsub("$$DATE$$", Time.now.strftime("%Y-%m-%d"))
59+
File.open("#{progit_v}.asc", "w") {|file| file.puts new_contents }
60+
1261
puts "Converting to HTML..."
13-
`bundle exec asciidoctor progit.asc`
14-
puts " -- HTML output at progit.html"
62+
exec_or_raise("bundle exec asciidoctor #{progit_v}.asc")
63+
puts " -- HTML output at #{progit_v}.html"
1564

1665
puts "Converting to EPub..."
17-
`bundle exec asciidoctor-epub3 progit.asc`
18-
puts " -- Epub output at progit.epub"
66+
exec_or_raise("bundle exec asciidoctor-epub3 #{progit_v}.asc")
67+
puts " -- Epub output at #{progit_v}.epub"
68+
69+
exec_or_raise("epubcheck #{progit_v}.epub")
1970

2071
puts "Converting to Mobi (kf8)..."
21-
`bundle exec asciidoctor-epub3 -a ebook-format=kf8 progit.asc`
22-
puts " -- Mobi output at progit.mobi"
72+
exec_or_raise("bundle exec asciidoctor-epub3 -a ebook-format=kf8 #{progit_v}.asc")
73+
# remove the fake epub that would shadow the really one
74+
exec_or_raise("rm progit*kf8.epub")
75+
puts " -- Mobi output at #{progit_v}.mobi"
2376

77+
repo = ENV['TRAVIS_REPO_SLUG']
2478
puts "Converting to PDF... (this one takes a while)"
25-
`bundle exec asciidoctor-pdf progit.asc 2>/dev/null`
26-
puts " -- PDF output at progit.pdf"
79+
if (repo == "progit/progit2-zh")
80+
exec_or_raise("asciidoctor-pdf-cjk-kai_gen_gothic-install")
81+
exec_or_raise("bundle exec asciidoctor-pdf -r asciidoctor-pdf-cjk -r asciidoctor-pdf-cjk-kai_gen_gothic -a pdf-style=KaiGenGothicCN #{progit_v}.asc")
82+
elsif (repo == "progit/progit2-ja")
83+
exec_or_raise("asciidoctor-pdf-cjk-kai_gen_gothic-install")
84+
exec_or_raise("bundle exec asciidoctor-pdf -r asciidoctor-pdf-cjk -r asciidoctor-pdf-cjk-kai_gen_gothic -a pdf-style=KaiGenGothicJP #{progit_v}.asc")
85+
elsif (repo == "progit/progit2-zh-tw")
86+
exec_or_raise("asciidoctor-pdf-cjk-kai_gen_gothic-install")
87+
exec_or_raise("bundle exec asciidoctor-pdf -r asciidoctor-pdf-cjk -r asciidoctor-pdf-cjk-kai_gen_gothic -a pdf-style=KaiGenGothicTW #{progit_v}.asc")
88+
else
89+
exec_or_raise("bundle exec asciidoctor-pdf #{progit_v}.asc 2>/dev/null")
90+
end
91+
puts " -- PDF output at #{progit_v}.pdf"
92+
end
93+
94+
desc 'tag the repo with the latest version'
95+
task :tag do
96+
api_token = ENV['GITHUB_API_TOKEN']
97+
if ((api_token) && (ENV['TRAVIS_PULL_REQUEST'] == 'false'))
98+
repo = ENV['TRAVIS_REPO_SLUG']
99+
@octokit = Octokit::Client.new(:access_token => api_token)
100+
begin
101+
last_version=@octokit.latest_release(repo).tag_name
102+
rescue
103+
last_version="2.1.-1"
104+
end
105+
new_patchlevel= last_version.split('.')[-1].to_i + 1
106+
new_version="2.1.#{new_patchlevel}"
107+
if (ENV['TRAVIS_BRANCH']=='master')
108+
obj = @octokit.create_tag(repo, new_version, "Version " + new_version,
109+
ENV['TRAVIS_COMMIT'], 'commit',
110+
'Automatic build', 'automatic@no-domain.org',
111+
Time.now.utc.iso8601)
112+
@octokit.create_ref(repo, "tags/#{new_version}", obj.sha)
113+
p "Created tag #{last_version}"
114+
elsif (ENV['TRAVIS_TAG'])
115+
version = ENV['TRAVIS_TAG']
116+
changelog = GitHubChangelogGenerator.get_log do |config|
117+
config[:since_tag] = last_version
118+
end
119+
credit_line = "*This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*"
120+
changelog.gsub!(credit_line, "")
121+
@octokit.create_release(repo, new_version, {:name => "v#{new_version}", :body => changelog})
122+
p "Created release #{new_version}"
123+
else
124+
p 'This only runs on a commit to master'
125+
end
126+
else
127+
p 'No interaction with GitHub'
128+
end
129+
end
130+
131+
desc 'convert book to asciidoctor compatibility'
132+
task:convert do
133+
`cp -aR ../progit2/images .`
134+
`sed -i -e 's!/images/!!' .gitignore`
135+
`git add images`
136+
`git rm -r book/*/images`
137+
138+
chapters = [
139+
["01", "introduction" ],
140+
["02", "git-basics" ],
141+
["03", "git-branching" ],
142+
["04", "git-server" ],
143+
["05", "distributed-git" ],
144+
["06", "github" ],
145+
["07", "git-tools" ],
146+
["08", "customizing-git" ],
147+
["09", "git-and-other-scms" ],
148+
["10", "git-internals" ],
149+
["A", "git-in-other-environments" ],
150+
["B", "embedding-git" ],
151+
["C", "git-commands" ]
152+
]
153+
154+
crossrefs = {}
155+
chapters.each { | num, title |
156+
if num =~ /[ABC]/
157+
chap = "#{num}-#{title}"
158+
else
159+
chap = "ch#{num}-#{title}"
160+
end
161+
Dir[File.join ["book","#{num}-#{title}" , "sections","*.asc"]].map { |filename|
162+
File.read(filename).scan(/\[\[(.*?)\]\]/)
163+
}.flatten.each { |ref|
164+
crossrefs[ref] = "#{chap}"
165+
}
166+
}
167+
168+
headrefs = {}
169+
chapters.each { | num, title |
170+
if num =~ /[ABC]/
171+
chap = "#{num}-#{title}"
172+
else
173+
chap = "ch#{num}-#{title}"
174+
end
175+
Dir[File.join ["book","#{num}-#{title}", "*.asc"]].map { |filename|
176+
File.read(filename).scan(/\[\[(.*?)\]\]/)
177+
}.flatten.each { |ref|
178+
headrefs[ref] = "#{chap}"
179+
}
180+
}
181+
182+
# transform all internal cross refs
183+
chapters.each { | num, title |
184+
if num =~ /[ABC]/
185+
chap = "#{num}-#{title}"
186+
else
187+
chap = "ch#{num}-#{title}"
188+
end
189+
files = Dir[File.join ["book","#{num}-#{title}" , "sections","*.asc"]] +
190+
Dir[File.join ["book","#{num}-#{title}" ,"1-*.asc"]]
191+
p files
192+
files.each { |filename|
193+
content = File.read(filename)
194+
new_contents = content.gsub(/\[\[(.*?)\]\]/, '[[r\1]]').gsub(
195+
"&rarr;", "→").gsub(/<<(.*?)>>/) { |match|
196+
ch = crossrefs[$1]
197+
h = headrefs[$1]
198+
# p " #{match} -> #{ch}, #{h}"
199+
if ch
200+
# if local do not add the file
201+
if ch==chap
202+
"<<r#{$1}>>"
203+
else
204+
"<<#{ch}#r#{$1}>>"
205+
end
206+
elsif h
207+
if h==chap
208+
"<<#{chap}>>"
209+
else
210+
"<<#{h}##{h}>>"
211+
end
212+
end
213+
}
214+
File.open(filename, "w") {|file| file.puts new_contents }
215+
}
216+
}
217+
218+
chapters.each { | num, title |
219+
if num =~ /[ABC]/
220+
chap = "#{num}-#{title}"
221+
else
222+
chap = "ch#{num}-#{title}"
223+
end
224+
Dir[File.join ["book","#{num}-#{title}" ,"1*.asc"]].map { |filename|
225+
content = File.read (filename)
226+
new_contents = content.gsub(/include::(.*?)asc/) {|match|
227+
"include::book/#{num}-#{title}/#{$1}asc"}
228+
`git rm -f #{filename}`
229+
File.open("#{chap}.asc", "w") {|file|
230+
file.puts "[##{chap}]\n"
231+
file.puts new_contents }
232+
`git add "#{chap}.asc"`
233+
}
234+
}
27235
end
28236
end
29237

238+
239+
30240
task :default => "book:build"

0 commit comments

Comments
 (0)