Giter Site home page Giter Site logo

django-feather's Introduction

Django Feather

Build and Publish Test

A simple Tag ({% icon "name" %}) to implement Feather Icons in Django.

Install

Install django-feather using pip and put it into your INSTALLED_APPS:

pip install django-feather

settings.py:

INSTALLED_APPS = [
    # ...
    'django_feather',
    # ...
]

Usage

After installation, the tag can be used just like any other tag:

{% load icon %}

<p>Using a string {% icon "coffee" class="css-class" height="8" width="8" %}</p>
<p>Using a variable {% icon icon_name class="css-class" height="8" width="8" %}</p>

The icon tag will simply take the SVG source from the Feather project, apply additional attributes and return the SVG tag.

Additionally, data URIs are supported by setting data_uri=True. This will yield a Base64 encoded data URI that can be used e.g. in src attributes or with CSS:

<img src="{% icon icon_name data_uri=True %}">

Testing

There are a few tests in the tests directory that should test the basic functions of this module. However, as these tests require the package to be build (so that the django_feather.icons module is populated), there are a few important steps to testing:

# Start by building the project
python setup.py build
# There should now be a build/lib directory present

# Make sure that django, pytest and pytest-django are installed:
pip install django pytest pytest-django

# Run the tests
export DJANGO_SETTINGS_MODULE=tests.settings
PYTHONPATH=build/lib:./ pytest tests 

The environment variable PYTHONPATH ensures that django_feather is not imported from the current directory but rather from the build/lib directory.

Performance

django-feather does not read the .svg files each time an icon is rendered. Instead, all the icons are written to a .py file upon build, just like the JavaScript library.
However, other than the JavaScript library, icons are rendered on the server side. This avoids having to call feather.replace() after the page has loaded.

License

Feather is licensed under the MIT License.

django-feather is licensed under the Apache License, Version 2.0:

Copyright 2019-2021 Jonas Drotleff <[email protected]>

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-feather's People

Contributors

3j14 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

xshapira

django-feather's Issues

Can't use as favicon

Would love to be able to use the icons as favicons, at the moment is not possible (or I am doing it wrong).

I tested it like this

{% load icon %}

<!DOCTYPE html>
<html lang="en">

  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="shortcut icon" href="{% icon 'lock' %}">
  </head>

</html>

Based on the usual way of doing it with static

{% load static %}

<!DOCTYPE html>
<html lang="en">

  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="shortcut icon" href="{% static 'img/favicon.svg' %}">
  </head>

</html>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.