-
Notifications
You must be signed in to change notification settings - Fork 4
FIX: Adds register method #5
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
|
|
||
| from django import template | ||
| from django.utils.html import format_html | ||
| from xml.dom import minidom | ||
|
|
||
| from . import OCTICON_DATA | ||
|
|
||
|
|
@@ -102,6 +103,26 @@ def _calculate_height(self, width): | |
| return int((int(width) * self.height) / self.width) | ||
|
|
||
|
|
||
| # Register method for a new icon. | ||
| @classmethod | ||
| def register(cls, symbol, svg_file): | ||
| doc = minidom.parse(svg_file) | ||
| path_strings = [path.getAttribute('d') for path | ||
| in doc.getElementsByTagName('path')] | ||
| path = '<path fill-rule="evenodd" d="'+path_strings[0]+'"'+"/>" | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add comments for all these magic literals. |
||
|
|
||
| values = { | ||
| 'name': symbol, | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indent the key-value pairs one level. |
||
| 'keywords': [symbol], | ||
| 'width': 24, | ||
| 'height': 24, | ||
| 'path': path | ||
| } | ||
|
|
||
| OCTICON_DATA.update({symbol:values}) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function should return |
||
| doc.unlink() | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this needed? Please add a comment. |
||
|
|
||
|
|
||
| @register.simple_tag | ||
| def octicon(symbol, **options): | ||
| icon = Octicon(symbol, **options) | ||
|
|
||
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.
Add a docstring for this method, which should explain what this method does and how it should be used. This is important since it's a public method.