Skip to content

Commit

Permalink
Hash the paths of the generated icons to dedup them
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@17968 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Nov 2, 2013
1 parent 3de1824 commit 2b53879
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
21 changes: 16 additions & 5 deletions Examples/GenerateDoc.mos
Expand Up @@ -49,6 +49,8 @@ runScript("loadModel.mos");
getErrorString();
getClassNames();

// should we keep readable names (nice online), or use the hashed names in the links (nice if you want a zipped version to work on Windows)
readSymlinks := false;
// should we generate documentation for OM built-in functions?
genBuiltin := true;
// should we generate MetaModelica documentation?
Expand Down Expand Up @@ -111,14 +113,23 @@ function svgIcon
input String file;
input String link;
input String cssClass;
input Boolean readSymlinks;
output String tag;
protected
String hashedName;
algorithm
tag := if OpenModelica.Scripting.regularFileExists(file) then \"<a href=\\\"\" + link + \"\\\"><img class=\\\"\"+cssClass+\"\\\" src=\\\"\"+ file +\"\\\" /></a> \" else \"\";
if OpenModelica.Scripting.regularFileExists(file) then
hashedName := if readSymlinks then OpenModelica.Scripting.dirname(file) + \"/\" + OpenModelica.Scripting.basename(OpenModelica.Scripting.realpath(file)) else file;
tag := \"<a href=\\\"\" + (if link == file then hashedName else link) + \"\\\"><img class=\\\"\"+cssClass+\"\\\" src=\\\"\"+ hashedName +\"\\\" /></a> \";
else
tag := \"\";
end if;
end svgIcon;

function head
input String strs[:];
input String svgFile;
input Boolean readSymlinks;
output String head;
protected
String compound := \"\", file;
Expand All @@ -130,7 +141,7 @@ algorithm
<title>\"+sum(s + \".\" for s in strs[1:end-1])+strs[end]+\"</title>
</head>
<body>
<h1>\" + svgIcon(\"Icons/\" + svgFile,\"Icons/\" + svgFile,\"svgiconhead\") + \"<a class=\\\"omc-h1-a\\\" href=\\\"index.html\\\">.</a>\";
<h1>\" + svgIcon(\"Icons/\" + svgFile,\"Icons/\" + svgFile,\"svgiconhead\",readSymlinks=readSymlinks) + \"<a class=\\\"omc-h1-a\\\" href=\\\"index.html\\\">.</a>\";
for ident in strs[1:end-1] loop
compound := if compound == \"\" then ident else compound+\".\"+ident;
file := filename(compound+\".html\");
Expand Down Expand Up @@ -180,11 +191,11 @@ end Item;
echo(false);
items:={Item(
filename(OpenModelica.Scripting.typeNameString(c))+".html",
head(OpenModelica.Scripting.typeNameStrings(c),filename(OpenModelica.Scripting.typeNameString(c))+".svg"),
head(OpenModelica.Scripting.typeNameStrings(c),filename(OpenModelica.Scripting.typeNameString(c))+".svg",readSymlinks=readSymlinks),
OpenModelica.Scripting.getDocumentationAnnotation(c),
preSuffixIfNotEmpty(
"<h2>Contents</h2>\n<table><tr><th>Name</th><th>Description</th></tr>",
sum("<tr><td>"+ svgIcon("Icons/" + filename(OpenModelica.Scripting.typeNameString(cl)) + ".svg",filename(OpenModelica.Scripting.typeNameString(cl)) + ".html","svgiconsmall") +"<a href=\"" + filename(OpenModelica.Scripting.typeNameString(cl)) + ".html\">" +
sum("<tr><td>"+ svgIcon("Icons/" + filename(OpenModelica.Scripting.typeNameString(cl)) + ".svg",filename(OpenModelica.Scripting.typeNameString(cl)) + ".html","svgiconsmall",readSymlinks=readSymlinks) +"<a href=\"" + filename(OpenModelica.Scripting.typeNameString(cl)) + ".html\">" +
last(OpenModelica.Scripting.typeNameStrings(cl)) + "</a></td>" + "<td>" +
toHtml(OpenModelica.Scripting.getClassComment(cl)) +
"</td></tr>\n"
Expand Down Expand Up @@ -225,7 +236,7 @@ for cl in classNames loop
end if;
comment := OpenModelica.Scripting.stringReplace(getClassComment(cl),"&","&amp;"); // let's escape "&" on the fly
fileName := filename(contentStr);
writeFile(filetmp, "<tr><td>" + svgIcon("Icons/" + fileName + ".svg",fileName + ".html","svgiconsmall") + "<a href=\"" + fileName + ".html\">" + contentStr + "</a></td><td>" + comment + "</td><td>" + modelVersion + "</td></tr>", append = true);
writeFile(filetmp, "<tr><td>" + svgIcon("Icons/" + fileName + ".svg",fileName + ".html","svgiconsmall",readSymlinks=readSymlinks) + "<a href=\"" + fileName + ".html\">" + contentStr + "</a></td><td>" + comment + "</td><td>" + modelVersion + "</td></tr>", append = true);
end if;
end for;
writeFile(filetmp, "</table>\n", append = true);
Expand Down
10 changes: 8 additions & 2 deletions Examples/generate_icons.py
Expand Up @@ -36,6 +36,7 @@
import logging
import sys
import time
import hashlib
from optparse import OptionParser

import svgwrite
Expand Down Expand Up @@ -1035,7 +1036,8 @@ def generateSvg(filename, iconGraphics):
height = maxY - minY

dwg = svgwrite.Drawing(filename, size=(width, height), viewBox="0 0 " + str(width) + " " + str(height))
dwg.add(svgwrite.base.Desc(iconGraphics[-1]['className']))
# Makes hashing not work
# dwg.add(svgwrite.base.Desc(iconGraphics[-1]['className']))

for iconGraphic in iconGraphics:
for graphics in iconGraphic['graphics']:
Expand All @@ -1062,7 +1064,11 @@ def generateSvg(filename, iconGraphics):
group.add(port_info)

dwg.add(group)
dwg.save()
hashName = hashlib.sha1(dwg.tostring()).hexdigest() + ".svg"
hashPath = os.path.join(os.path.dirname(filename),hashName)
if not os.path.exists(hashPath):
dwg.saveas(hashPath)
os.symlink(hashName, filename)

return dwg

Expand Down

0 comments on commit 2b53879

Please sign in to comment.