Repository: getnikola/nikola

Issue:
Submenus break on (stock) Jinja themes
Steps to show submenus work with mako themes:

`nikola init foo`
`cd foo`
`vim conf.py` and change:

``` py
NAVIGATION_LINKS = {
    DEFAULT_LANG: (
        ("/archive.html", "Archive"),
        ("/categories/index.html", "Tags"),
        ("/rss.xml", "RSS feed"),
        (
            (('http://www.example.org/', 'Example'), ),
            'Menu'
        )
    ),
}
```

`nikola build`

This should work just fine.

`nikola install_theme bootstrap3-jinja`
`vim conf.py` and change `THEME='bootstrap3-jinja'`
`nikola build`

this should give a nice little traceback:

``` pytb
Scanning posts....done!
... omitted copy_assets ...
.  render_indexes:output/index.html
########################################
TaskError - taskid:render_indexes:output/index.html
PythonAction Error
Traceback (most recent call last):
  File "/home/tritium/.virtualenvs/site/local/lib/python2.7/site-packages/doit/action.py", line 360, in execute
    returned_value = self.py_callable(*self.args, **kwargs)
  File "/home/tritium/.virtualenvs/site/local/lib/python2.7/site-packages/nikola/nikola.py", line 769, in render_template
    template_name, None, local_context)
  File "/home/tritium/.virtualenvs/site/local/lib/python2.7/site-packages/nikola/plugins/template/jinja.py", line 88, in render_template
    output = template.render(**context)
  File "/home/tritium/.virtualenvs/site/local/lib/python2.7/site-packages/jinja2/environment.py", line 969, in render
    return self.environment.handle_exception(exc_info, True)
  File "/home/tritium/.virtualenvs/site/local/lib/python2.7/site-packages/jinja2/environment.py", line 742, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/home/tritium/.virtualenvs/site/local/lib/python2.7/site-packages/nikola/data/themes/base-jinja/templates/index.tmpl", line 4, in top-level template code
    {% extends 'base.tmpl' %}
  File "themes/bootstrap3-jinja/templates/base.tmpl", line 36, in top-level template code
    {{ base.html_navigation_links() }}
  File "themes/bootstrap3-jinja/templates/base_helper.tmpl", line 129, in template
    {% if rel_link(permalink, url) == "#" %}
  File "/home/tritium/.virtualenvs/site/local/lib/python2.7/site-packages/nikola/nikola.py", line 1056, in rel_link
    dst = urljoin(src, dst)
  File "/usr/lib/python2.7/urlparse.py", line 253, in urljoin
    urlparse(url, bscheme, allow_fragments)
  File "/usr/lib/python2.7/urlparse.py", line 135, in urlparse
    tuple = urlsplit(url, scheme, allow_fragments)
  File "/usr/lib/python2.7/urlparse.py", line 174, in urlsplit
    i = url.find(':')
AttributeError: 'tuple' object has no attribute 'find'
```

I assume that the jinja version of the template does not even attempt to render submenus where the mako one does.



Discussion:
The Jinja versions are usually autogenerated from the Mako versions.  This needs investigating.

Here’s the deal:

```
--- mako ---
[2014-06-12T14:51:14Z] WARNING: Nikola: rel_link with /index.html and http://www.example.org/

--- jinja ---
[2014-06-12T14:51:31Z] WARNING: Nikola: rel_link with /galleries/index.html and ((u'http://www.example.org/', u'Example'),)
```

Fix should be out in a while.


Resolving patch:
diff --git a/nikola/plugins/template/jinja.py b/nikola/plugins/template/jinja.py
--- a/nikola/plugins/template/jinja.py
+++ b/nikola/plugins/template/jinja.py
@@ -55,6 +55,8 @@ def __init__(self):
         self.lookup.lstrip_blocks = True
         self.lookup.filters['tojson'] = json.dumps
         self.lookup.globals['enumerate'] = enumerate
+        self.lookup.globals['isinstance'] = isinstance
+        self.lookup.globals['tuple'] = tuple
 
     def set_directories(self, directories, cache_folder):
         """Create a template lookup."""
diff --git a/scripts/jinjify.py b/scripts/jinjify.py
--- a/scripts/jinjify.py
+++ b/scripts/jinjify.py
@@ -11,7 +11,6 @@
 import jinja2
 
 dumb_replacements = [
-    ["{% if isinstance(url, tuple) %}", "{% if url is mapping %}"],
     ["{% if any(post.is_mathjax for post in posts) %}", '{% if posts|selectattr("is_mathjax")|list %}'],
     ["json.dumps(title)", "title|tojson"],
     ["{{ parent.extra_head() }}", "{{ super() }}"],


Test patch: