require 'rake/clean' require_relative 'lib/lib_sec_file.rb' require_relative 'lib/lib_src2md.rb' srcfiles = [] FileList['src/*.src.md'].each do |file| srcfiles << Sec_file.new(file) end srcfiles = Sec_files.new srcfiles srcfiles.renum! mdfilenames = srcfiles.map {|srcfile| "gfm/#{srcfile.to_md}"} htmlfilenames = srcfiles.map {|srcfile| "html/#{srcfile.to_html}"} texfilenames = srcfiles.map {|srcfile| "latex/#{srcfile.to_tex}"} ["gfm", "html", "latex"].each do |d| if ! Dir.exist?(d) Dir.mkdir(d) end end CLEAN.append(*mdfilenames) CLEAN << "Readme.md" # Abstract abstract=<<'EOS' This tutorial illustrates how to write C programs with Gtk4 library. It focuses on beginners so the contents are limited to basic things such as widgets, GObject, signal, menus and build system. Please refer [Gnome API reference](https://developer.gnome.org/) for further topics. This tutorial is under development and unstable. Even though the examples written in C language have been tested on gtk4 version 4.0, there might exist bugs. If you find any bugs, errors or mistakes in the tutorial and C examples, please let me know. You can post it to [github issues](https://github.com/ToshioCP/Gtk4-tutorial/issues). The latest version of the tutorial is located at [Gtk4-tutorial githup repository](https://github.com/ToshioCP/Gtk4-tutorial). You can read it without download. EOS abstract_html_array = abstract.gsub(/\[([^\]]*)\]\(([^\)]*)\)/,"\\1").split("\n\n") abstract_html_array.map! { |s| s.gsub(/[^\n]\z/,"\n").gsub(/\A/,"

\n").gsub(/\z/,"

\n") } abstract_html = abstract_html_array.join abstract_latex = abstract.gsub(/\[([^\]]*)\]\(([^\)]*)\)/, "\\href{\\2}{\\1}") # Headers or a tail which is necessary for html files. header=<<'EOS' gtk4 tutorial EOS tail=<<'EOS' EOS file_index =<<'EOS' gtk4 tutorial

Gtk4 Tutorial for beginners

@@@ abstract \n" + tail) IO.write("html/index.html",file_index) end 0.upto(srcfiles.size - 1) do |i| file "html/#{srcfiles[i].to_html}" => (srcfiles[i].c_files << srcfiles[i].path) do src2md srcfiles[i].path, "html/#{srcfiles[i].to_md}", -1 buf = IO.readlines "html/"+srcfiles[i].to_md buf.each do |line| line.gsub!(/(\[[^\]]*\])\((sec\d+)\.md\)/,"\\1(\\2.html)") end IO.write "html/"+srcfiles[i].to_md, buf.join sh "pandoc -o html/#{srcfiles[i].to_html} html/#{srcfiles[i].to_md}" File.delete("html/#{srcfiles[i].to_md}") if srcfiles.size == 1 nav = "Up: index.html\n" elsif i == 0 nav = "Up: index.html, " nav += "Next: Section 2\n" elsif i == srcfiles.size - 1 nav = "Up: index.html, " nav += "Prev: Section #{i}\n" else nav = "Up: index.html, " nav += "Prev: Section #{i}, " nav += "Next: Section #{i+2}\n" end buf = IO.readlines "html/"+srcfiles[i].to_html buf.insert(0, header, nav, "\n") buf.append("\n", nav, "\n", tail) IO.write "html/"+srcfiles[i].to_html, buf.join end end task pdf: "latex" do sh "cd latex; pdflatex main.tex" sh "cd latex; pdflatex main.tex" sh "mv latex/main.pdf latex/gtk4_tutorial.pdf" end task latex: ["latex/main.tex"] file "latex/main.tex" => texfilenames do 0.upto(srcfiles.size-1) do |i| main += " \\input{#{srcfiles[i].to_tex}}\n" end main += "\\end{document}\n" IO.write("latex/main.tex", main) IO.write("latex/helper.tex", helper) end 0.upto(srcfiles.size - 1) do |i| file "latex/#{srcfiles[i].to_tex}" => (srcfiles[i].c_files << srcfiles[i].path) do src2md srcfiles[i].path, "latex/#{srcfiles[i].to_md}", 80 sh "pandoc -o latex/#{srcfiles[i].to_tex} --top-level-division=chapter latex/#{srcfiles[i].to_md}" File.delete("latex/#{srcfiles[i].to_md}") end end task :clean task :cleanhtml do if Dir.exist?("html") && (! Dir.empty?("html")) sh "rm html/*" end end task :cleanlatex do if Dir.exist?("latex") && (! Dir.empty?("latex")) sh "rm latex/*" end end task cleanall: [:clean, :cleanhtml, :cleanlatex]