Skip to content

Commit 0b3231c

Browse files
committed
The documentation generation now uses SVG icons (instead of no icons)
- The sample scripts now includes generate_icons.py - a script that uses OMPython to export SVG icons. The code is not perfect, but it works for many cases and should not be very hard to extend. git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@17410 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent cfecabc commit 0b3231c

File tree

2 files changed

+1247
-11
lines changed

2 files changed

+1247
-11
lines changed

Examples/GenerateDoc.mos

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242
setDebugFlags("nogen") /* Don't generate dll/so-files when instantiating classes (performance) */;
4343

44-
loadModel(Modelica,{"3.2"});
44+
loadModel(Modelica);
4545

4646
writeFile("loadModel.mos",sum("if loadModel(" + lib + ") then true else if loadModel(" + lib + ",languageStandard=\"2.x\") then true else loadModel(" + lib + ",languageStandard=\"1.x\");getErrorString();\n" for lib in getAvailableLibraries()));
4747
getErrorString();
@@ -61,6 +61,15 @@ if genMetaModelica then
6161
end if;
6262

6363
echo(false);
64+
self:=getInstallationDirectoryPath() + "/share/doc/omc/testmodels/GenerateDoc.mos";getErrorString();
65+
py:=getInstallationDirectoryPath() + "/share/doc/omc/testmodels/generate_icons.py";getErrorString();
66+
commands:={"python "+py+" --output-dir . "+typeNameString(cl) for cl in getClassNames()};getErrorString();
67+
res:=system_parallel(commands);getErrorString();
68+
system("rm -f *.json");getErrorString();
69+
if max(res) <> 0 then
70+
exit(1);
71+
end if;
72+
6473
allClassNames:=getClassNames(builtin=genBuiltin,recursive=true,sort=true);
6574
system("date -u +%FT%TZ > tmp");
6675
genTimeStamp := readFile("tmp");
@@ -98,8 +107,17 @@ function preSuffixIfNotEmpty
98107
output String out := if str <> \"\" then prefix + str + suffix else \"\";
99108
end preSuffixIfNotEmpty;
100109

110+
function svgIcon
111+
input String file;
112+
input String cssClass;
113+
output String tag;
114+
algorithm
115+
tag := if OpenModelica.Scripting.regularFileExists(file) then \"<img class=\\\"\"+cssClass+\"\\\" src=\\\"\"+ file +\"\\\" /> \" else \"\";
116+
end svgIcon;
117+
101118
function head
102119
input String strs[:];
120+
input String svgFile;
103121
output String head;
104122
protected
105123
String compound := \"\", file;
@@ -111,13 +129,13 @@ algorithm
111129
<title>\"+sum(s + \".\" for s in strs[1:end-1])+strs[end]+\"</title>
112130
</head>
113131
<body>
114-
<h1><a href = \\\"index.html\\\">.</a>\";
132+
<h1>\" + svgIcon(svgFile,\"svgiconhead\") + \"<a class=\\\"omc-h1-a\\\" href=\\\"index.html\\\">.</a>\";
115133
for ident in strs[1:end-1] loop
116134
compound := if compound == \"\" then ident else compound+\".\"+ident;
117135
file := filename(compound+\".html\");
118-
head := head + \"<a href = \\\"\"+file+\"\\\">\"+ident+\"</a>.\";
136+
head := head + \"<a class=\\\"omc-h1-a\\\" href = \\\"\"+file+\"\\\">\"+ident+\"</a>.\";
119137
end for;
120-
head := head + strs[end] + \"</h1>\";
138+
head := head + \"<span class=\\\"omc-h1\\\">\" + strs[end] + \"</span></h1>\";
121139
end head;
122140

123141
function itemString
@@ -161,11 +179,11 @@ end Item;
161179
echo(false);
162180
items:={Item(
163181
filename(OpenModelica.Scripting.typeNameString(c))+".html",
164-
head(OpenModelica.Scripting.typeNameStrings(c)),
182+
head(OpenModelica.Scripting.typeNameStrings(c),filename(OpenModelica.Scripting.typeNameString(c))+".svg"),
165183
OpenModelica.Scripting.getDocumentationAnnotation(c),
166184
preSuffixIfNotEmpty(
167185
"<h2>Contents</h2>\n<table><tr><th>Name</th><th>Description</th></tr>",
168-
sum("<tr><td><a href=\"" + filename(OpenModelica.Scripting.typeNameString(cl)) + ".html\">" +
186+
sum("<tr><td>"+ svgIcon(filename(OpenModelica.Scripting.typeNameString(cl)) + ".svg","svgiconsmall") +"<a href=\"" + filename(OpenModelica.Scripting.typeNameString(cl)) + ".html\">" +
169187
last(OpenModelica.Scripting.typeNameStrings(cl)) + "</a></td>" + "<td>" +
170188
toHtml(OpenModelica.Scripting.getClassComment(cl)) +
171189
"</td></tr>\n"
@@ -188,7 +206,7 @@ replaceCommands := "";
188206
filetmp := "index.html";
189207
writeFile(filetmp, "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /><title>Modelica Documentation</title><link href=\"style.css\" rel=\"stylesheet\" type=\"text/css\" /></head><body><h1>Modelica Documentation</h1>\n");
190208
writeFile(filetmp, "<p>This is a listing of builtin Modelica functions, miscellaneous Modelica libraries stored in a <a href=\"https://openmodelica.org/git/OpenModelicaLibraries.git\">git</a> repository. There is also documentation for OpenModelica-specific <a href=\"OpenModelica.Scripting.html\">scripting</a>.</p>\n", append = true);
191-
writeFile(filetmp, "<p>Note that not all libraries are supported or have been tested. Feel free to add bug reports either to <a href=\"https://trac.openmodelica.org/OpenModelica/newticket\">OpenModelica</a> (for compiler bugs) or to the <a href=\"https://github.com/modelica-3rdparty\">GitHub projects</a> for enhancements or bugs in the libraries. Older libraries may contain broken links and images (only libraries with modelica:// links produce good documentation). The Modelica Standard Library is best supported package in OpenModelica.</p>\n", append = true);
209+
writeFile(filetmp, "<p>Note that not all libraries are supported or have been tested. Feel free to add bug reports either to <a href=\"https://trac.openmodelica.org/OpenModelica/newticket\">OpenModelica</a> (for compiler bugs) or to the <a href=\"https://github.com/modelica-3rdparty\">GitHub projects</a> for enhancements or bugs in the libraries. Older libraries may contain broken links and images (only libraries with modelica:// links produce good documentation). The Modelica Standard Library is the best supported package in OpenModelica.</p>\n", append = true);
192210
writeFile(filetmp, "<h2>Libraries</h2>\n", append = true);
193211
writeFile(filetmp, "<table><tr><th>Name</th><th>Description</th><th>Version</th></tr>", append = true);
194212
for cl in classNames loop
@@ -306,15 +324,20 @@ done
306324
rm -f tmp
307325
");
308326

309-
writeFile("style.css","
310-
h1
327+
writeFile("style.css",".omc-h1
311328
{
312329
font-family: mono;
313330
font-size: x-large;
314331
color:rgb(153,0,0);
332+
vertical-align: middle;
315333
}
316334

317-
h1 a {font-size:large;}
335+
.omc-h1-a
336+
{
337+
font-family: mono;
338+
font-size: large;
339+
vertical-align: middle;
340+
}
318341

319342
table
320343
{
@@ -338,6 +361,19 @@ pre
338361
{
339362
white-space: pre-wrap; /* CSS 3 */
340363
}
364+
365+
.svgiconhead {
366+
height: 32px;
367+
width: 32px;
368+
vertical-align: top;
369+
-o-object-fit: contain;
370+
}
371+
.svgiconsmall {
372+
height: 20px;
373+
width: 20px;
374+
vertical-align: top;
375+
-o-object-fit: contain;
376+
}
341377
");
342378

343379
writeFile("FilterTidy.sh","#!/bin/bash
@@ -362,8 +398,9 @@ system("bash FilterTidy.sh");
362398
system("bash FindFiles.sh");
363399
system("rm -f ModelicaDocumentation.tar.xz");
364400
system("mkdir -p " + dirs);
401+
system("cp '" + py + "' '" + self + "' .");
365402
"tar";
366403
dirs;
367-
cmd := "tar cJf ModelicaDocumentation.tar.xz --dereference style.css *.html " + dirs + " GenerateDoc.mos FindFiles.log tidy.filtered tidy.links";
404+
cmd := "tar cJf ModelicaDocumentation.tar.xz --dereference style.css *.html " + dirs + " GenerateDoc.mos generate_icons.py FindFiles.log tidy.filtered tidy.links";
368405
system(cmd);
369406
getErrorString();

0 commit comments

Comments
 (0)