Skip to content

Commit

Permalink
templating tests
Browse files Browse the repository at this point in the history
  • Loading branch information
situx committed Dec 5, 2023
1 parent 00a1122 commit 922381a
Show file tree
Hide file tree
Showing 22 changed files with 244 additions and 31 deletions.
13 changes: 0 additions & 13 deletions doc/docconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,6 @@ class DocConfig:

bibtextypemappings={"http://purl.org/ontology/bibo/Document":"@misc","http://purl.org/ontology/bibo/Article":"@article","http://purl.org/ontology/bibo/Thesis":"@phdthesis","http://purl.org/ontology/bibo/BookSection":"@inbook","http://purl.org/ontology/bibo/Book":"@book","http://purl.org/ontology/bibo/Proceedings":"@inproceedings"}

labelproperties={
"http://www.w3.org/2004/02/skos/core#prefLabel":"DatatypeProperty",
"http://www.w3.org/2004/02/skos/core#prefSymbol": "DatatypeProperty",
"http://www.w3.org/2004/02/skos/core#altLabel": "DatatypeProperty",
"https://schema.org/name": "DatatypeProperty",
"https://schema.org/alternateName": "DatatypeProperty",
"http://purl.org/dc/terms/title": "DatatypeProperty",
"http://purl.org/dc/elements/1.1/title":"DatatypeProperty",
"http://www.w3.org/2004/02/skos/core#altSymbol": "DatatypeProperty",
"http://www.w3.org/2004/02/skos/core#hiddenLabel": "DatatypeProperty",
"http://www.w3.org/2000/01/rdf-schema#label": "DatatypeProperty"
}

baselayers={
"OpenStreetMap (OSM)":{"url":"https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png","default":True,"type":"tile"}
}
Expand Down
36 changes: 30 additions & 6 deletions docgeneration.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,26 @@ def resolveTemplate(templatename):
else:
templates[file] = f.read()
elif os.path.exists(templatepath+"/"+templatename+"/templates/"):
for filename in os.listdir(templatepath+"/"+templatename+"/templates/"):
if filename.endswith(".html") or filename.endswith(".css"):
with open(templatepath+"/"+templatename+"/templates/"+filename, 'r') as f:
global stylesheet
templates[filename.replace(".html","")] = f.read()
if os.path.exists(templatepath+"/"+templatename+"/templates/layouts/") and os.path.exists(templatepath+"/"+templatename+"/templates/includes/"):
templates["includes"]={}
templates["layouts"] = {}
for filename in os.listdir(templatepath+"/"+templatename+"/templates/includes"):
if filename.endswith(".html") or filename.endswith(".css"):
with open(templatepath+"/"+templatename+"/templates/"+filename, 'r') as f:
content=f.read()
templates["includes"][filename.replace(".html","")] = content
templates[filename.replace(".html", "")] = content
for filename in os.listdir(templatepath + "/" + templatename + "/templates/layouts"):
if filename.endswith(".html") or filename.endswith(".css"):
with open(templatepath + "/" + templatename + "/templates/" + filename, 'r') as f:
content=f.read()
templates["layouts"][filename.replace(".html", "")] = content
templates[filename.replace(".html", "")] = content
else:
for filename in os.listdir(templatepath+"/"+templatename+"/templates/"):
if filename.endswith(".html") or filename.endswith(".css"):
with open(templatepath+"/"+templatename+"/templates/"+filename, 'r') as f:
templates[filename.replace(".html","")] = f.read()
return False
return True

Expand Down Expand Up @@ -156,6 +171,14 @@ def processLiteral(self,literal, literaltype, reproject,currentlayergeojson=None
print(traceback.format_exc())
return None

includepattern=p = re.compile("\{% include (.+) %\}")

def getIncludesInTemplate(self,template):
includes=re.findall(OntDocGeneration.includepattern, template)
for inc in includes:
print("INCLUDES: "+str(inc))


def createOfflineCompatibleVersion(self,outpath,myhtmltemplate,templatepath,templatename):
if not os.path.isdir(outpath):
os.mkdir(outpath)
Expand Down Expand Up @@ -309,7 +332,6 @@ def generateOntDocForNameSpace(self, prefixnamespace,dataformat="HTML"):
with open(outpath + "epsgdefs.js", 'w', encoding='utf-8') as f:
f.write(templates["epsgdefs"])
f.close()
pathmap = {}
paths = {}
nonnsmap={}
postprocessing=Graph()
Expand Down Expand Up @@ -424,6 +446,8 @@ def generateOntDocForNameSpace(self, prefixnamespace,dataformat="HTML"):
f.write(indexhtml)
f.close()
sparqlhtml = self.replaceStandardVariables(templates["htmltemplate"], "", "0","false")
if "layouts" in templates:
self.getIncludesInTemplate(sparqlhtml)
sparqlhtml = sparqlhtml.replace("{{iconprefixx}}",("icons/" if self.offlinecompat else "")).replace("{{baseurl}}", prefixnamespace).replace("{{relativedepth}}","0").replace("{{relativepath}}",".").replace("{{toptitle}}","SPARQL Query Editor").replace("{{title}}","SPARQL Query Editor").replace("{{startscriptpath}}", "startscripts.js").replace("{{stylepath}}", "style.css")\
.replace("{{classtreefolderpath}}",corpusid + "_classtree.js").replace("{{baseurlhtml}}", "").replace("{{nonnslink}}","").replace("{{scriptfolderpath}}", corpusid + "_search.js").replace("{{exports}}",templates["nongeoexports"]).replace("{{versionurl}}",DocConfig.versionurl).replace("{{version}}",DocConfig.version).replace("{{bibtex}}","").replace("{{proprelationpath}}","proprelations.js")
sparqlhtml+=templates["sparqltemplate"]
Expand Down
Empty file.
Empty file.
12 changes: 12 additions & 0 deletions resources/html/default/templates/includes/head.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<html about="{{subject}}"><head><title>{{toptitle}}</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.12.1/css/jquery.dataTables.min.css" />
<link rel="stylesheet" type="text/css" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" />
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.1.1/themes/default/style.min.css" />
<link rel="stylesheet" type="text/css" href="{{stylepath}}" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script><script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script><script src="https://cdn.datatables.net/1.12.1/js/jquery.dataTables.min.js"></script>
<script src="{{scriptfolderpath}}"></script><script src="{{classtreefolderpath}}"></script><script src="{{proprelationpath}}"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.3.14/jstree.min.js"></script><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/rdflib.min.js"></script>
<script type="text/javascript" src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.bundle.min.js"></script>
<script src="{{startscriptpath}}"></script></head>
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
<html about="{{subject}}"><head><title>{{toptitle}}</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.12.1/css/jquery.dataTables.min.css" />
<link rel="stylesheet" type="text/css" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" />
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.1.1/themes/default/style.min.css" />
<link rel="stylesheet" type="text/css" href="{{stylepath}}" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script><script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script><script src="https://cdn.datatables.net/1.12.1/js/jquery.dataTables.min.js"></script>
<script src="{{scriptfolderpath}}"></script><script src="{{classtreefolderpath}}"></script><script src="{{proprelationpath}}"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.3.14/jstree.min.js"></script><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/rdflib.min.js"></script>
<script type="text/javascript" src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.bundle.min.js"></script>
<script src="{{startscriptpath}}"></script></head><div id="mySidenav" class="sidenav" style="overflow:auto;"><a href="javascript:void(0)" class="closebtn" onclick="closeNav()">&times;</a>
<div id="mySidenav" class="sidenav" style="overflow:auto;"><a href="javascript:void(0)" class="closebtn" onclick="closeNav()">&times;</a>
GeoClasses: <input type="checkbox" id="geoclasses"/><br/>
Search:<input type="text" id="classsearch"><br/><div id="jstree"></div>
</div><script>var indexpage={{indexpage}}; var baseurl="{{baseurl}}"; var iconprefixx="{{iconprefixx}}";
Expand Down
Loading

0 comments on commit 922381a

Please sign in to comment.