Skip to main content



Django-svg-clip

Django-svg-clip is a django template tags plugin for manipulating and rendering of svg and its attributes.

Features

  • Adding static and dynamic attributes to svg icons.
  • You don't have to paste the whole svg tag to add atrributes such as classes, inline-styles, WAI-arias.
  • Make the templates look cleaner and shorter.
  • Increases readability.

Installation

Install django-svg-clip from PyPI by running:

# shell
pip install django-svg-clip

Setup

  1. After installing add svg_clip to INSTALLED_APPS in the DJANGO_SETTINGS_MODULE(e.g. settings.py).
# settings.py
INSTALLED_APPS = [
    # ...
    'svg_clip',
]
  1. Add SVG icons path to SVG_ICONS_DIRS:
# settings.py
SVG_ICONS_DIRS = [
    # path/to/icons
    # E.g:
    BASE_DIR / "static" / "heroicons" / "outline",
    BASE_DIR / "static/heroicons/solid",
    BASE_DIR / "static" / "icons",
    BASE_DIR / "static/icons",
]
  1. Or you can use default icons by setting USE_CLIP_ICONS to True.
# settings.py
USE_CLIP_ICONS = True

Usage

After adding the path of icons, use this tag {% clip 'icon-name' keyword_attrs="key word attrs" "non-keyword" "attrs" %} to add the icons to the django template.

NOTE: Don't put .svg extension to the icons, it is automatically added during compilation.

<!-- template.html -->
<!DOCTYPE html>
{% load svg_clip %}
<html>
  <head>
    <!-- ...  -->
  </head>
  <body>
    <!-- ...  -->
    {% clip 'academic-cap' %}
    {% clip 'academic-cap' class="h-6 w-6" %}
    {% clip 'academic-cap-solid' class="h-6 w-6" styles="display: block" %}
    {% clip 'academic-cap' class="h-6 w-6" styles="display: block" "hidden" %}
  </body>
</html>

Remarks: The defult icon set is heroicons-v2.0.13. To use the outline version, just use the icon name and for solid version, add '-solid' suffix to the icon name. For example, to use 'academic-cap.svg' outline version, just use 'academic-cap' and for solid version use 'academic-cap-solid'.

Development

NOTE: For contributing read the CONTRIBUTING.md file.

Support

If you are having issues, please let us know by opening an issue in our github repo. We warmly welcome you for any suggestion.

License

The project is licensed under the MIT license giving the community maximum priviledge to use. For more read LICENSE.md file.

Author

Name: Dayal Moirangthem
Twitter: @thisisdayal

Acknowledgement and credits

Heroicons: By default, we use icon set provided by heroicons with a minimal tweaks in icon names. For example, academic-cap.svg, there is no modification for outline version, just use academic-cap(without ".svg" extension) but for solid, you should use academic-cap-solid(without ".svg" extension) .This is done to avoid naming conflicts with outline and solid versions.

We'd like to show our regards to tailwindlabs team for availing those icons to community with an open source license.

Python project template: We use rochacbruno's python project template with little modification. It saves us a lot of time and headache during initial setup.

MIT License

Copyright (c) 2023 Dayal Moirangthem

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Changelog

(unreleased)

Other

  • Chore: updated workflow files. [Dayal Moirangthem]

1.0.1 (2023-02-15)

Other

  • Release: version 1.0.1 🚀 [Dayal Moirangthem]

  • CI: updated main.yml to use latest actions. [Dayal Moirangthem]

  • CI: updated release.yml and rename_project.yml to use latest actions. [Dayal Moirangthem]

  • CI: added production environment to release.yml. [Dayal Moirangthem]

  • Chore: update README.md. [Dayal Moirangthem]

  • Delete static-pages.yml. [Dayal Moirangthem]

  • Create static-pages.yml. [Dayal Moirangthem]

  • Chore: README.md typo fix. [Dayal Moirangthem]

1.0.0 (2023-02-15)

Fix

  • Updated kwargs_re to match all unicode characters. [Dayal Moirangthem]

Other

  • Release: version 1.0.0 🚀 [Dayal Moirangthem]

  • Chore: minor fixes. [Dayal Moirangthem]

  • Chore: minor fixes. [Dayal Moirangthem]

  • Chore: added extra dependencies. [Dayal Moirangthem]

  • Docs: added instructions in README.md and minor modifications to other files. [Dayal Moirangthem]

  • Refactor: refactoring code for distribution build. [Dayal Moirangthem]

    • added build method, Makefile.

    • included VERSION and pylintrc in MANIFEST.in.

    • added version detection in svg_clip package.

    • updated conftest.py.

    • refactored tests for better compliance to code formatters.

  • Chore: tox.ini, requirements.txt, MANIFEST.in and Makefile are reconfigured. [Dayal Moirangthem]

  • Test: removed vague tests. [Dayal Moirangthem]

    Removed tests for path returning multiple path (list or tuple) and removed malinformed argument test. Cannot find suitable test for malinformed arguments

  • Refactor: code refactoring. [Dayal Moirangthem]

    Reduced the number of variables for better design.

  • Chore: added tox and Makefile is changed to use tox. [Dayal Moirangthem]

  • Refactor: code refactoring. [Dayal Moirangthem]

    Dictionary concatenation for new attributes has been shortned. Variable old attrs has been removed. 'key' and 'value' has replaced 'k', 'v' respectively.

  • Chore: updated .coverage file to test __repr__ method. [Dayal Moirangthem]

  • Refactor: remove test for multiple icon paths. [Dayal Moirangthem]

    Since we cannot find any case for path to return a list or tuple, this test is vague so removed from the test

  • Test: test for almost all of the possible cases covering the whole source code. [Dayal Moirangthem]

  • Chore: added .coveragerc for code coverage configurations. [Dayal Moirangthem]

  • Refactor: 'svg_clip.py' returning multiple paths for an icon. [Dayal Moirangthem]

0.1.0 (2023-02-11)

Fix

  • ClipNode must not have no child Nodes. [Dayal Moirangthem]

  • ClipNode no longer accepts empty string value for svg_name. [Dayal Moirangthem]

    passing empty string value raises ValueError

Other

  • Release: version 0.1.0 🚀 [Dayal Moirangthem]

  • Feat: added default icons. [Dayal Moirangthem]

    By default SVG clip uses heroiconsSVG's.

    set 'USE_CLIP_ICONS=True' in your 'DJANGO_SETTINGS_MODULE' to enable default icons.

  • Wip: added compilation function for ClipNode. [Dayal Moirangthem]

    Implemented render method for rendering SVG markup with user provided attributes.

  • Wip: added SVGParser for parsing SVG files and extract attributes. [Dayal Moirangthem]

  • Wip: added custom exceptions. [Dayal Moirangthem]

  • Test(passed)!:ClipNode repr test. [Dayal Moirangthem]

    • test with all valid arguments

    • test with valid svg_name, empty args and kwargs

    • test with empty string value for svg_name

    • test with no value for svg_name

    • test with no arguments

  • Wip: created ClipNode for compilation function and added __repr__ method. [Dayal Moirangthem]

  • Chore: added templatetags module. [Dayal Moirangthem]

  • Chore: deleted non-needed files __main__.py, base.py, cli.py [Dayal Moirangthem]

  • Chore: updated different project files. [Dayal Moirangthem]

  • ✅ Ready to clone and code. [thisisdayal]

  • Initial commit. [Dayal Moirangthem]

Release files for django-svg-clip 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-svg-clip 1.0.2
File Size Uploaded
django-svg-clip-1.0.2.tar.gz 111.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-svg-clip 1.0.2
File Interpreter ABI Platform
django_svg_clip-1.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 415.6 kB

Release files / django-svg-clip-1.0.2.tar.gz

Download URL django-svg-clip-1.0.2.tar.gz
Size 111.0 kB
Tags Source
SHA-256 checksum
How to use checksums
e4a99500a061312c0ac7ed92258e6db538521cc16c6fe21cd7a0844df0e35573
BLAKE2b-256 checksum
How to use checksums
0c5a60851b0844b552265ce8783194ecc0ae7bae6502f4f6abb5540d347be41f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.1

Release files / django_svg_clip-1.0.2-py3-none-any.whl

Download URL django_svg_clip-1.0.2-py3-none-any.whl
Size 304.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
939a111381a2fd025d9b9f57bdc65fd91d184d369954cf68b5ff9ff1938e99cc
BLAKE2b-256 checksum
How to use checksums
705b14470f5d21216fede3550ab9a060c1cb5a3c6190d783aecf3bd0dcc9c805
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.1

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 release files

1.0.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page