billiges Templatesystem geschrieben

This commit is contained in:
age 2006-07-22 01:51:35 +00:00
parent 8a347b655e
commit 55e4a8f5cb
22 changed files with 317 additions and 0 deletions

45
tmpl2html/README Normal file
View File

@ -0,0 +1,45 @@
!Warnung: dieses Pythonscript ist ein ein riesen Haufen Stinkescheisse!
Ich hab mir damit nur laestige Schreibarbeit fuer die Erstellung einer
Webseite gespart. Ich wollte schon immer mal ein eigenes
Templatesystem schreiben 8]
Die Funktionsweise ist recht einfach und schnell eingaenglich anhand
eines Beispiels: (Das Beispiel laeuft nur, wenn es keine Verzeichnisse ausser den
erwaehnten gibt. Verzeichnisse wie ".svn" wirken z.B. aeusserst stoerend.)
* in "gerippe.tmpl" kommen Platzhalter z.B. "<!-- $foo$ -->"
* ins Verz. "placeholder" kommen Dateien mit gleichem Namen "foo", wie der Platzhalter
* der Inhalt der Datei "foo" wird spaeter den gleichnamigen Platzhalter ersetzen
* diese Ersetzungen finden fuer alle html Dateien statt, eignen sich also nur fuer Inhalte, die in jeder .html gleich sind
* ins Verz. "content" kommt jeweils ein Unterverzeichnis z.B. "bar"
* daraus wird spaeter "bar.html"
* Grundlage fuer "bar.html" bilden gerippe.tmpl + placeholder
* im Verz. "bar" werden Dateien abgelegt, die nach Nummern benannt werden
* diese Dateien bilden spaeter einen Eintrag, im Content der jeweiligen html Datei
* die Nummerierung legt die Reihenfolge innerhalb der html Datei fest (1 ist der erste Eintrag)
*
|_ gerippe.tmpl
|
|_ placeholder +
| |_ header
| |_ footer
| |_ immergleicherkrempel
|
|_ content +
|_ index +
| |_ 1
| |_ 2
|
|_ kontakt +
| |_ 1
|
|_ misc +
|_ 1
|_ 2
|_ 3

View File

@ -0,0 +1,6 @@
<div class="entry">
<h2>Der erste Starteintrag</h2>
<p>
Dies ist kein Blog!
</p>
</div>

View File

@ -0,0 +1,6 @@
<div class="entry">
<h2>Nummer Zwo</h2>
<p>
ist aber aehnlich aufgebaut
</p>
</div

View File

@ -0,0 +1,6 @@
<div class="entry">
<h2>Kontakt</h2>
<p>
ruf mich an
</p>
</div>

View File

@ -0,0 +1,6 @@
<div class="entry">
<h2>blafasel</h2>
<p>
Haelt mich denn niemand vom Schreiben ab?
</p>
</div>

View File

@ -0,0 +1,7 @@
<!-- $preheader$ -->
<!-- $header$ -->
<div id="content">
<!-- $entries$ -->
</div>
<!-- $rightbar$ -->
<!-- $footer$ -->

View File

@ -0,0 +1,9 @@
<div id="footer">
Designentwurf <a href="http://www.drugo.biz">Carlo Forghieri</a>
</div>
</div>
</div>
</body>
</html>

View File

@ -0,0 +1,11 @@
<div id="head">
<ul class="navbar">
<li><a href="index.html">Projekt</a></li>
<li><a href="motivation.html">Motivation</a></li>
<li><a href="orga.html">Organisatorisches</a></li>
<li><a href="kontakt.html">Kontakt</a></li>
</ul>
<h1 class="title">Schachtspringer</h1>
</div>

View File

@ -0,0 +1,12 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Schachtspringer</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<link href="style/metro01.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="wrap">
<div id="wrap_top"></div>
<div id="main">

View File

@ -0,0 +1,5 @@
<div id="rightbar">
<img src="style/aph2.jpg">
</div>

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 203 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 177 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 206 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 133 B

View File

@ -0,0 +1,140 @@
body{
/*font: 70%/1.4em Verdana, Arial, Helvetica, sans-serif;*/
font: 90% Verdana, Arial, Helvetica, sans-serif;
color: #666;
background: #fff url('body_bg3.png') repeat-x;
}
a:link, a:visited, a:active {
font-weight:bold;
color: #555;
text-decoration:none;
}
a:hover, a:visited:hover {
font-weight:bold;
color:#2a56d6;
text-decoration:underline;
}
#wrap{
width:760px;
margin:0 auto;
}
#wrap_top{
background: url('tab_top_bg.gif') top center no-repeat;
height:5px;
}
#main{
background:#fff;
margin:0;
overflow:hidden;
}
#head{
margin:0;
padding: 5px 5px 17px 5px;
background: url('title2.jpg') no-repeat;
background-position: 50% 100%;
height:145px;
}
#head .navbar{
padding:0;
margin:0;
}
#head .navbar li{
display:inline;
}
#head .navbar li a{
padding: 0 15px ;
font-weight:bold;
font-size: 13px;
color:#666666;
}
#head .navbar li a:hover,#head .navbar li a:active {
text-decoration:underline;
color:#2a56d6;
}
#head h1.title{
color:#fff;
font-size: 18px;
text-align:right;
text-transform:uppercase;
margin:0;
padding: 115px 10px 0 0;
}
#content{
margin: 5px 0 0 0;
width: 580px;
padding: 0 20px 20px 20px;
float:left;
/*
background: url('content_sep.png') repeat-y;
*/
background-position: 98.5% 0;
}
#content .entry{
/*
border-bottom: #ddd 1px solid;
*/
text-align:justify;
}
#content .entry p{
margin: 0.2em 0 1.2em 0;
}
#content .entry h2{
border-bottom:2px solid #F0F0F0;
margin:25px 0 10px 0;
padding:0;
color:#557ef5;
}
#content .entry .links{
margin:-8px 0 2px 0;
text-align:right;
letter-spacing:1px;
font-size: 8px;
color:#666;
}
#rightbar{
width: 130px;
padding: 10px 10px 5px 0;
float:left;
text-align:right;
}
#rightbar .box{
margin: 5px 0 20px 0;
}
#rightbar .box h2{
margin:0 0 2px 0;
padding: 0;
font-size: 11px;
letter-spacing:1px;
font-variant: small-caps;
border-bottom: #666 1px solid;
color:#557ef5;
}
#rightbar .box ul{
margin:0;
padding:0;
list-style:none;
}
#rightbar .box li{
font-size: 12px;
padding: 2px 0;
}
#rightbar #desc.box{
background:#eee;
padding:10px;
}
#footer{
clear:both;
text-align:right;
background: #ddd;
padding: 10px;
font-size:8px;
color:#333;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 112 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

64
tmpl2html/templatewriter.py Executable file
View File

@ -0,0 +1,64 @@
#!/usr/bin/env python
import string, os
class TemplateWriter:
templatefile = "gerippe.tmpl"
tmpldir = "./placeholder"
contentdir = "./content"
tmplfileext = ".tmpl"
outfileext = ".html"
def __init__(self):
pass
def string_replace(self, infile, outfile):
template = open(infile).read()
open(outfile,"w").write(template)
text = {}
for tmpl in os.listdir(self.tmpldir):
tmplfile = str(self.tmpldir+"/"+tmpl)
if not os.path.isfile(tmplfile):
print " str.repl: cancelling "+tmplfile+" - not a file"
else:
template = open(outfile).read()
print " str.repl: using "+tmplfile
newcontent = open(tmplfile).read()
text[tmpl] = string.replace(template,"<!-- $"+tmpl+"$ -->",newcontent)
open(outfile,"w").write(text[tmpl])
return
def build_sites(self):
'''use all files ending with .tmpl'''
for tmplfile in os.listdir("./"):
if tmplfile.rfind(self.tmplfileext) >= 1:
infile = tmplfile
(tmplfilename, tmplfileext)=os.path.splitext(tmplfile)
outfile = tmplfilename + self.outfileext
print "building: "+tmplfile+" -> "+outfile
self.string_replace(infile, outfile)
return
def build_sites_from_gerippe(self):
print "Let's build some html files from: "+self.templatefile
for html in os.listdir(self.contentdir):
print " building: "+html+self.outfileext
entries = ""
for entry in os.listdir(self.contentdir+"/"+html):
print " adding entry: "+entry
entries += open(self.contentdir+"/"+html+"/"+entry).read()
template = open(self.templatefile).read()
text = string.replace(template,"<!-- $entries$ -->",entries)
infile = html+".tmp"
open(infile,"w").write(text)
outfile = html+self.outfileext
self.string_replace(infile, outfile)
return
if __name__ == "__main__":
foo = TemplateWriter()
foo.build_sites_from_gerippe()
#foo.string_replace("gerippe.tmpl", "gerippe.html) # for single tests
#foo.build_sites() # oldfashiond version