Created
November 3, 2013 10:46
-
-
Save podhmo/7288912 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%inherit file="./layout.mako"/> | |
<%! from datetime import datetime %> | |
<%def name="title()"> | |
<% color = "#222244" if datetime.now().hour > 19 else "#444477" %> | |
<span style="color:${color}">title</span> | |
</%def> | |
<%def name="messagebox(id)"> | |
<div class="messsage-box" id="${id}"}> | |
${caller.body()} | |
</div> | |
</%def> | |
<div class="box" style="padding-left:30px; padding-right:30px;"> | |
<%include file="./env.template.mako" args="env=self"/> | |
</div> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%page args="env"/> | |
<h1>${env.title()}</h1> | |
<%env:messagebox id="box_1"> | |
this is template page | |
</%env:messagebox> | |
<ul> | |
<li>one</li> | |
<li>two</li> | |
<li>three</li> | |
</ul> | |
<%env:messagebox id="box_2"> | |
this is template page | |
</%env:messagebox> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- start of header @layout --> | |
<div class="header"> | |
header | |
</div> | |
<!-- end of header @layout --> | |
${next.body()} | |
<!-- start of footer @layout --> | |
<div class="footer"> | |
footer | |
</div> | |
<!-- end of footer @layout --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding:utf-8 -*- | |
""" | |
file structure:: | |
. | |
|-- sample_caller2.py | |
`-- templates | |
`-- caller2 | |
|-- env.base.mako | |
|-- env.template.mako | |
`-- layout.mako | |
""" | |
import contextlib | |
@contextlib.contextmanager | |
def section(message): | |
print("## {}".format(message)) | |
print("```html") | |
yield | |
print("```") | |
from mako.lookup import TemplateLookup | |
lookup = TemplateLookup(directories=["./templates/caller2"]) | |
with section("env template -> base template"): | |
result = (lookup.get_template("env.base.mako").render()) | |
## cleanup | |
import re | |
empty_lines_rx = re.compile("\n{2,}", re.MULTILINE) | |
print(empty_lines_rx.sub("\n", result)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
env template -> base template