Skip to content

Commit e8a8f68

Browse files
committed
Refactor book:build task
Добавлены book:build_html book:build_epub book:build_pdf
1 parent 6846ed8 commit e8a8f68

File tree

2 files changed

+98
-42
lines changed

2 files changed

+98
-42
lines changed

README.asc

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,13 @@ image:https://travis-ci.org/progit/progit2-ru.svg?branch=master["Build Status",
1010

1111
С момента публикации первого издания многое изменилось.
1212
Для начала, мы перешли с Markdown на AsciiDoc -- вот краткий справочник по синтаксису https://asciidoctor.org/docs/asciidoc-syntax-quick-reference/[AsciiDoc].
13-
К тому же мы теперь используем https://atlas.oreilly.com[Atlas] от О'Рейли для постоянной сборки книги, так что все основные форматы всегда в наличии.
1413

1514
Еще мы убрали переводы из подразделов английского языка в отдельные репозитории.
1615
Подробнее в пункте про переводы.
1716

1817
== Участие
1918

20-
Чтобы исправить ошибку или добавить что-то новое в этот репозиторий, вам нужно открыть пулл-реквест на GitHub.
19+
Чтобы исправить ошибку или добавить что-то новое в этот репозиторий, вам нужно открыть запрос на изменение (Pull Request) на GitHub.
2120

2221
Несмотря на то, что в английской версии просят воздержаться от стилистических изменений на больших участках текста, русский перевод профессиональные редакторы не просматривали, будем рады вашим правкам.
2322

@@ -27,10 +26,11 @@ image:https://travis-ci.org/progit/progit2-ru.svg?branch=master["Build Status",
2726

2827
Самый простой -- поручить это нам. Робот реагирует на изменения в ветке `master` репозитория и автоматически собирает книгу во всех форматах.
2928

30-
Текущую сборку можно найти на https://git-scm.com/book/ru/v2.
29+
Текущую сборку можно найти по адресу https://git-scm.com/book/ru/v2.
3130

32-
Другой способ получить кнугу -- собрать её самостоятельно с помощью Asciidoctor.
33-
Используя команды ниже, вы сможете получить HTML, Epub, Mobi и PDF файлы:
31+
Другой способ получить книгу -- собрать её самостоятельно с помощью Asciidoctor.
32+
Раньше мы могли собирать файлы .mobi (Kindle), но сейчас не можем, см. https://github.com/progit/progit2/issues/1496[#1496] для получения дополнительной информации.
33+
Используя команды ниже, вы сможете получить HTML, Epub и PDF-файлы:
3434

3535
----
3636
$ bundle install
@@ -39,14 +39,32 @@ Converting to HTML...
3939
-- HTML output at progit.html
4040
Converting to EPub...
4141
-- Epub output at progit.epub
42-
Converting to Mobi (kf8)...
43-
-- Mobi output at progit.mobi
4442
Converting to PDF...
45-
-- PDF output at progit.pdf
43+
-- PDF output at progit.pdf
4644
----
4745

4846
Здесь используются проекты `asciidoctor`, `asciidoctor-pdf` и `asciidoctor-epub`.
4947

48+
Также возможно собрать отдельно в одном из поддерживаемых форматов (HTML, EPUB или PDF).
49+
50+
Сборка только в HTML:
51+
52+
----
53+
$ bundle exec rake book:build_html
54+
----
55+
56+
Сборка только в EPUB:
57+
58+
----
59+
$ bundle exec rake book:build_epub
60+
----
61+
62+
Сборка только в PDF:
63+
64+
----
65+
$ bundle exec rake book:build_pdf
66+
----
67+
5068
По умолчанию, `bundle install` устанавливает зависимости глобально в систему.
5169
Чтобы этого избежать, следует сконфигурировать менеджер пакетов перед установкой зависимостей с помощью следующей команды:
5270

Rakefile

Lines changed: 72 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,51 +8,74 @@ namespace :book do
88
end
99
end
1010

11-
desc 'build basic book formats'
12-
task :build do
11+
lang = "ru"
12+
begin
13+
locale_file = "attributes-#{lang}.adoc"
14+
locale_file_url = "https://raw.githubusercontent.com/asciidoctor/asciidoctor/master/data/locale/#{locale_file}"
15+
16+
if not File.exist?(locale_file)
17+
puts "Downloading locale attributes file #{locale_file_url} ..."
18+
l10n_text = URI.open(locale_file_url).read
19+
File.open(locale_file, 'w') { |file| file.puts l10n_text }
20+
else
21+
puts "Use existing file with locale attributes #{locale_file}"
22+
end
23+
rescue
24+
puts "[ERROR] Can not download attributes list for language #{lang}"
25+
end
26+
27+
# Variables referenced for build
28+
version_string = ENV['TRAVIS_TAG'] || `git describe --tags`.chomp
29+
if version_string.empty?
30+
version_string = '0'
31+
end
32+
33+
date_string = Time.now.strftime("%d.%m.%Y")
34+
params = "--attribute revnumber='#{version_string}' --attribute revdate='#{date_string}' --attribute lang='#{lang}'"
1335

36+
`rm book/contributors.txt`
37+
38+
desc 'build basic book formats'
39+
task :build => [:build_html, :build_epub, :build_pdf] do
1440
begin
15-
lang = "ru"
16-
begin
17-
locale_file = "attributes-#{lang}.adoc"
18-
locale_file_url = "https://raw.githubusercontent.com/asciidoctor/asciidoctor/master/data/locale/#{locale_file}"
19-
20-
if not File.exist?(locale_file)
21-
puts "Downloading locale attributes file #{locale_file_url} ..."
22-
l10n_text = URI.open(locale_file_url).read
23-
File.open(locale_file, 'w') { |file| file.puts l10n_text }
24-
else
25-
puts "Use existing file with locale attributes #{locale_file}"
26-
end
27-
rescue
28-
puts "[ERROR] Can not download attributes list for language #{lang}"
29-
end
30-
31-
version_string = ENV['TRAVIS_TAG'] || `git describe --tags`.chomp
32-
if version_string.empty?
33-
version_string = '0'
34-
end
35-
36-
date_string = Time.now.strftime("%d.%m.%Y")
37-
params = "--attribute revnumber='#{version_string}' --attribute revdate='#{date_string}' --attribute lang=#{lang} "
41+
# Run check
42+
Rake::Task['book:check'].invoke
43+
44+
# Rescue to ignore checking errors
45+
rescue => e
46+
puts e.message
47+
puts "Error when checking books (ignored)"
48+
end
49+
end
50+
51+
desc 'build basic book formats (for ci)'
52+
task :ci => [:build_html, :build_epub, :build_pdf] do
53+
# Run check, but don't ignore any errors
54+
Rake::Task['book:check'].invoke
55+
end
3856

57+
desc 'generate contributors list'
58+
file 'book/contributors.txt' do
3959
puts "Generating contributors list"
40-
`git shortlog -s | grep -v -E "(Straub|Chacon|dependabot)" | cut -f 2- | column -c 96 > book/contributors.txt`
60+
`git shortlog -s | grep -v -E "(Straub|Chacon|dependabot)" | cut -f 2- | column -x -c 48 > book/contributors.txt`
61+
end
4162

63+
desc 'build HTML format'
64+
task :build_html => 'book/contributors.txt' do
4265
puts "Converting to HTML..."
4366
`bundle exec asciidoctor #{params} -a data-uri progit.asc`
4467
puts " -- HTML output at progit.html"
68+
end
4569

46-
puts " -- Validate HTML file progit.html"
47-
exec_or_raise('htmlproofer --check-html progit.html')
48-
70+
desc 'build Epub format'
71+
task :build_epub => 'book/contributors.txt' do
4972
puts "Converting to EPub..."
5073
`bundle exec asciidoctor-epub3 #{params} progit.asc`
5174
puts " -- Epub output at progit.epub"
75+
end
5276

53-
puts " -- Validate Epub output file progit.epub"
54-
exec_or_raise('epubcheck progit.epub')
55-
77+
desc 'build Mobi format'
78+
task :build_mobi => 'book/contributors.txt' do
5679
# Commented out the .mobi file creation because the kindlegen dependency is not available.
5780
# For more information on this see: #1496.
5881
# This is a (hopefully) temporary fix until upstream asciidoctor-epub3 is fixed and we can offer .mobi files again.
@@ -61,11 +84,26 @@ namespace :book do
6184
# `bundle exec asciidoctor-epub3 #{params} -a ebook-format=kf8 progit.asc`
6285
# puts " -- Mobi output at progit.mobi"
6386

87+
# FIXME: If asciidoctor-epub3 supports Mobi again, uncomment these lines below
88+
puts "Converting to Mobi isn't supported yet."
89+
puts "For more information see issue #1496 at https://github.com/progit/progit2/issues/1496."
90+
exit(127)
91+
end
92+
93+
desc 'build PDF format'
94+
task :build_pdf => 'book/contributors.txt' do
6495
puts "Converting to PDF... (this one takes a while)"
65-
`bundle exec asciidoctor-pdf #{params} progit.asc 2>/dev/null`
96+
`bundle exec asciidoctor-pdf #{params} progit.asc`
6697
puts " -- PDF output at progit.pdf"
67-
end
6898
end
99+
100+
desc 'Check generated books'
101+
task :check => [:build_html, :build_epub] do
102+
puts "Checking generated books"
103+
exec_or_raise('htmlproofer --check-html progit.html')
104+
exec_or_raise('epubcheck progit.epub')
105+
end
106+
69107
end
70108

71109
task :default => "book:build"

0 commit comments

Comments
 (0)