mirror of
https://github.com/ToshioCP/Gtk4-tutorial.git
synced 2025-01-28 19:58:41 +01:00
Change Rakefile, lib_src2md.rb and lib_src_file.rb.
This commit is contained in:
parent
bfcfe106b1
commit
3db40bc7db
20 changed files with 122 additions and 117 deletions
39
Rakefile
39
Rakefile
|
@ -12,12 +12,8 @@ end
|
|||
secfiles = Sec_files.new secfiles
|
||||
secfiles.renum!
|
||||
|
||||
def basename srcfile
|
||||
File.basename(srcfile, ".src.md")
|
||||
end
|
||||
|
||||
abstract = Src_file.new "src/abstract.src.md"
|
||||
|
||||
|
||||
otherfiles = ["src/turtle/turtle_doc.src.md",
|
||||
"src/tfetextview/tfetextview_doc.src.md",
|
||||
"src/Readme_for_developers.src.md"].map {|file| Src_file.new file}
|
||||
|
@ -32,27 +28,12 @@ file_table = srcfiles.map do |srcfile|
|
|||
]
|
||||
end
|
||||
|
||||
# Paths are relative from the directory "src".
|
||||
file_table_src = srcfiles.map do |srcfile|
|
||||
[
|
||||
srcfile.sub(/^src\//, ""),
|
||||
"../gfm/" + srcfile.to_md,
|
||||
"../html/" + srcfile.to_html,
|
||||
"../latex/" + srcfile.to_tex
|
||||
]
|
||||
end
|
||||
|
||||
othermdfiles = otherfiles.map {|file| "gfm/" + file.to_md}
|
||||
otherhtmlfiles = otherfiles.map {|file| "html/" + file.to_html}
|
||||
othertexfiles = otherfiles.map {|file| "latex/" + file.to_tex}
|
||||
|
||||
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}
|
||||
|
||||
|
||||
["gfm", "html", "latex"].each do |d|
|
||||
if ! Dir.exist?(d)
|
||||
Dir.mkdir(d)
|
||||
|
@ -71,7 +52,7 @@ task md: %w[Readme.md] + mdfiles
|
|||
|
||||
file "Readme.md" => [abstract] + secfiles do
|
||||
buf = [ "# Gtk4 Tutorial for beginners\n", "\n" ]
|
||||
src2md abstract, abstract.to_md, file_table_src, "gfm"
|
||||
src2md abstract, abstract.to_md, file_table, "gfm"
|
||||
buf += File.readlines(abstract.to_md)
|
||||
File.delete(abstract.to_md)
|
||||
buf.append("\n", "## Table of contents\n", "\n")
|
||||
|
@ -84,8 +65,8 @@ file "Readme.md" => [abstract] + secfiles do
|
|||
end
|
||||
|
||||
file_table.each do |tbl|
|
||||
file tbl[1] => tbl[0] do
|
||||
src2md tbl[0], tbl[1], file_table_src, "gfm"
|
||||
file tbl[1] => [tbl[0]] + tbl[0].c_files do
|
||||
src2md tbl[0], tbl[1], file_table, "gfm"
|
||||
if tbl[0].instance_of? Sec_file
|
||||
i = tbl[0].num.to_i - 1
|
||||
if secfiles.size == 1
|
||||
|
@ -110,7 +91,7 @@ task html: ["html/index.html"] + htmlfiles
|
|||
file "html/index.html" => [abstract] + secfiles do
|
||||
buf = [ "# Gtk4 Tutorial for beginners\n", "\n" ]
|
||||
abstract_md = "html/#{abstract.to_md}"
|
||||
src2md abstract, abstract_md, file_table_src, "html"
|
||||
src2md abstract, abstract_md, file_table, "html"
|
||||
buf += File.readlines(abstract_md)
|
||||
File.delete(abstract_md)
|
||||
buf.append("\n", "## Table of contents\n", "\n")
|
||||
|
@ -126,9 +107,9 @@ file "html/index.html" => [abstract] + secfiles do
|
|||
end
|
||||
|
||||
file_table.each do |tbl|
|
||||
file tbl[2] => tbl[0] do
|
||||
file tbl[2] => [tbl[0]] + tbl[0].c_files do
|
||||
html_md = "html/" + tbl[0].to_md
|
||||
src2md tbl[0], html_md, file_table_src, "html"
|
||||
src2md tbl[0], html_md, file_table, "html"
|
||||
if tbl[0].instance_of? Sec_file
|
||||
i = tbl[0].num.to_i - 1 # 0 based index
|
||||
if secfiles.size == 1
|
||||
|
@ -166,15 +147,15 @@ end
|
|||
abstract_tex = "latex/"+abstract.to_tex
|
||||
file abstract_tex => abstract do
|
||||
abstract_md = "latex/"+abstract.to_md
|
||||
src2md abstract, abstract_md, file_table_src, "latex"
|
||||
src2md abstract, abstract_md, file_table, "latex"
|
||||
sh "pandoc --listings -o #{abstract_tex} #{abstract_md}"
|
||||
File.delete(abstract_md)
|
||||
end
|
||||
|
||||
file_table.each do |tbl|
|
||||
file tbl[3] => tbl[0] do
|
||||
file tbl[3] => [tbl[0]] + tbl[0].c_files do
|
||||
tex_md = "latex/" + tbl[0].to_md
|
||||
src2md tbl[0], tex_md, file_table_src, "latex"
|
||||
src2md tbl[0], tex_md, file_table, "latex"
|
||||
sh "pandoc --listings -o #{tbl[3]} #{tex_md}"
|
||||
File.delete(tex_md)
|
||||
end
|
||||
|
|
|
@ -5,13 +5,13 @@
|
|||
1. You need linux operationg system, ruby, rake, pandoc and latex system.
|
||||
2. download this repository and uncompress the files.
|
||||
3. change your current directory to the top directory of the source files.
|
||||
4. type `rake html` to create html files. The files are generated under `html` directory.
|
||||
5. type `rake pdf` to create pdf file. The file is generated under `latex` directory.
|
||||
4. type `rake html` to create html files. The files are created under `html` directory.
|
||||
5. type `rake pdf` to create pdf file. The file is created under `latex` directory.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- Linux operationg system.
|
||||
The programs in the repository has been tested on Ubuntu 2.04.
|
||||
The programs in the repository has been tested on Ubuntu 21.04.
|
||||
- Download the files in this repository.
|
||||
There are two ways to download.
|
||||
1. Use git.
|
||||
|
@ -225,7 +225,7 @@ For example,
|
|||
@@@if gfm
|
||||
Refer to [tfetextview API reference](tfetextview_doc.md)
|
||||
@@@elif html
|
||||
Refer to [tfetextview API reference](../src/tfetextview/tfetextview_doc.src.html)
|
||||
Refer to [tfetextview API reference](tfetextview_doc.html)
|
||||
@@@elif latex
|
||||
Refer to tfetextview API reference in appendix.
|
||||
@@@end
|
||||
|
@ -298,6 +298,12 @@ The task of the script seems easy, but the program is not so simple.
|
|||
The script `mktbl.rb` uses a library `lib/lib_mktbl.rb`
|
||||
This script is independent from `src2md.rb`.
|
||||
|
||||
@@@commands are effective in the whole text.
|
||||
This means you can't stop the @@@commands.
|
||||
But sometimes you want to show the commands literally like this document.
|
||||
One solution is to add four blanks at the top of the line.
|
||||
Then @@@commands are not effective because @@@commands must be at the top of the line.
|
||||
|
||||
## Directory structure
|
||||
|
||||
There are six directories under `gtk4_tutorial` directory.
|
||||
|
@ -391,10 +397,10 @@ So the size is removed in the conversion.
|
|||
|
||||
If a .src.md file has relative URL link, it will be changed by conversion.
|
||||
Because .src.md files are located under `src` directory and GFM files are located under `gfm` directory, base URL of GFM files is different from base URL of .src.md files.
|
||||
For example, `[src/sample.c](../src/sample.c)` is translated to `[src/sample.c](../src/sample.c)`.
|
||||
For example, `[src/sample.c](sample.c)` is translated to `[src/sample.c](../src/sample.c)`.
|
||||
|
||||
If a link points another .src.md file, then the target filename will be changed to .md file.
|
||||
For example, `[Section 5](sec5.md)` is translated to `[Section 5](../src/sec5.md)`.
|
||||
For example, `[Section 5](sec5.md)` is translated to `[Section 5](sec5.md)`.
|
||||
|
||||
If you want to clean the directory, that means remove all the generated markdown files, type `rake clean`.
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ A new version of the text file editor (`tfe`) will be made in this section and t
|
|||
It is `tfe5`.
|
||||
There are many changes from the prior version.
|
||||
All the sources are listed in [Section 16](sec16.md).
|
||||
They are located in two directories, [src/tfe5](../src/tfe5) and [src/tfetextview](../src/tfetextview).
|
||||
They are located in two directories, [src/tfe5](tfe5) and [src/tfetextview](tfetextview).
|
||||
|
||||
## Encapsulation
|
||||
|
||||
|
|
|
@ -442,11 +442,11 @@ See [Gio reference manual](https://developer.gnome.org/gio/stable/GFile.html#g-f
|
|||
|
||||
## The API document and source file of tfetextview.c
|
||||
|
||||
Refer [API document of TfeTextView](tfetextview_doc.md).
|
||||
Refer [API document of TfeTextView](../gfm/tfetextview_doc.md).
|
||||
It is under the directory `src/tfetextview`.
|
||||
|
||||
All the source files are listed in [Section 16](sec16.md).
|
||||
You can find them under [src/tfe5](../src/tfe5) and [src/tfetextview](../src/tfetextview) directories.
|
||||
You can find them under [src/tfe5](tfe5) and [src/tfetextview](tfetextview) directories.
|
||||
|
||||
|
||||
Up: [Readme.md](../Readme.md), Prev: [Section 12](sec12.md), Next: [Section 14](sec14.md)
|
||||
|
|
|
@ -319,6 +319,6 @@ If you use git, run the terminal and type the following.
|
|||
|
||||
$ git clone https://github.com/ToshioCP/Gtk4-tutorial.git
|
||||
|
||||
The source files are under [`/src/tfe5`](../src/tfe5) directory.
|
||||
The source files are under [`/src/tfe5`](tfe5) directory.
|
||||
|
||||
Up: [Readme.md](../Readme.md), Prev: [Section 14](sec14.md), Next: [Section 16](sec16.md)
|
||||
|
|
28
gfm/sec18.md
28
gfm/sec18.md
|
@ -336,19 +336,21 @@ The code is as follows.
|
|||
90 gtk_window_present (GTK_WINDOW (win));
|
||||
91 }
|
||||
92
|
||||
93 int
|
||||
94 main (int argc, char **argv) {
|
||||
95 GtkApplication *app;
|
||||
96 int stat;
|
||||
97
|
||||
98 app = gtk_application_new ("com.github.ToshioCP.menu2", G_APPLICATION_FLAGS_NONE);
|
||||
99 g_signal_connect (app, "activate", G_CALLBACK (app_activate), NULL);
|
||||
100
|
||||
101 stat =g_application_run (G_APPLICATION (app), argc, argv);
|
||||
102 g_object_unref (app);
|
||||
103 return stat;
|
||||
104 }
|
||||
105
|
||||
93 #define APPLICATION_ID "com.github.ToshioCP.menu2"
|
||||
94
|
||||
95 int
|
||||
96 main (int argc, char **argv) {
|
||||
97 GtkApplication *app;
|
||||
98 int stat;
|
||||
99
|
||||
100 app = gtk_application_new (APPLICATION_ID, G_APPLICATION_FLAGS_NONE);
|
||||
101 g_signal_connect (app, "activate", G_CALLBACK (app_activate), NULL);
|
||||
102
|
||||
103 stat =g_application_run (G_APPLICATION (app), argc, argv);
|
||||
104 g_object_unref (app);
|
||||
105 return stat;
|
||||
106 }
|
||||
107
|
||||
~~~
|
||||
|
||||
- 5-26: Signal handlers.
|
||||
|
|
|
@ -1231,7 +1231,7 @@ The following is `meson.build`.
|
|||
16
|
||||
~~~
|
||||
|
||||
Source files of `tfe` is under [src/tfe6](../src/tfe6) directory.
|
||||
Source files of `tfe` is under [src/tfe6](tfe6) directory.
|
||||
Copy them to your temporary directory and try to compile and install.
|
||||
|
||||
~~~
|
||||
|
|
|
@ -842,7 +842,7 @@ $ ninja -C _build
|
|||
$ ninja -C _build install # or 'sudo ninja -C _build install'
|
||||
~~~
|
||||
|
||||
Source files are in [src/tfe7](../src/tfe7) directory.
|
||||
Source files are in [src/tfe7](tfe7) directory.
|
||||
|
||||
We made a very small text editor.
|
||||
You can add features to this editor.
|
||||
|
|
|
@ -116,7 +116,7 @@ To compile this, type the following.
|
|||
|
||||
$ gcc `pkg-config --cflags cairo` cairo.c `pkg-config --libs cairo`
|
||||
|
||||
![rectangle.png](../src/misc/rectangle.png)
|
||||
![rectangle.png](misc/rectangle.png)
|
||||
|
||||
There are lots of documentations in [Cairo's website](https://www.cairographics.org/).
|
||||
If you aren't familiar with Cairo, it is strongly recommended to read the [tutorial](https://www.cairographics.org/tutorial/) in the website.
|
||||
|
|
|
@ -6,7 +6,7 @@ A program `turtle` is an example with the combination of TfeTextView and GtkDraw
|
|||
It is a very small interpreter but it provides a tool to draw fractal curves.
|
||||
The following diagram is a Koch curve, which is a famous example of fractal curves.
|
||||
|
||||
![Koch curve](../src/turtle/image/turtle_koch.png)
|
||||
![Koch curve](turtle/image/turtle_koch.png)
|
||||
|
||||
This program uses flex and bison.
|
||||
Flex is a lexical analyzer.
|
||||
|
@ -42,7 +42,7 @@ The side of the square is 100 pixels long.
|
|||
|
||||
In the same way, you can draw other curves.
|
||||
The documentation above shows some fractal curves such as tree, snow and square-koch.
|
||||
The source code in turtle language is located at [src/turtle/example](../src/turtle/example) directory.
|
||||
The source code in turtle language is located at [src/turtle/example](turtle/example) directory.
|
||||
You can read these files into `turtle` editor by clicking on the `Open` button.
|
||||
|
||||
## Combination of TfeTextView and GtkDrawingArea objects
|
||||
|
@ -129,7 +129,7 @@ Its size is the same as the surface of the GtkDrawingArea instance.
|
|||
|
||||
|
||||
Other part of `turtleapplication.c` is almost same as the codes of `colorapplication.c` in the previous section.
|
||||
The codes of `turtleapplication.c` is in the [turtle directory](../src/turtle).
|
||||
The codes of `turtleapplication.c` is in the [turtle directory](turtle).
|
||||
|
||||
## What does the interpreter do?
|
||||
|
||||
|
|
|
@ -199,7 +199,7 @@ GtkNoSelection is used, so user can't select any item.
|
|||
79
|
||||
~~~
|
||||
|
||||
The file `list1.c` is located under the directory [src/misc](../src/misc).
|
||||
The file `list1.c` is located under the directory [src/misc](misc).
|
||||
Make a shell script below and save it to your bin directory.
|
||||
(If you've installed Gtk4 from the source to $HOME/local, then your bin directory is $Home/local/bin.
|
||||
Otherwise, $Home/bin is your private bin directory.)
|
||||
|
@ -268,7 +268,7 @@ Therefore, GtkListItem instance is used as the `this` object of the lookup tag w
|
|||
`this` object will be explained in [section 27](sec27.md).
|
||||
|
||||
The C source code is as follows.
|
||||
Its name is `list2.c` and located under [src/misc](../src/misc) directory.
|
||||
Its name is `list2.c` and located under [src/misc](misc) directory.
|
||||
|
||||
~~~C
|
||||
1 #include <gtk/gtk.h>
|
||||
|
@ -427,7 +427,7 @@ Because it can be NULL when GListItem `item` is unbound.
|
|||
If its GFileInfo, then return the filename (copy of the filename).
|
||||
|
||||
The whole program (`list3.c`) is as follows.
|
||||
The program is located in [src/misc](../src/misc) directory.
|
||||
The program is located in [src/misc](misc) directory.
|
||||
|
||||
~~~C
|
||||
1 #include <gtk/gtk.h>
|
||||
|
|
|
@ -482,7 +482,7 @@ Such functionality comes from desktop.
|
|||
|
||||
## Compilation and execution
|
||||
|
||||
The source files are located in [src/list4](../src/list4) directory.
|
||||
The source files are located in [src/list4](list4) directory.
|
||||
To compile and execute list4, type as follows.
|
||||
|
||||
~~~
|
||||
|
@ -566,7 +566,7 @@ This method decreases the number of ui files.
|
|||
But, the new ui file is a bit complicated especially for the beginners.
|
||||
If you feel some difficulty, it is better for you to separate the ui file.
|
||||
|
||||
A directory [src/list5](../src/list5) includes the ui file above.
|
||||
A directory [src/list5](list5) includes the ui file above.
|
||||
|
||||
|
||||
Up: [Readme.md](../Readme.md), Prev: [Section 25](sec25.md), Next: [Section 27](sec27.md)
|
||||
|
|
|
@ -23,7 +23,7 @@ Evaluation is like a calculation.
|
|||
A value is got by evaluating the expression.
|
||||
|
||||
First, I want to show you the C file of the example for GtkExpression.
|
||||
Its name is `exp.c` and located under [src/expression](../src/expression) directory.
|
||||
Its name is `exp.c` and located under [src/expression](expression) directory.
|
||||
You don't need to understand the details now, just look at it.
|
||||
It will be explained in the next subsection.
|
||||
|
||||
|
@ -97,7 +97,7 @@ It will be explained in the next subsection.
|
|||
67 gtk_box_append (GTK_BOX (box), label3);
|
||||
68 gtk_box_append (GTK_BOX (box), entry);
|
||||
69 gtk_window_set_child (GTK_WINDOW (win1), box);
|
||||
70
|
||||
70
|
||||
71 /* Constant expression */
|
||||
72 expression = gtk_constant_expression_new (G_TYPE_INT,100);
|
||||
73 if (gtk_expression_evaluate (expression, NULL, &value)) {
|
||||
|
@ -637,7 +637,7 @@ It will be used in the next section to build GtkListItem in GtkColumnView, which
|
|||
|
||||
## Compilation and execution
|
||||
|
||||
All the sources are in [src/expression](../src/expression) directory.
|
||||
All the sources are in [src/expression](expression) directory.
|
||||
Change your current directory to the directory and run meson and ninja.
|
||||
Then, execute the application.
|
||||
|
||||
|
|
|
@ -490,7 +490,7 @@ These are almost same as the functions in section 25 and 26.
|
|||
|
||||
## Compilation and execution.
|
||||
|
||||
All the source files are in [src/column](../src/column) directory.
|
||||
All the source files are in [src/column](column) directory.
|
||||
Change your current directory to the directory and type the following.
|
||||
|
||||
~~~
|
||||
|
|
|
@ -3,23 +3,23 @@
|
|||
TfeTextView -- Child object of GtkTextView. It holds GFile which the contents of GtkTextBuffer correponds to.
|
||||
|
||||
## Functions
|
||||
- GFile *[tfe_text_view_get_file ()](../src/tfetextview/#tfe_text_view_get_file)
|
||||
- void [tfe_text_view_open ()](../src/tfetextview/#tfe_text_view_open)
|
||||
- void [tfe_text_view_save ()](../src/tfetextview/#tfe_text_view_save)
|
||||
- void [tfe_text_view_saveas ()](../src/tfetextview/#tfe_text_view_saveas)
|
||||
- GtkWidget *[tfe_text_view_new_with_file ()](../src/tfetextview/#tfe_text_view_new_with_file)
|
||||
- GtkWidget *[tfe_text_view_new ()](../src/tfetextview/#tfe_text_view_new)
|
||||
- GFile *[tfe_text_view_get_file ()](#tfe_text_view_get_file)
|
||||
- void [tfe_text_view_open ()](#tfe_text_view_open)
|
||||
- void [tfe_text_view_save ()](#tfe_text_view_save)
|
||||
- void [tfe_text_view_saveas ()](#tfe_text_view_saveas)
|
||||
- GtkWidget *[tfe_text_view_new_with_file ()](#tfe_text_view_new_with_file)
|
||||
- GtkWidget *[tfe_text_view_new ()](#tfe_text_view_new)
|
||||
|
||||
## Signals
|
||||
|
||||
- void [change-file](../src/tfetextview/#change-file)
|
||||
- void [open-response](../src/tfetextview/#open-response)
|
||||
- void [change-file](#change-file)
|
||||
- void [open-response](#open-response)
|
||||
|
||||
## Types and Values
|
||||
|
||||
- [TfeTextView](../src/tfetextview/#tfetextview-1)
|
||||
- [TfeTextViewClass](../src/tfetextview/#tfetextviewclass)
|
||||
- [TfeTextViewOpenResponseType](../src/tfetextview/#enum-tfetextviewopenresponsetype)
|
||||
- [TfeTextView](#tfetextview-1)
|
||||
- [TfeTextViewClass](#tfetextviewclass)
|
||||
- [TfeTextViewOpenResponseType](#enum-tfetextviewopenresponsetype)
|
||||
|
||||
## Object Hierarchy
|
||||
|
||||
|
|
|
@ -27,14 +27,14 @@ Type the following command then turtle shows the following window.
|
|||
$ turtle
|
||||
~~~
|
||||
|
||||
![Screenshot just after it's executed](../src/turtle/image/turtle1.png)
|
||||
![Screenshot just after it's executed](image/turtle1.png)
|
||||
|
||||
The left half is a text editor and the right half is a surface.
|
||||
Surface is like a canvas to draw shapes.
|
||||
|
||||
Write turtle language in the text editor and click on `run` button, then the program will be executed and it draws shapes on the surface.
|
||||
|
||||
![Tree](../src/turtle/image/turtle_tree.png)
|
||||
![Tree](image/turtle_tree.png)
|
||||
|
||||
If you add the following line in `turtle.h`, then codes to inform the status will also be compiled.
|
||||
However, the speed will be quite slow because of the output messages.
|
||||
|
@ -86,7 +86,7 @@ Therefore, `tr 90` means "Turn right by 90 degrees".
|
|||
If you click on the `run`button, then two line segments appears.
|
||||
One is vertical and the other is horizontal.
|
||||
|
||||
![Two line segments on the surface](../src/turtle/image/turtle2.png)
|
||||
![Two line segments on the surface](image/turtle2.png)
|
||||
|
||||
## Background and foreground color
|
||||
|
||||
|
@ -113,7 +113,7 @@ This command changes the pen color.
|
|||
The prior shapes on the surface aren't affected.
|
||||
After this command, the turtle draws lines with the new color.
|
||||
|
||||
![Change the foreground color](../src/turtle/image/turtle3.png)
|
||||
![Change the foreground color](image/turtle3.png)
|
||||
|
||||
## Other simple commands
|
||||
|
||||
|
@ -307,7 +307,7 @@ Recursive call can be applied to draw fractal curves.
|
|||
Fractal curves appear when a procedure is applied to it repeatedly.
|
||||
The procedure replaces a part of the curve with the contracted curve.
|
||||
|
||||
![Tree](../src/turtle/image/turtle_tree.png)
|
||||
![Tree](image/turtle_tree.png)
|
||||
|
||||
This shape is called tree.
|
||||
The basic pattern of this shape is a line segment.
|
||||
|
@ -321,9 +321,9 @@ This repeating is programmed by recursive call.
|
|||
Two more examples are shown here.
|
||||
They are Koch curve and Square Koch curve.
|
||||
|
||||
![Koch curve](../src/turtle/image/turtle_koch.png)
|
||||
![Koch curve](image/turtle_koch.png)
|
||||
|
||||
![Square Koch curve](../src/turtle/image/turtle_square_koch.png)
|
||||
![Square Koch curve](image/turtle_square_koch.png)
|
||||
|
||||
## Tokens and punctuations
|
||||
|
||||
|
|
|
@ -72,7 +72,8 @@ require 'pathname'
|
|||
# Bison, lex, markdown and meson aren't supported.
|
||||
|
||||
# file_table contains paths of source, GFM, html and latex.
|
||||
# It is possible to get the relationship between source file and created GFM/html/latex file.
|
||||
# If the paths are relative, srcmd and md must be relative.
|
||||
# And their base directory must be the same.
|
||||
|
||||
# type is "gfm", "html" or "latex".
|
||||
# Caller can specify the target type.
|
||||
|
@ -275,13 +276,13 @@ def change_rel_link line, org_dir, new_dir, file_table=nil, type="gfm"
|
|||
link = $2
|
||||
if file_table
|
||||
file_table.each do |tbl|
|
||||
if tbl[0] == link
|
||||
link = tbl[i]
|
||||
if tbl[0] == "#{org_dir}/#{link}"
|
||||
p_link = Pathname.new tbl[i]
|
||||
link = p_link.relative_path_from(p_new_dir).to_s
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
if ! (link =~ /^(http|\/)/)
|
||||
elsif ! (link =~ /^(http|\/)/)
|
||||
p_link = Pathname.new "#{org_dir}/#{link}"
|
||||
link = p_link.relative_path_from(p_new_dir).to_s
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
class Src_file <String
|
||||
def initialize path
|
||||
unless path.instance_of?(String)
|
||||
unless path.is_a?(String)
|
||||
raise "Src_file class initialization error: The argument is not String type."
|
||||
end
|
||||
unless File.exist?(path)
|
||||
|
@ -13,6 +13,20 @@ class Src_file <String
|
|||
@dirname = File.dirname path
|
||||
super(path)
|
||||
end
|
||||
def replace path
|
||||
unless path.is_a?(String)
|
||||
raise "Replace error: The argument is not String type."
|
||||
end
|
||||
unless File.exist?(path)
|
||||
raise "Replace error: File #{path} is not exist."
|
||||
end
|
||||
unless path =~ /\.src\.md$/
|
||||
raise "Replace error: The argment \"#{path}\" doesn't have .src.md suffix."
|
||||
end
|
||||
super(path)
|
||||
@name = File.basename path, ".src.md"
|
||||
@dirname = File.dirname path
|
||||
end
|
||||
def path
|
||||
self
|
||||
end
|
||||
|
@ -31,15 +45,6 @@ class Src_file <String
|
|||
def to_tex
|
||||
@name+".tex"
|
||||
end
|
||||
end
|
||||
|
||||
class Sec_file < Src_file
|
||||
def initialize path
|
||||
unless path =~ /sec\d+(\.\d+)?\.src\.md$/
|
||||
raise "Sec_file class initialization error: The argment \"#{path}\" doesn't have secXX.src.md form. XX is int or float."
|
||||
end
|
||||
super(path)
|
||||
end
|
||||
def c_files
|
||||
buf = IO.readlines(self)
|
||||
files = []
|
||||
|
@ -57,8 +62,18 @@ class Sec_file < Src_file
|
|||
# lines out of @@@include command is thrown away.
|
||||
end
|
||||
end
|
||||
raise "Syntax error: @@@include didn't end (no @@@ line)." if in_include
|
||||
files
|
||||
end
|
||||
end
|
||||
|
||||
class Sec_file < Src_file
|
||||
def initialize path
|
||||
unless path =~ /sec\d+(\.\d+)?\.src\.md$/
|
||||
raise "Sec_file class initialization error: The argment \"#{path}\" doesn't have secXX.src.md form. XX is int or float."
|
||||
end
|
||||
super(path)
|
||||
end
|
||||
def num # the return value is String
|
||||
@name.match(/\d+(\.\d+)?/)[0]
|
||||
end
|
||||
|
@ -89,8 +104,6 @@ class Sec_file < Src_file
|
|||
if old != new
|
||||
File.rename old, new
|
||||
self.replace new
|
||||
@name = File.basename new, ".src.md"
|
||||
@dirname = File.dirname new
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -136,7 +149,7 @@ private
|
|||
(self.size - 1).downto 0 do |i|
|
||||
if tbl[i][2] == false
|
||||
n = tbl[i][1] # number to substitute
|
||||
found = self.find_index { |sec_file| sec_file != self && sec_file.to_f == n }
|
||||
found = self.find_index { |sec_file| sec_file.to_f == n }
|
||||
unless found # OK to replace
|
||||
self[i].renum! n
|
||||
tbl[i][2] = true
|
||||
|
|
|
@ -5,13 +5,13 @@
|
|||
1. You need linux operationg system, ruby, rake, pandoc and latex system.
|
||||
2. download this repository and uncompress the files.
|
||||
3. change your current directory to the top directory of the source files.
|
||||
4. type `rake html` to create html files. The files are generated under `html` directory.
|
||||
5. type `rake pdf` to create pdf file. The file is generated under `latex` directory.
|
||||
4. type `rake html` to create html files. The files are created under `html` directory.
|
||||
5. type `rake pdf` to create pdf file. The file is created under `latex` directory.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- Linux operationg system.
|
||||
The programs in the repository has been tested on Ubuntu 2.04.
|
||||
The programs in the repository has been tested on Ubuntu 21.04.
|
||||
- Download the files in this repository.
|
||||
There are two ways to download.
|
||||
1. Use git.
|
||||
|
@ -223,9 +223,9 @@ This command is similar to "#if", "#elif", #else" and "#endif" directives in C p
|
|||
For example,
|
||||
|
||||
@@@if gfm
|
||||
Refer to [tfetextview API reference](tfetextview/tfetextview_doc.src.md)
|
||||
Refer to [tfetextview API reference](tfetextview_doc.md)
|
||||
@@@elif html
|
||||
Refer to [tfetextview API reference](tfetextview/tfetextview_doc.src.html)
|
||||
Refer to [tfetextview API reference](tfetextview_doc.html)
|
||||
@@@elif latex
|
||||
Refer to tfetextview API reference in appendix.
|
||||
@@@end
|
||||
|
@ -298,6 +298,12 @@ The task of the script seems easy, but the program is not so simple.
|
|||
The script `mktbl.rb` uses a library `lib/lib_mktbl.rb`
|
||||
This script is independent from `src2md.rb`.
|
||||
|
||||
@@@commands are effective in the whole text.
|
||||
This means you can't stop the @@@commands.
|
||||
But sometimes you want to show the commands literally like this document.
|
||||
One solution is to add four blanks at the top of the line.
|
||||
Then @@@commands are not effective because @@@commands must be at the top of the line.
|
||||
|
||||
## Directory structure
|
||||
|
||||
There are six directories under `gtk4_tutorial` directory.
|
||||
|
|
|
@ -467,7 +467,7 @@ files.each do |f|
|
|||
end
|
||||
|
||||
# --- test change_rel_link
|
||||
file_table = [["sec3.src.md", "../gfm/sec3.md", "../html/sec3.html", "../latex/sec3.html"]]
|
||||
file_table = [["src/sec3.src.md", "gfm/sec3.md", "html/sec3.html", "latex/sec3.html"]]
|
||||
# general relative link
|
||||
s = "[sample.c](temp/sample.c)"
|
||||
t = change_rel_link s, "test", "gfm"
|
||||
|
@ -498,27 +498,23 @@ dst_dirs.each do |d|
|
|||
src2md "temp/sample.src.md", "#{d}/sample.md"
|
||||
dst_md = File.read "#{d}/sample.md"
|
||||
if d == "gfm"
|
||||
print "Gfm result didn't match !!\n" if dst_md != sample_md_gfm
|
||||
print "Gfm result didn't match !!\n" unless dst_md == sample_md_gfm
|
||||
#File.write "tmp.txt", sample_md_gfm
|
||||
#system "diff", "#{d}/sample.md", "tmp.txt"
|
||||
#File.delete "tmp.txt"
|
||||
elsif d == "html"
|
||||
if dst_md != sample_md_html
|
||||
print "Html result didn't match !!\n"
|
||||
print "Html result didn't match !!\n" unless dst_md == sample_md_html
|
||||
#File.write "tmp.txt", sample_md_html
|
||||
#system "diff", "#{d}/sample.md", "tmp.txt"
|
||||
#File.delete "tmp.txt"
|
||||
end
|
||||
elsif d == "latex"
|
||||
sample_md_latex.gsub!(/\[((R|r)elative link)\]\([^)]+\)/, "\\1")
|
||||
if dst_md != sample_md_latex
|
||||
print "Latex result didn't match !!\n"
|
||||
print "Latex result didn't match !!\n" unless dst_md == sample_md_latex
|
||||
#File.write "tmp.txt", sample_md_latex
|
||||
#system "diff", "#{d}/sample.md", "tmp.txt"
|
||||
#File.delete "tmp.txt"
|
||||
end
|
||||
else
|
||||
print "Unexpected error.\n"
|
||||
print "Unexpected error.\n"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue