startling / cytoplasm

A static site generator written in python.
MIT License
13 stars 0 forks source link

bombing with mako template inheritance #4

Open pjv opened 12 years ago

pjv commented 12 years ago

in trying to get started with cytoplasm i'm running into an issue early on. following the instructions in the tutorial, the initial set up and test posts worked fine. then i tried to move the templates from inside the blog controller to a _templates directory in the root of the site and create a simple "site.mako" template to be inherited by post.mako and chronological.mako.

i changed _config.py to point at the root _templates directory:

...
controllers = [
    # you can optionally specify where the templates are; here, use the controller's defaults.
    ("blog", ["_posts", "_build", "_templates"]),
]

i put this line at the top of post and chronological:

<%inherit file="/_templates/site.mako" />

site.mako looks like this:

<!DOCTYPE html>
<html>
<head>
    <title>cyto site sighting</title>
</head>
<body>
    ${self.body()}
</body>
</html>

then when i try to build or serve -r, it pukes ending with:

File "/Volumes/hd/Users/paul/development/virtualenvs/cyto/lib/python2.7/site-packages/mako/runtime.py", line 704, in _exec_template
    callable_(context, *args, **kwargs)
  File "__templates_site_mako", line 22, in render_body
TypeError: render_body() takes at least 2 arguments (1 given)

here is the entire traceback: http://pastebin.com/5NyHWuYY

pjv commented 12 years ago

i should add that the issue above was seen after doing a cytoplasm init bare and following along with the rest of the tutorial.

i subsequently tried cytoplasm-site and it works fine, including the mako template inheritance, and i cannot see any functional difference in the templates, the config, or anything else that seems like it should matter.

startling commented 12 years ago

Yeah that's weird. Want to gist your post and chronological templates?

pjv commented 12 years ago

they are box-stock with just the inherit line added.

pastebin: http://pastebin.com/fUi4tuAt

startling commented 12 years ago

Oh wow, it looks like the problem is that declaring arguments for a template breaks mako's inheritance. self.body needs to have been given all of the arguments that are declared -- but they aren't given, because they already exist in the namespace of the inherited template. Weird.

I'm not sure what to do with this other than to take the argument declarations (the lines that look like <%page args="posts, previous=None, next=None"/>) out. I'll do that now for the default templates. It's an ugly workaround; I'll leave this open until we figure out something better to do.

Thanks for catching this! I'm surprised no one else has.

startling commented 12 years ago

Worked around with this commit in the blog-controller repository.

pjv commented 12 years ago

i'm completely new to mako and find the docs there a little opaque, so excuse my ignorance, but is this a mako issue or a cytoplasm issue? in other words, are you saying that page arguments break mako inheritance in any context (hard to believe), or specifically in the way that cytoplasm is using mako to render templates?

startling commented 12 years ago

Adding arguments breaks mako's inheritance in the way that cytoplasm is using it. I doubt it's a mako issue; I bet there's some actual way to make it work.