2020-12-21 13:12:05 +01:00
|
|
|
require 'rake/clean'
|
|
|
|
|
2021-04-27 14:08:30 +02:00
|
|
|
require_relative 'lib/lib_src_file.rb'
|
2020-12-21 13:12:05 +01:00
|
|
|
require_relative 'lib/lib_src2md.rb'
|
2021-02-06 15:50:02 +01:00
|
|
|
require_relative 'lib/lib_gen_main_tex.rb'
|
|
|
|
require_relative 'lib/lib_add_head_tail_html.rb'
|
2020-12-21 13:12:05 +01:00
|
|
|
|
2021-04-27 14:08:30 +02:00
|
|
|
secfiles = []
|
2021-02-06 15:50:02 +01:00
|
|
|
FileList['src/sec*.src.md'].each do |file|
|
2021-04-27 14:08:30 +02:00
|
|
|
secfiles << Sec_file.new(file)
|
2020-12-21 13:12:05 +01:00
|
|
|
end
|
2021-04-27 14:08:30 +02:00
|
|
|
secfiles = Sec_files.new secfiles
|
|
|
|
secfiles.renum!
|
|
|
|
|
|
|
|
abstract = Src_file.new "src/abstract.src.md"
|
2021-06-30 14:44:57 +02:00
|
|
|
|
2021-04-27 14:08:30 +02:00
|
|
|
otherfiles = ["src/turtle/turtle_doc.src.md",
|
|
|
|
"src/tfetextview/tfetextview_doc.src.md",
|
2021-05-14 14:34:11 +02:00
|
|
|
"src/Readme_for_developers.src.md"].map {|file| Src_file.new file}
|
2021-04-27 14:08:30 +02:00
|
|
|
srcfiles = secfiles + otherfiles
|
|
|
|
|
|
|
|
file_table = srcfiles.map do |srcfile|
|
|
|
|
[
|
|
|
|
srcfile,
|
|
|
|
"gfm/" + srcfile.to_md,
|
|
|
|
"html/" + srcfile.to_html,
|
|
|
|
"latex/" + srcfile.to_tex
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
mdfiles = srcfiles.map {|file| "gfm/" + file.to_md}
|
|
|
|
htmlfiles = srcfiles.map {|file| "html/" + file.to_html}
|
|
|
|
sectexfiles = secfiles.map {|file| "latex/" + file.to_tex}
|
|
|
|
othertexfiles = otherfiles.map {|file| "latex/" + file.to_tex}
|
|
|
|
texfiles = srcfiles.map {|file| "latex/" + file.to_tex}
|
2020-12-21 13:12:05 +01:00
|
|
|
|
2021-01-13 12:59:15 +01:00
|
|
|
["gfm", "html", "latex"].each do |d|
|
2021-01-11 03:15:04 +01:00
|
|
|
if ! Dir.exist?(d)
|
|
|
|
Dir.mkdir(d)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-04-27 14:08:30 +02:00
|
|
|
CLEAN.append(*mdfiles)
|
2020-12-21 13:12:05 +01:00
|
|
|
CLEAN << "Readme.md"
|
|
|
|
|
2021-01-09 07:35:06 +01:00
|
|
|
# tasks
|
|
|
|
|
2020-12-21 13:12:05 +01:00
|
|
|
task default: :md
|
2021-01-11 15:32:09 +01:00
|
|
|
task all: [:md, :html, :pdf]
|
2020-12-21 13:12:05 +01:00
|
|
|
|
2021-04-27 14:08:30 +02:00
|
|
|
task md: %w[Readme.md] + mdfiles
|
2021-01-09 07:35:06 +01:00
|
|
|
|
2021-04-27 14:08:30 +02:00
|
|
|
file "Readme.md" => [abstract] + secfiles do
|
2021-01-09 07:35:06 +01:00
|
|
|
buf = [ "# Gtk4 Tutorial for beginners\n", "\n" ]
|
2021-06-30 14:44:57 +02:00
|
|
|
src2md abstract, abstract.to_md, file_table, "gfm"
|
2021-04-27 14:08:30 +02:00
|
|
|
buf += File.readlines(abstract.to_md)
|
|
|
|
File.delete(abstract.to_md)
|
2021-04-22 04:48:18 +02:00
|
|
|
buf.append("\n", "## Table of contents\n", "\n")
|
2021-04-27 14:08:30 +02:00
|
|
|
0.upto(secfiles.size-1) do |i|
|
|
|
|
h = File.open(secfiles[i].path) { |file| file.readline }
|
2021-01-09 07:35:06 +01:00
|
|
|
h = h.gsub(/^#* */,"").chomp
|
2021-04-27 14:08:30 +02:00
|
|
|
buf << "1. [#{h}](gfm/#{secfiles[i].to_md})\n"
|
2021-01-09 07:35:06 +01:00
|
|
|
end
|
|
|
|
File.write("Readme.md", buf.join)
|
|
|
|
end
|
2020-12-21 13:12:05 +01:00
|
|
|
|
2021-04-27 14:08:30 +02:00
|
|
|
file_table.each do |tbl|
|
2021-06-30 14:44:57 +02:00
|
|
|
file tbl[1] => [tbl[0]] + tbl[0].c_files do
|
|
|
|
src2md tbl[0], tbl[1], file_table, "gfm"
|
2021-04-27 14:08:30 +02:00
|
|
|
if tbl[0].instance_of? Sec_file
|
|
|
|
i = tbl[0].num.to_i - 1
|
|
|
|
if secfiles.size == 1
|
|
|
|
nav = "Up: [Readme.md](../Readme.md)\n"
|
|
|
|
elsif i == 0
|
|
|
|
nav = "Up: [Readme.md](../Readme.md), Next: [Section 2](#{secfiles[1].to_md})\n"
|
|
|
|
elsif i == secfiles.size - 1
|
|
|
|
nav = "Up: [Readme.md](../Readme.md), Prev: [Section #{i}](#{secfiles[i-1].to_md})\n"
|
|
|
|
else
|
|
|
|
nav = "Up: [Readme.md](../Readme.md), Prev: [Section #{i}](#{secfiles[i-1].to_md}), Next: [Section #{i+2}](#{secfiles[i+1].to_md})\n"
|
|
|
|
end
|
|
|
|
buf = [nav, "\n"]
|
|
|
|
buf += File.readlines tbl[1]
|
|
|
|
buf.append("\n", nav)
|
|
|
|
File.write tbl[1], buf.join
|
2020-12-21 13:12:05 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-04-27 14:08:30 +02:00
|
|
|
task html: ["html/index.html"] + htmlfiles
|
2021-01-09 07:35:06 +01:00
|
|
|
|
2021-04-27 14:08:30 +02:00
|
|
|
file "html/index.html" => [abstract] + secfiles do
|
2021-02-06 15:50:02 +01:00
|
|
|
buf = [ "# Gtk4 Tutorial for beginners\n", "\n" ]
|
2021-04-27 14:08:30 +02:00
|
|
|
abstract_md = "html/#{abstract.to_md}"
|
2021-06-30 14:44:57 +02:00
|
|
|
src2md abstract, abstract_md, file_table, "html"
|
2021-04-27 14:08:30 +02:00
|
|
|
buf += File.readlines(abstract_md)
|
|
|
|
File.delete(abstract_md)
|
2021-04-22 04:48:18 +02:00
|
|
|
buf.append("\n", "## Table of contents\n", "\n")
|
2021-04-27 14:08:30 +02:00
|
|
|
0.upto(secfiles.size-1) do |i|
|
|
|
|
h = File.open(secfiles[i].path) { |file| file.readline }
|
2020-12-21 13:12:05 +01:00
|
|
|
h = h.gsub(/^#* */,"").chomp
|
2021-04-27 14:08:30 +02:00
|
|
|
buf << "1. [#{h}](#{secfiles[i].to_html})\n"
|
2021-01-09 07:35:06 +01:00
|
|
|
end
|
2021-02-06 15:50:02 +01:00
|
|
|
File.write("html/index.md", buf.join)
|
|
|
|
sh "pandoc -o html/index.html html/index.md"
|
|
|
|
File.delete "html/index.md"
|
|
|
|
add_head_tail_html "html/index.html"
|
2021-01-09 07:35:06 +01:00
|
|
|
end
|
|
|
|
|
2021-04-27 14:08:30 +02:00
|
|
|
file_table.each do |tbl|
|
2021-06-30 14:44:57 +02:00
|
|
|
file tbl[2] => [tbl[0]] + tbl[0].c_files do
|
2021-04-27 14:08:30 +02:00
|
|
|
html_md = "html/" + tbl[0].to_md
|
2021-06-30 14:44:57 +02:00
|
|
|
src2md tbl[0], html_md, file_table, "html"
|
2021-04-27 14:08:30 +02:00
|
|
|
if tbl[0].instance_of? Sec_file
|
|
|
|
i = tbl[0].num.to_i - 1 # 0 based index
|
|
|
|
if secfiles.size == 1
|
|
|
|
nav = "Up: [index.html](index.html)\n"
|
|
|
|
elsif i == 0
|
|
|
|
nav = "Up: [index.html](index.html), Next: [Section 2](#{secfiles[1].to_html})\n"
|
|
|
|
elsif i == secfiles.size - 1
|
|
|
|
nav = "Up: [index.html](index.html), Prev: [Section #{i}](#{secfiles[i-1].to_html})\n"
|
|
|
|
else
|
|
|
|
nav = "Up: [index.html](index.html), Prev: [Section #{i}](#{secfiles[i-1].to_html}), Next: [Section #{i+2}](#{secfiles[i+1].to_html})\n"
|
|
|
|
end
|
|
|
|
buf = [nav, "\n"]
|
|
|
|
buf += File.readlines html_md
|
|
|
|
buf.append("\n", nav)
|
|
|
|
File.write html_md, buf.join
|
2021-01-09 07:35:06 +01:00
|
|
|
end
|
2021-04-27 14:08:30 +02:00
|
|
|
sh "pandoc -o #{tbl[2]} #{html_md}"
|
2021-02-06 15:50:02 +01:00
|
|
|
File.delete(html_md)
|
2021-04-27 14:08:30 +02:00
|
|
|
add_head_tail_html tbl[2]
|
2020-12-21 13:12:05 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-01-11 03:15:04 +01:00
|
|
|
task pdf: "latex" do
|
2021-03-03 15:45:54 +01:00
|
|
|
sh "cd latex; lualatex main.tex"
|
|
|
|
sh "cd latex; lualatex main.tex"
|
2021-01-11 03:15:04 +01:00
|
|
|
sh "mv latex/main.pdf latex/gtk4_tutorial.pdf"
|
|
|
|
end
|
|
|
|
|
2021-01-22 14:14:05 +01:00
|
|
|
task latex: ["latex/main.tex"]
|
2021-01-11 03:15:04 +01:00
|
|
|
|
2021-04-27 14:08:30 +02:00
|
|
|
file "latex/main.tex" => ["latex/abstract.tex"]+texfiles do
|
|
|
|
gen_main_tex "latex", sectexfiles, othertexfiles
|
2021-02-09 10:16:52 +01:00
|
|
|
end
|
|
|
|
|
2021-04-27 14:08:30 +02:00
|
|
|
abstract_tex = "latex/"+abstract.to_tex
|
|
|
|
file abstract_tex => abstract do
|
|
|
|
abstract_md = "latex/"+abstract.to_md
|
2021-06-30 14:44:57 +02:00
|
|
|
src2md abstract, abstract_md, file_table, "latex"
|
2021-04-27 14:08:30 +02:00
|
|
|
sh "pandoc --listings -o #{abstract_tex} #{abstract_md}"
|
|
|
|
File.delete(abstract_md)
|
2021-03-07 03:36:51 +01:00
|
|
|
end
|
|
|
|
|
2021-04-27 14:08:30 +02:00
|
|
|
file_table.each do |tbl|
|
2021-06-30 14:44:57 +02:00
|
|
|
file tbl[3] => [tbl[0]] + tbl[0].c_files do
|
2021-04-27 14:08:30 +02:00
|
|
|
tex_md = "latex/" + tbl[0].to_md
|
2021-06-30 14:44:57 +02:00
|
|
|
src2md tbl[0], tex_md, file_table, "latex"
|
2021-06-30 16:52:33 +02:00
|
|
|
if tbl[0] == "src/Readme_for_developers.src.md"
|
|
|
|
sh "pandoc -o #{tbl[3]} #{tex_md}"
|
|
|
|
else
|
|
|
|
sh "pandoc --listings -o #{tbl[3]} #{tex_md}"
|
|
|
|
end
|
2021-04-27 14:08:30 +02:00
|
|
|
File.delete(tex_md)
|
2021-01-11 03:15:04 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-12-21 13:12:05 +01:00
|
|
|
task :clean
|
2021-01-09 07:35:06 +01:00
|
|
|
task :cleanhtml do
|
2021-01-11 03:15:04 +01:00
|
|
|
if Dir.exist?("html") && (! Dir.empty?("html"))
|
|
|
|
sh "rm html/*"
|
|
|
|
end
|
2021-01-09 07:35:06 +01:00
|
|
|
end
|
2021-01-11 03:15:04 +01:00
|
|
|
task :cleanlatex do
|
|
|
|
if Dir.exist?("latex") && (! Dir.empty?("latex"))
|
|
|
|
sh "rm latex/*"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
task cleanall: [:clean, :cleanhtml, :cleanlatex]
|
|
|
|
|