Commit 6851060b authored by Matthieu Gautier's avatar Matthieu Gautier
Browse files

Les pages peuvent avoir des templates de css.

Les templates de css peuvent accéder à la page durant leur génération.
parent 5003e2e3
#menu {
background: {{page["color1"]}};
}
h1 {
background: {{page["color1"]}};
}
......@@ -23,8 +23,8 @@
<!--%
mpages = [p for p in pages if "menu-position" in p]
mpages.sort(key=lambda p: int(p["menu-position"]))
entry = '''<div class="%(index-style)s %(display-style)s index-entry">
<div class="content">
entry = '''<div class="%(index-style)s %(id)s index-entry">
<div class="content" style="background:%(color1)s">
<a href="%(url)s">%(title)s</a>
</div></div>'''
for p in mpages:
......
......@@ -2,7 +2,6 @@
margin-left: -250px; /* "#menu" width */
width: 250px;
position: fixed;
background: #294172;
color: white;
height: 100%;
top: 0;
......@@ -21,6 +20,11 @@
color: white;
}
#menu .pure-menu-selected .content {
background: white !important;
color: #3c6eb4;
}
/* -- Responsive Styles (Media Queries) ------------------------------------- */
/*
......
menu-position: 3
title: Parlons XMPP - épisode 6 - les commandes à distance
display-style: xmpp
id: xmpp
css-template: article.css
color1: #a07cbc
index-style: pure-u-1 pure-u-md-1-3
authors: Goffi
date: 2015-07-27T12:31:53+02:00
......
menu-position: 3
title: Présentation d'idée : PGPID
display-style: pgpid
id: pgpid
css-template: article.css
color1: #3c6eb4
index-style: pure-u-1 pure-u-md-1-3
authors: GaMa
date: 2013-07-23T00:59:56+02:00
......
menu-position: 4
title: Red Hat Enterprise Linux 6.7
display-style: redhat
id: redhat
css-template: article.css
color1: #79db32
index-style: pure-u-1 pure-u-md-1-3
authors: Nils Ratusznik
Yvan Munoz, BAud, palm123, Nÿco, patrick_g, eggman, Stéphane Aulery et Benoît Sibaud
......
menu-position: 1
title: Sortie de Fedora 22
display-style: fedora_22
id: fedora_22
css-template: article.css
color1: #db3279
index-style: pure-u-1 pure-u-md-2-3
authors: M5oul
Stéphane Aulery, eggman, BAud, palm123, Renault, Sébastien Wilmet, Nils Ratusznik, CheckMatt, Benoît Sibaud, Julien.D, Jiehong et Atem18
......
menu-position: 2
title: Sortie du noyau Linux 4.1
display-style: linux_41
id: linux_41
css-template: article.css
color1: #e59728
index-style: pure-u-1 pure-u-md-1-3
authors: Martin Peres
eggman, Davy Defaud, Siosm, BAud, palm123, M5oul, alpha_one_x86, Stéphane Aulery, Mali, tiwaz, Romain Perier, xaccrocheur, Olivier Esver, Xavier Claude, Benoît Sibaud, jcr83, pums974, ʭ ☯ , Nÿco, mimaison, Ytterbium, Segfault, Kioob, Vincent Meurisse, titinux, EdB et Jiehong
......
......@@ -24,18 +24,3 @@
color: white;
}
.fedora_22 .content {
background: #db3279 !important;
}
.linux_41 .content {
background: #e59728 !important;
}
.xmpp .content {
background: #a07cbc !important;
}
.redhat .content {
background: #79db32 !important;
}
import os
MKD_PATT = r'\.(?:css)$'
class CSSPage(dict):
"""Virtual CSS page to let poole generate the custom css page"""
def __init__(self, fname, original_page):
super(CSSPage, self).__init__()
self.update(original_page)
del self["menu-position"]
fname = os.path.join(project, fname)
self["template"] = fname
self["output"] = fname[:-4] + self['id'] + fname[-4:]
#import pdb; pdb.set_trace()
self["url"] = self["output"][len(project):].lstrip(os.path.sep)
self["url"] = self["url"].replace(os.path.sep, "/")
self["output"] = self["output"].replace(project, output)
with open(os.path.join(project,fname), 'r', encoding="utf8") as fp:
self.raw = fp.readlines()
self.html = ""
original_page["css-url"] = self["url"]
def __getattr__(self, name):
"""Attribute-style access to dictionary items."""
try:
return self[name]
except KeyError:
raise AttributeError(name)
def hook_postconvert_make_css():
"""Create virtual page than will generate css"""
new_pages = []
for p in pages:
if 'css-url' not in p:
p['css-url'] = 'article.css'
if 'css-template' in p:
new_pages.append(CSSPage(p['css-template'], p))
pages.extend(new_pages)
......@@ -15,6 +15,10 @@
<!--<![endif]-->
<link rel="stylesheet" href="style.css" />
<link rel="stylesheet" href="menu.css" />
<!--%
if 'css-url' in page:
print('<link rel="stylesheet" href="/%s" />'%page['css-url'])
%-->
</head>
<body>
<div id="layout">
......@@ -27,8 +31,8 @@
<!--%
mpages = [p for p in pages if "menu-position" in p]
mpages.sort(key=lambda p: int(p["menu-position"]))
entry = '''<li class="pure-menu-item %(style)s %(display-style)s">
<div class="content">
entry = '''<li class="pure-menu-item %(style)s %(id)s">
<div class="content" style="background:%(color1)s">
<a href="%(url)s">%(title)s</a>
</div></li>'''
for p in mpages:
......
......@@ -348,6 +348,7 @@ class Page(dict):
_template = None # template dictionary
_opts = None # command line options
_pstrip = None # path prefix to strip from (non-virtual) page file names
_outdir = None
_re_eom = re.compile(r'^---+ *\r?\n?$')
_re_vardef = re.compile(r'^([^\n:=]+?)[:=]((?:.|\n )*)', re.MULTILINE)
......@@ -379,6 +380,9 @@ class Page(dict):
self["fname"] = fname
self["output"] = fname.replace(self._pstrip, self._outdir)
self["output"] = re.sub(MKD_PATT, ".html", self["output"])
self["url"] = re.sub(MKD_PATT, ".html", fname)
self["url"] = self["url"][len(self._pstrip):].lstrip(os.path.sep)
self["url"] = self["url"].replace(os.path.sep, "/")
......@@ -538,6 +542,7 @@ def build(project, opts):
Page._template = macros.get("page", {})
Page._opts = opts
Page._pstrip = dir_in
Page._outdir = dir_out
pages = []
custom_converter = macros.get('converter', {})
......@@ -643,10 +648,8 @@ def build(project, opts):
#out = regx_rurl.sub(repl_rurl, out)
# write HTML page
fname = page.fname.replace(dir_in, dir_out)
fname = re.sub(MKD_PATT, ".html", fname)
if not opts.dry_run:
with open(fname, 'w', encoding=UTF8) as fp:
with open(page["output"], 'w', encoding=UTF8) as fp:
fp.write(out)
if opts.dry_run:
......@@ -726,6 +729,7 @@ def options():
op.exit()
opts.project = args and args[0] or "."
opts.project = os.path.abspath(opts.project)
return opts
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment