pax_global_header 0000666 0000000 0000000 00000000064 14741166115 0014520 g ustar 00root root 0000000 0000000 52 comment=f38b1d2c90b30bfbbff97689d8d111a9ec5d7352
django-iconify-0.4.1/ 0000775 0000000 0000000 00000000000 14741166115 0014422 5 ustar 00root root 0000000 0000000 django-iconify-0.4.1/.gitignore 0000664 0000000 0000000 00000001004 14741166115 0016405 0 ustar 00root root 0000000 0000000 # Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
# pyenv
.python-version
# Environments
.env
.venv
env/
venv/
ENV/
# Editors
*~
DEADJOE
\#*#
# Database
db.sqlite3
node_modules/
package.json
yarn.lock
django-iconify-0.4.1/LICENSE 0000664 0000000 0000000 00000026124 14741166115 0015434 0 ustar 00root root 0000000 0000000 Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "{}"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright 2020 [Copyright holder]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
django-iconify-0.4.1/README.rst 0000664 0000000 0000000 00000011615 14741166115 0016115 0 ustar 00root root 0000000 0000000 Iconify API implementation and tools for Django projects
========================================================
This re-usable app hepls integrating `Iconify`_ into Django projects.
Iconify is a unified icons framework, providing access to 40,000+ icons
from different icon sets.
Iconify replaces classical icon fonts, claiming that such fonts would
get too large for some icon sets out there. Instead, it provides an API
to add icons in SVG format from its collections.
`django-iconify`_ eases integration into Django. Iconify, to be performant,
uses a server-side API to request icons from (in batches, with transformations
applied, etc.). Upstream provides a CDN-served central API as well as
self-hosted options written in PHP or Node.js, all of which are undesirable
for Django projects. `django-iconify`_ implements the Iconify API as a
re-usable Django app.
Installation
------------
To add `django-iconify`_ to a project, first add it as dependency to your
project, e.g. using `poetry`_::
$ poetry add django-iconify
Then, add it to your `INSTALLED_APPS` setting to make its views available
later::
INSTALLED_APPS = [
...
"dj_iconify.apps.DjIconifyConfig",
...
]
You need to make the `JSON collection`_ available by some means. You can
download it manually, or use your favourite asset management library. For
instance, you could use `django-yarnpkg`_ to depend on the `@iconify/json`
Yarn package::
YARN_INSTALLED_APPS = [
"@iconify/json",
]
NODE_MODULES_ROOT = os.path.join(BASE_DIR, "node_modules")
No matter which way, finally, you have to configure the path to the
collections in your settings::
ICONIFY_JSON_ROOT = os.path.join(NODE_MODULES_ROOT, "@iconify", "json")
If you do not use `django-yarnpkg`_, construct the path manually, ot use
whatever mechanism your asset manager provides.
You can configure which icon collections are available using two settings:
ICONIFY_COLLECTIONS_ALLOWED = ["foo", "bar"]
This list controls which collections can be used. If it is set to a
non-empty list, only the collections listed are allowed.
ICONIFY_COLLECTIONS_DISALLOWED = ["foo", "bar"]
This list, on the other hand, controls which collections cannot be used.
If this list contains values, while `COLLECTIONS_ALLOWED` doesn't, all
collections except the listed ones are allowed.
The allow/disallow feature can be used in cases where only a limited set
of collections should be available due to design principles or for legal
reasons.
Finally, include the URLs in your `urlpatterns`::
from django.urls import include, path
urlpatterns = [
path("icons/", include("dj_iconify.urls")),
]
Usage
-----
Iconify SVG Framework
~~~~~~~~~~~~~~~~~~~~~
To use the `Iconify SVG Framework`_, get its JavaScript from somewhere
(e.g. using `django-yarnpkg`_ again, or directly from the CDN, from your
ow nstatic files, or wherever).
`django-iconify`_ provides a view that returns a small JavaScript snippet
that configures the `Iconify SVG Framework`_ to use its API endpoints. In
the following example, we first load this configuration snippet, then
include the `Iconify SVG Framework`_ from the CDN (do not do this in
production, where data protection matters)::
Loading SVG directly ("How to use Iconify in CSS")
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
`django-iconify`_ also implements the direct SVG API. For now, you have to use
Django's regular URL reverse resolver to construct an SVG URL, or craft it
by hand::
Documentation on what query parameters are supported can be found in the
documentation on `How to use Iconify in CSS`_.
In the future, a template tag will be available to simplify this.
Including SVG in template directly
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*Not implemented yet*
In the future, a template tag will be available to render SVG icons directly
into the template, which can be helpful in situations where retrieving external
resources in undesirable, like HTML e-mails.
Example
-------
The source distribution as well as the `Git repository`_ contain a full example
application that serves the API under `/icons/` and a test page under `/test.html`.
It is reduced to a minimal working example for the reader's convenience.
.. _Iconify: https://iconify.design/
.. _django-iconify: https://edugit.org/AlekSIS/libs/django-iconify
.. _poetry: https://python-poetry.org/
.. _JSON collection: https://github.com/iconify/collections-json
.. _django-yarnpkg: https://edugit.org/AlekSIS/libs/django-yarnpkg
.. _Iconify SVG Framework: https://docs.iconify.design/implementations/svg-framework/
.. _How to use Iconify in CSS: https://docs.iconify.design/implementations/css.html
.. _Git repository: https://edugit.org/AlekSIS/libs/django-iconify
django-iconify-0.4.1/dj_iconify/ 0000775 0000000 0000000 00000000000 14741166115 0016537 5 ustar 00root root 0000000 0000000 django-iconify-0.4.1/dj_iconify/__init__.py 0000664 0000000 0000000 00000000000 14741166115 0020636 0 ustar 00root root 0000000 0000000 django-iconify-0.4.1/dj_iconify/apps.py 0000664 0000000 0000000 00000000164 14741166115 0020055 0 ustar 00root root 0000000 0000000 from django.apps import AppConfig
class DjIconifyConfig(AppConfig):
name = "dj_iconify"
label = "iconify"
django-iconify-0.4.1/dj_iconify/conf.py 0000664 0000000 0000000 00000000472 14741166115 0020041 0 ustar 00root root 0000000 0000000 """App configuration for django-iconify."""
from django.conf import settings
_prefix = "ICONIFY_"
JSON_ROOT = getattr(settings, f"{_prefix}JSON_ROOT")
COLLECTIONS_ALLOWED = getattr(settings, f"{_prefix}COLLECTIONS_ALLOWED", [])
COLLECTIONS_DISALLOWED = getattr(settings, f"{_prefix}COLLECTIONS_DISALLOWED", [])
django-iconify-0.4.1/dj_iconify/types.py 0000664 0000000 0000000 00000033633 14741166115 0020265 0 ustar 00root root 0000000 0000000 """Iconify data types used in API.
Documentation: https://docs.iconify.design/types/
"""
from typing import Collection, Dict, List, Optional, Sequence, TextIO, Union
import json
from .util import split_css_unit
class IconifyOptional:
"""Mixin containing optional attributes all other types can contain."""
left: Optional[int] = None
top: Optional[int] = None
width: Optional[int] = None
height: Optional[int] = None
rotate: Optional[int] = None
h_flip: Optional[bool] = None
v_flip: Optional[bool] = None
def _as_dict_optional(self) -> dict:
res = {}
if self.left is not None:
res["left"] = self.left
if self.top is not None:
res["top"] = self.top
if self.width is not None:
res["width"] = self.width
if self.height is not None:
res["height"] = self.height
if self.rotate is not None:
res["rotate"] = self.rotate
if self.h_flip is not None:
res["hFlip"] = self.h_flip
if self.v_flip is not None:
res["vFlip"] = self.v_flip
return res
def _from_dict_optional(self, src: dict) -> None:
self.left = src.get("left", None)
self.top = src.get("top", None)
self.width = src.get("width", None)
self.height = src.get("height", None)
self.rotate = src.get("rotate", None)
self.h_flip = src.get("hFlip", None)
self.v_flip = src.get("vFlip", None)
class IconifyIcon(IconifyOptional):
"""Single icon as loaded from Iconify JSON data.
Documentation: https://docs.iconify.design/types/iconify-icon.html
"""
_collection: Optional["IconifyJSON"]
_name: str
body: str
@classmethod
def from_dict(
cls, name: str, src: dict, collection: Optional["IconifyJSON"] = None
) -> "IconifyIcon":
self = cls()
self.body = src["body"]
self._name = name
self._from_dict_optional(src)
self._collection = collection
return self
def as_dict(self) -> dict:
res = {
"body": self.body,
}
res.update(self._as_dict_optional())
return res
def get_width(self):
"""Get the width of the icon.
If the icon has an explicit width, it is returned.
If not, the width set in the collection is returned, or the default of 16.
"""
if self.width:
return self.width
elif self._collection and self._collection.width:
return self._collection.height
else:
return 16
def get_height(self):
"""Get the height of the icon.
If the icon has an explicit height, it is returned.
If not, the height set in the collection is returned, or the default of 16.
"""
if self.height:
return self.height
elif self._collection and self._collection.height:
return self._collection.height
else:
return 16
def as_svg(
self,
color: Optional[str] = None,
width: Optional[str] = None,
height: Optional[str] = None,
rotate: Optional[str] = None,
flip: Optional[Union[str, Sequence]] = None,
box: bool = False,
) -> str:
"""Generate a full SVG of this icon.
Some transformations can be applied by passing arguments:
width, height - Scale the icon; if only one is set and the other is not
(or set to 'auto'), the other is calculated, preserving aspect ratio.
Suffixes (i.e. CSS units) are allowed
rotate - Either a degress value with 'deg' suffix, or a number from 0 to 4
expressing the number of 90 degreee rotations
flip - horizontal, vertical, or both values with comma
box - Include a transparent box spanning the whole viewbox
Documentation: https://docs.iconify.design/types/iconify-icon.html
"""
# Original dimensions, the viewbox we use later
orig_width, orig_height = self.get_width(), self.get_height()
if width and (height is None or height.lower() == "auto"):
# Width given, determine height automatically
value, unit = split_css_unit(width)
height = str(value / (orig_width / orig_height)) + unit
elif height and (width is None or width.lower() == "auto"):
# Height given, determine width automatically
value, unit = split_css_unit(height)
width = str(value / (orig_height / orig_width)) + unit
elif width is None and height is None:
# Neither width nor height given, default to browser text size
width, height = "1em", "1em"
# Build attributes to inject into