Giter VIP home page Giter VIP logo

djangocms-icon's Introduction

django CMS Icon

pypi coverage python django djangocms djangocms4

django CMS Icon is a plugin for django CMS that allows you to insert an icon (font or svg) into your project.

Note

This project is endorsed by the django CMS Association. That means that it is officially accepted by the dCA as being in line with our roadmap vision and development/plugin policy. Join us on Slack.

image

Contribute to this project and win rewards

Because this is a an open-source project, we welcome everyone to get involved in the project and receive a reward for their contribution. Become part of a fantastic community and help us make django CMS the best CMS in the world.

We'll be delighted to receive your feedback in the form of issues and pull requests. Before submitting your pull request, please review our contribution guidelines.

We're grateful to all contributors who have helped create and maintain this package. Contributors are listed at the contributors section.

Installation

For a manual install:

  • run pip install djangocms-icon
  • add djangocms_icon to your INSTALLED_APPS
  • run python manage.py migrate djangocms_icon

A note about django CMS Text CKEditor

There are additional steps required for the icon plugin to display correctly inside CKEditor.

1. You need to make sure your icon CSS is passed via CKEditors contentsCss parameter. On Divio Cloud this can be done through the Addons configuration.

2. CKEditor automatically removes empty tags, you can prevent this by adding a javascript configuration file to style_set.

django CMS Icon does not add the styles or javascript files to your frontend, these need to be added at your discretion.

Configuration

This addon provides a default template for all instances. You can provide additional template choices by adding a DJANGOCMS_ICON_TEMPLATES setting:

DJANGOCMS_ICON_TEMPLATES = [
    ('svg', 'SVG template'),
]

Web Font Icons

The django CMS Icon plugin ships with Font Awesome 5 as default. This can be changed by overriding the following setting:

DJANGOCMS_ICON_SETS = [
    ('fontawesome5regular', 'far', 'Font Awesome 5 Regular', 'lastest'),
    ('fontawesome5solid', 'fas', 'Font Awesome 5 Solid', 'lastest'),
    ('fontawesome5brands', 'fab', 'Font Awesome 5 Brands', 'lastest'),
]

In addition you need to load the resources for your fonts in /admin/djangocms_icon/includes/assets.html. Add this file to your project in order for the icon picker to pick up your custom icons in the admin.

The icon picker supports numerous font libraries out of the box. You can also add multiple font sets like this:

DJANGOCMS_ICON_SETS = [
    ('elusiveicon', 'el', 'Elusive Icons'),
    ('flagicon', 'flag-icon', 'Flag Icons'),
    ('fontawesome5regular', 'far', 'Font Awesome 5 Regular'),
    ('fontawesome5solid', 'fas', 'Font Awesome 5 Solid'),
    ('fontawesome5brands', 'fab', 'Font Awesome 5 Brands'),
    ('fontawesome5light', 'fal', 'Font Awesome 5 Light', '5.3.1_pro'),
    ('glyphicon', 'glyphicon', 'Glyphicons'),
    ('ionicon', 'ion', 'Ionicons Icons'),
    ('mapicon', 'map-icon', 'Map Icons'),
    ('materialdesign', 'zmdi', 'Material Design'),
    ('octicon', 'octicon', 'Octicons'),
    ('typicon', 'typcn', 'Typicons'),
    ('weathericon', 'wi', 'Weather Icons'),
]

You can also add the version number as a fourth parameter. If no parameter is given the latest version of the bootstrap-iconpicker icon set is used.:

DJANGOCMS_ICON_SETS = [
    ('fontawesome4', 'fa', 'Font Awesome 4', '4.0.0'),
    ('fontawesome5light', 'fal', 'Font Awesome 5 Light', '5.3.1_pro'),
]

Just don't forget to include both libraries in the assets.html file. This is only necessary for the plugin rendering while selecting the icon. You still need to implement the font libraries into your frontend stack.

Custom Web Font Icons

You can also add your own custom web fonts, for this you need to tell the icon picker where to find the necessary files:

DJANGOCMS_ICON_SETS = [
    (ICONSET, 'icon', 'Custom web font'),
]

In this example, we add our own font icon set on top of it. Please mind that the second parameter needs to be the icon prefix. ICONSET is an external reference to a JSON file at the root of your project setting up your custom font icons, add this before:

with open('iconset.json') as fh:
    ICONSET = fh.read()

Here an example of its content:

{
    "iconClass": "icon",
    "icons": [
        "icon-icon1",
        "icon-icon2",
        "..."
    ]
}

The iconClass refers to the second parameter in the settings file for the icon prefix. Make sure both of them are the same. Instead of using an external file you can also write the settings directly to the DJANGOCMS_ICON_SETS setting.

djangocms-boilerplate-webpack can generate the iconset.json automatically for you through gulp icons.

Make sure the icons names contain the iconset prefix as shown in the example, the widget will determine the iconset based on that. They can be omitted if only one iconset is used.

Don't forget to also add your custom fonts to /admin/djangocms_icon/includes/assets.html into your project.

SVG Icons

django CMS Icon also supports SVG icons. Follow the instructions from Custom Web Font Icons and then adapt the JSON file a bit:

{
    "svg": true,
    "spritePath": "sprites/icons.svg",
    "iconClass": "icon",
    "icons": [
        "icon-icon1",
        "icon-icon2",
        "..."
    ]
}

svg and spritePath are the only required additional properties. You also need to add an icon template to your project to render it correctly, for example:

<span class="{{ instance.icon }} {{ instance.attributes.class }}">
    <svg role="presentation">
        <use xlink:href="{% static 'sprites/icons.svg' %}#{{ instance.icon }}"></use>
    </svg>
</span>

Running Tests

You can run tests by executing:

virtualenv env
source env/bin/activate
pip install -r tests/requirements.txt
python setup.py test

djangocms-icon's People

Contributors

antwertinger avatar crydotsnake avatar dependabot[bot] avatar finalangel avatar fsbraun avatar kaushal-dhungel avatar marksweb avatar narenderrajub avatar nicolairidani avatar pre-commit-ci[bot] avatar vthaian avatar vxsx avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

djangocms-icon's Issues

Add steps for installing Font Awesome

When installing Django Icon - it doesn't mean that Font Awesome will be installed also
Maybe it's a good idea to stress on it, and to add some step for installing it

Icon is not displayed in django_bootstrap4_link

icon class is not rendered correctly.

<i class="" aria-hidden="true"></i>

Based on my investigation, the problem is caused when passing a parameter instance.icon_left or instance.icon_right from templates/djangocms_bootstrap4/link/default/link.html to templates/djangocms_icon/includes/icon.html

{% with icon_class=instance.icon_left instance=instance.icon_left %}{% include "djangocms_icon/includes/icon.html" %}{% endwith %}

<i class="{{ instance.icon }}...</i>

  • Instance.icon_left or instance.icon_right is String type
  • instance in icon.html is Icon Instance
  • The String type does not have icon property, so it will render empty string by errors

The easy is to create a custom template for templates/djangocms_icon/includes/icon.html, as follows

{% load cms_tags %}<i class="{% if icon_class %}{{ icon_class }}{% else %}{{ instance.icon }}{% endif %}{% if instance.attributes.class %} {{ instance.attributes.class }}{% endif %}" aria-hidden="true"{% for key, value in instance.attributes.items %}{% if key != 'class' %}{{ key }}="{{ value }}" {% endif %}{% endfor %}></i>

Update (or document) for use with current Font Aweseome 5.0

This is still targeted to work with old Font Aweseome 4.7.0. Would be great if this could be updated to be compatible with the current version of Font Awesome (5.0). Alternatively, a slightly more elaborate documentation would be helpful, e.g. with some hints on how to configure Font Awesome 5.0 as ones "own" SVG icon set.

Should I find the time to figure it out, I will follow up here.

Keep up the excellent work, team divio!

Multiple iconsets cause problems with the icon selector widget

There is a problem with the icon selector widget using multiple icon sets.

Example:

DJANGOCMS_ICON_SETS = [
    (ICONSET, 'icon', 'SVG icons'),
    (ICONSET2, 'icon2', 'SVG icons 2'),
]

If one does select an icon from "SVG icons 2" and saves the plugin, opens it again, the wrong icon will be preselected (first of "SVG icons").
Steps to reproduce:

  1. Use following configuration:
DJANGOCMS_ICON_SETS = [
    ('fontawesome', 'fa', 'Font Awesome'),
    (ICONSET, 'icon', 'SVG icons'),
]
  1. Insert an icon plugin with an icon from "SVG Icons" into a placeholder.
  2. Open the plugin again - wrong icon will be selected.

Version 1.3.0 breaks compatibility with djangocms-bootstrap4

The new changes to enable FA5 support break compatibility with Bootstrap 4 links from the djangocms-bootstrap4 library, because that library stores the Icon as a charfield and it has not been updated to follow the conventions of the updated djangocms-icon. The result has a few effects, including icons on existing links being lost in the update, and editing being broken due to an indexing error resulting from the charfield in the Bootstrap library not storing the icon in the form "fa fa-". This may be an issue that needs to be fixed in the Bootstrap 4 library itself, but until the point in which that library is updated it creates a number of issues for anyone attempting to use both.

Support for Font Awesome 5 Pro

I would like to use Font Awesome 5 Pro.
I saw that in Bootstrap-Iconpicker it is possible to specify the version of the iconset to be used e.g
data-iconset-version="5.3.1_pro"
I could not find a way to set the version in this plugin. Could you add this possibility?

Can not find icons

After update Django 2.1.8 and Djangocms 3.6.0 I can't see de icons to chooose

icon

Issue with Django CMS Icon Module: Missing Static Path and Extra Class in Generated Markup

I am attempting to utilize the djangocms-icon module to incorporate my own SVG icons into my Django CMS project. Following the documentation, I have successfully added Material Design icons. However, I encounter issues when adding my custom SVG icons.

In my settings.py, I added the following code:

with open('iconset.json') as fh:
    ICONSET = fh.read()

DJANGOCMS_ICON_SETS = [
    ('fontawesome5regular', 'far', 'Font Awesome 5 Regular', 'latest'),
    ('fontawesome5solid', 'fas', 'Font Awesome 5 Solid', 'latest'),
    ('fontawesome5brands', 'fab', 'Font Awesome 5 Brands', 'latest'),
    ('materialdesign', 'zmdi', 'Material Design'),
    (ICONSET, 'svg-icon', 'My Icons'),
]

DJANGOCMS_ICON_TEMPLATES = [
    ('svg', 'SVG template'),
]

I have created an iconset.json file at the root of my project:

{
    "svg": true,
    "spritePath": "sprites/icons.svg",
    "iconClass": "svg-icon",
    "iconClassFix": "svg-icon-",
    "icons": [
        "svg-icon-card",
        "svg-icon-card-add"
    ]
}

I have also created my icons.svg file in static/sprites/icons.svg:

<svg width="0" height="0" class="hidden">
  <symbol xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" id="svg-icon-card">
    <!-- path data -->
  </symbol>
  <symbol xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" id="svg-icon-card-add">
    <!-- path data -->
  </symbol>
</svg>

Additionally, I created templates/djangocms_icon/svg/icon.html:

{% load cms_tags static %}
<span class="icon {{ instance.attributes.class }}">
    <svg role="presentation">
        <use xlink:href="{% static 'sprites/icons.svg' %}#{{ instance.icon }}"></use>
    </svg>
</span>

The issue arises in the generated markup. In the icon addition widget inspection, there is a missing /static/ before sprites/icons.svg#svg-icon-card. Additionally, in the page render, there is an extra svg-icon class after the # in the xlink. The generated markup looks like this:

<span class="djangocms-svg-icon svg-icon svg-icon-card">
    <svg role="presentation">
        <use xlink:href="sprites/icons.svg#svg-icon-card"></use>
    </svg>
</span>

There is a missing /static/ before sprites/icons.svg#svg-icon-card.

There also an issue in my rendered page with an extra "svg-icon " after the # in the xlink.

<span class="icon  cms-plugin cms-plugin-3730">
    <svg role="presentation">
        <use xlink:href="/static/sprites/icons.svg#svg-icon svg-icon-card"></use>
    </svg>
</span>

How can I resolve these issues?

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.