2020-12-21 13:12:05 +01:00
|
|
|
require 'rake/clean'
|
2022-04-16 08:46:29 +02:00
|
|
|
require 'fileutils'
|
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
|
|
|
|
2022-04-16 08:46:29 +02:00
|
|
|
secfiles = Sec_files.new(FileList['src/sec*.src.md'].to_a.map{|file| Sec_file.new(file)})
|
2021-04-27 14:08:30 +02:00
|
|
|
secfiles.renum!
|
|
|
|
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
|
2022-04-16 08:46:29 +02:00
|
|
|
abstract = Src_file.new "src/abstract.src.md"
|
2021-04-27 14:08:30 +02:00
|
|
|
|
|
|
|
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}
|
2022-04-16 08:46:29 +02:00
|
|
|
texfiles = sectexfiles + othertexfiles
|
|
|
|
abstract_tex = "latex/"+abstract.to_tex
|
2020-12-21 13:12:05 +01:00
|
|
|
|
2022-04-16 08:46:29 +02:00
|
|
|
["gfm", "html", "latex"].each{|d| Dir.mkdir(d) unless Dir.exist?(d)}
|
2021-01-11 03:15:04 +01:00
|
|
|
|
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
|
2022-04-16 08:46:29 +02:00
|
|
|
src2md abstract, abstract.to_md, "gfm"
|
|
|
|
buf = [ "# Gtk4 Tutorial for beginners\n", "\n" ]\
|
|
|
|
+ File.readlines(abstract.to_md)\
|
|
|
|
+ ["\n", "## Table of contents\n", "\n"]
|
2021-04-27 14:08:30 +02:00
|
|
|
File.delete(abstract.to_md)
|
2022-04-16 08:46:29 +02:00
|
|
|
secfiles.each_with_index do |secfile, i|
|
|
|
|
h = File.open(secfile.path){|file| file.readline}.sub(/^#* */,"").chomp
|
|
|
|
buf << "1. [#{h}](gfm/#{secfile.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
|
|
|
|
2022-04-16 08:46:29 +02:00
|
|
|
# srcfiles => mdfiles
|
|
|
|
(0...srcfiles.size).each do |i|
|
|
|
|
file mdfiles[i] => [srcfiles[i]] + srcfiles[i].c_files do
|
|
|
|
src2md srcfiles[i], mdfiles[i], "gfm"
|
|
|
|
if srcfiles[i].instance_of? Sec_file
|
|
|
|
i = srcfiles[i].num.to_i - 1
|
2021-04-27 14:08:30 +02:00
|
|
|
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
|
2022-04-16 08:46:29 +02:00
|
|
|
File.write(mdfiles[i], nav + "\n" + File.read(mdfiles[i]) + "\n" + nav)
|
2020-12-21 13:12:05 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-04-16 08:46:29 +02:00
|
|
|
task html: %w[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
|
|
|
|
abstract_md = "html/#{abstract.to_md}"
|
2022-04-16 08:46:29 +02:00
|
|
|
src2md abstract, abstract_md, "html"
|
|
|
|
buf = ["# Gtk4 Tutorial for beginners\n", "\n"]\
|
|
|
|
+ File.readlines(abstract_md)\
|
|
|
|
+ ["\n", "## Table of contents\n", "\n"]
|
2021-04-27 14:08:30 +02:00
|
|
|
File.delete(abstract_md)
|
2022-04-16 08:46:29 +02:00
|
|
|
secfiles.each_with_index do |secfile, i|
|
|
|
|
h = File.open(secfile.path){|file| file.readline}.sub(/^#* */,"").chomp
|
|
|
|
buf << "1. [#{h}](#{secfile.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
|
|
|
|
|
2022-04-16 08:46:29 +02:00
|
|
|
(0...srcfiles.size).each do |i|
|
|
|
|
file htmlfiles[i] => [srcfiles[i]] + srcfiles[i].c_files do
|
|
|
|
html_md = "html/#{srcfiles[i].to_md}"
|
|
|
|
src2md srcfiles[i], html_md, "html"
|
|
|
|
if srcfiles[i].instance_of? Sec_file
|
|
|
|
i = srcfiles[i].num.to_i - 1 # 0 based index
|
2021-04-27 14:08:30 +02:00
|
|
|
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
|
2022-04-16 08:46:29 +02:00
|
|
|
File.write(html_md, nav + "\n" + File.read(html_md) + "\n" + nav)
|
2021-01-09 07:35:06 +01:00
|
|
|
end
|
2022-04-16 08:46:29 +02:00
|
|
|
sh "pandoc -o #{htmlfiles[i]} #{html_md}"
|
2021-02-06 15:50:02 +01:00
|
|
|
File.delete(html_md)
|
2022-04-16 08:46:29 +02:00
|
|
|
add_head_tail_html htmlfiles[i]
|
2020-12-21 13:12:05 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-04-16 08:46:29 +02:00
|
|
|
task pdf: %w[latex/main.tex] 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
|
|
|
|
|
2022-04-16 10:31:29 +02:00
|
|
|
file "latex/main.tex" => [abstract_tex] + texfiles do
|
2022-04-16 08:46:29 +02:00
|
|
|
gen_main_tex "latex", abstract.to_tex, sectexfiles, othertexfiles
|
2021-02-09 10:16:52 +01:00
|
|
|
end
|
|
|
|
|
2021-04-27 14:08:30 +02:00
|
|
|
file abstract_tex => abstract do
|
|
|
|
abstract_md = "latex/"+abstract.to_md
|
2022-04-16 08:46:29 +02:00
|
|
|
src2md abstract, abstract_md, "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
|
|
|
|
|
2022-04-16 10:31:29 +02:00
|
|
|
(0...texfiles.size).each do |i|
|
2022-04-16 08:46:29 +02:00
|
|
|
file texfiles[i] => [srcfiles[i]] + srcfiles[i].c_files do
|
|
|
|
tex_md = "latex/#{srcfiles[i].to_md}"
|
|
|
|
src2md srcfiles[i], tex_md, "latex"
|
|
|
|
if srcfiles[i] == "src/Readme_for_developers.src.md"
|
|
|
|
sh "pandoc -o #{texfiles[i]} #{tex_md}"
|
2021-06-30 16:52:33 +02:00
|
|
|
else
|
2022-04-16 08:46:29 +02:00
|
|
|
sh "pandoc --listings -o #{texfiles[i]} #{tex_md}"
|
2021-06-30 16:52:33 +02:00
|
|
|
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
|
2022-04-16 08:46:29 +02:00
|
|
|
remove_entry_secure('html') if Dir.exist?('html')
|
2021-01-09 07:35:06 +01:00
|
|
|
end
|
2021-01-11 03:15:04 +01:00
|
|
|
task :cleanlatex do
|
2022-04-16 08:46:29 +02:00
|
|
|
remove_entry_secure('latex') if Dir.exist?('latex')
|
2021-01-11 03:15:04 +01:00
|
|
|
end
|
|
|
|
task cleanall: [:clean, :cleanhtml, :cleanlatex]
|