From 8f119c3828c539e55a19bb5a24feb381b19d3f96 Mon Sep 17 00:00:00 2001 From: wasw100 Date: Sun, 24 Apr 2016 03:08:12 +0800 Subject: [PATCH] Link object can set attributes --- example/__init__.py | 3 ++- flask_nav/elements.py | 3 ++- flask_nav/renderers.py | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/example/__init__.py b/example/__init__.py index f7a1aa0..1a51567 100644 --- a/example/__init__.py +++ b/example/__init__.py @@ -17,7 +17,8 @@ Text('Discontinued Products'), View('Wg10X', 'products', product='wg10x'), ), - Link('Tech Support', 'http://techsupport.invalid/widgits_inc'), + Link('Tech Support', 'http://techsupport.invalid/widgits_inc', + target='_blank'), )) diff --git a/flask_nav/elements.py b/flask_nav/elements.py index dd1ad59..57432af 100644 --- a/flask_nav/elements.py +++ b/flask_nav/elements.py @@ -27,9 +27,10 @@ def render(self, renderer=None, **kwargs): class Link(NavigationItem): """An item that contains a link to a destination and a title.""" - def __init__(self, text, dest): + def __init__(self, text, dest, **attribs): self.text = text self.dest = dest + self.attribs = attribs def get_url(self): return self.dest diff --git a/flask_nav/renderers.py b/flask_nav/renderers.py index 39e3a1f..6b47a41 100644 --- a/flask_nav/renderers.py +++ b/flask_nav/renderers.py @@ -40,7 +40,7 @@ def __init__(self, **kwargs): self.kwargs = kwargs def visit_Link(self, node): - return tags.a(node.text, href=node.get_url()) + return tags.a(node.text, href=node.get_url(), **node.attribs) def visit_Navbar(self, node): kwargs = {'_class': 'navbar'}