-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ability to get breadcrumbs from menus #1
Merged
Merged
Changes from 3 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
navbuilder/templates/navbuilder/inclusion_tags/breadcrumbs.html
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{% load navbuilder_tags %} | ||
{% for crumb in navbuilder_breadcrumbs %} | ||
<a class="Crumb" href="{{ crumb.link.get_absolute_url }}" title="{{ crumb.link.title|default:crumb.title }}" target="{{ crumb.target|default:"" }}" data-slug="{{ crumb.link.slug|default:crumb.slug }}">{{ crumb.link.title|default:crumb.title }}</a> | ||
{% if not forloop.last %} > {% endif %} | ||
{% endfor %} |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
from django.core.urlresolvers import reverse | ||
from django.test import TestCase | ||
from django.test.client import Client | ||
|
||
from navbuilder import models | ||
from navbuilder.tests.test_base import load_fixtures, load_crumb_fixtures | ||
|
||
from django.template import Context, Template | ||
|
||
crumb_template_1 = Template( | ||
"{% load navbuilder_tags %}" | ||
"{% navbuilder_breadcrumbs 'menu-1' %}" | ||
) | ||
|
||
crumb_template_2 = Template( | ||
"{% load navbuilder_tags %}" | ||
"{% navbuilder_breadcrumbs 'menu-2' %}" | ||
) | ||
|
||
crumb_template_3 = Template( | ||
"{% load navbuilder_tags %}" | ||
"{% navbuilder_breadcrumbs 'menu-3' %}" | ||
) | ||
|
||
|
||
class BreadcrumbsTestCase(TestCase): | ||
def setUp(self): | ||
self.client = Client() | ||
load_fixtures(self) | ||
load_crumb_fixtures(self) | ||
# Reorganise the items | ||
self.menuitem.link = None | ||
self.sub_menuitem_2.link = self.link | ||
|
||
|
||
def test_single_level(self): | ||
# The link object maps to a single level in menu 2 | ||
out = crumb_template_2.render(Context({"object": self.link})) | ||
self.assertHTMLEqual(out, """ | ||
<a class="Crumb" href="/link/1/" title="Link 1" | ||
target="" data-slug="link-1"> | ||
Link 1 | ||
</a> | ||
""" | ||
) | ||
|
||
def test_multilevel(self): | ||
# The link object maps to the submenu in menu 1 | ||
out = crumb_template_1.render(Context({"object": self.link})) | ||
self.assertHTMLEqual(out, """ | ||
<a class="Crumb" href="/link/1/" | ||
title="Link 1" target="" data-slug="link-1"> | ||
Link 1 | ||
</a> | ||
> | ||
<a class="Crumb" data-slug="link-1" href="/link/1/" | ||
target="blank" title="Link 1"> | ||
Link 1 | ||
</a> | ||
""" | ||
) | ||
|
||
def test_menu_slug_not_found(self): | ||
# If we cannot identify the menu it comes from, take the first one. | ||
out = crumb_template_3.render(Context({"object": self.link})) | ||
self.assertIn("Link 1", out) | ||
|
||
def test_no_matching_menuitem(self): | ||
# If the object does not show up in any menu, render nothing | ||
self.menuitem_2.link = None | ||
out = crumb_template_3.render(Context({"object": self.link_2})) | ||
self.assertHTMLEqual("", out) | ||
|
||
def tearDown(self): | ||
pass |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indent please
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indented :)