Skip to content
Snippets Groups Projects
Commit e22bcda8 authored by Fabrice Salvaire's avatar Fabrice Salvaire
Browse files

implemented icon extension for jinja

parent 58202dd1
No related branches found
No related tags found
No related merge requests found
Showing
with 136 additions and 30 deletions
......@@ -4,7 +4,7 @@
{% with fields = form.non_field_errors() %}
{% if fields %}
<div class="alert alert-danger">
<a class="close" data-dismiss="alert"><i class="fas fa-times"></i></a>
<a class="close" data-dismiss="alert">{% icon 'fas.fa-times' %}</a>
{% for non_field_error in fields %}
{{ non_field_error }}
{% endfor %}
......
......@@ -10,6 +10,7 @@
{% block head_scripts %}
{% if use_cdn %}
{# Fontawesome #}
{# https://fontawesome.com/get-started/web-fonts-with-css #}
{# <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.8/css/solid.css" #}
{# integrity="sha384-v2Tw72dyUXeU3y4aM2Y0tBJQkGfplr39mxZqlTBDUZAb9BGoC40+rdFCG0m10lXk" #}
......@@ -17,11 +18,13 @@
{# <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.8/css/fontawesome.css" #}
{# integrity="sha384-q3jl8XQu1OpdLgGFvNRnPdj5VIlCvgsDQTQB6owSOHWlAurxul7f+JpUOVdAiJ5P" #}
{# crossorigin="anonymous"> #}
{# https://fontawesome.com/get-started/svg-with-js #}
<script defer src="https://use.fontawesome.com/releases/v5.0.8/js/solid.js"
integrity="sha384-+Ga2s7YBbhOD6nie0DzrZpJes+b2K1xkpKxTFFcx59QmVPaSA8c7pycsNaFwUK6l"
crossorigin="anonymous">
</script>
{# <script defer src="https://use.fontawesome.com/releases/v5.0.8/js/fontawesome.js" #}
{# integrity="sha384-7ox8Q2yzO/uWircfojVuCQOZl+ZZBg2D2J5nkpLqzH1HY0C1dHlTKIbpRz/LG23c" #}
{# crossorigin="anonymous"> #}
......@@ -34,8 +37,9 @@
{% else %}
{# Fontawesome #}
<script defer src={{ static('js-ext/fontawesome-all.min.js') }}></script>
<script defer src={{ static('js-ext/fa-v4-shims.min.js') }}></script>
<script defer src={{ static('js-ext/fontawesome-all.min.js') }}></script>
<link rel="stylesheet" href="{{ static('css-ext/fa-svg-with-js.css') }}">
<script defer src={{ static('js-ext/fa-v4-shims.min.js') }}></script>
<link rel="stylesheet" href="{{ static('css-ext/fa-solid.min.css') }}">
{# Bootstrap #}
......@@ -110,24 +114,24 @@
<li class="nav-item dropdown mr-md-5 {% block nav_account %}{% endblock %}">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="fa fa-user"></i> {{ user.username }} {#get_full_name()#}</a>
{% icon 'fa-user' %} {{ user.username }} {#get_full_name()#}</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="{{ url('account_settings') }}">
<i class="fa fa-user"></i> {{ _('Settings') }}</a>
{% icon 'fa-user' %} {{ _('Settings') }}</a>
{% if request.user.is_staff %}
{# {% url THEME_ADMIN_URL|default:"admin:index" %} #}
<a class="dropdown-item" href="{{ url('admin:index') }}">
<i class="fa fa-cog"></i> {{ _('Admin') }}</a>
{% icon 'fa-cog' %} {{ _('Admin') }}</a>
{% endif %}
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="{{ url('account_logout') }}">
<i class="fa fa-sign-out-alt"></i> {{ _('Log out') }}</a>
{% icon 'fa-sign-out-alt' %} {{ _('Log out') }}</a>
</div>
</li>
{% else %}
<li class="nav-item {% block nav_login %}{% endblock %}">
<a class="nav-link" href="{{ url('account_login') }}">
<i class="fa fa-sign-in-alt"></i> {{ _('Log in') }}
{% icon 'fa-sign-in-alt' %} {{ _('Log in') }}
</a>
</li>
{% if ACCOUNT_OPEN_SIGNUP %}
......@@ -147,19 +151,19 @@
<nav id="left-sidebar" class="active">
<div class="left-sidebar-wrapper">
<div id="left-sidebar-open-wrapper">
<button id="open-left-sidebar" type="button" class="btn btn-sm"><i class="fas fa-caret-right"></i></button>
<button id="open-left-sidebar" type="button" class="btn btn-sm">{% icon 'fas.fa-caret-right' %}</button>
</div>
<div class="left-sidebar-header">
<button id="close-left-sidebar" type="button" class="btn btn-sm"><i class="fas fa-caret-left"></i></button>
<button id="close-left-sidebar" type="button" class="btn btn-sm">{% icon 'fas.fa-caret-left' %}</button>
</div>
<div class="left-sidebar-spacer">
<div id="left-sidebar-scroll">
<ul class="sidebar-elements">
{% block left_sidebar_menu %}
<li class="divider">Menu</li>
<li class="active"><a href="index.html"><i class="fas fa-home"></i><span>Dashboard</span></a>
<li class="active"><a href="index.html">{% icon 'fas.fa-home' %}<span>Dashboard</span></a>
</li>
<li class="parent"><a href="#"><i class="fas fa-home"></i><span>UI Elements</span></a>
<li class="parent"><a href="#">{% icon 'fas.fa-home' %}<span>UI Elements</span></a>
<ul class="sub-menu">
<li><a href="ui-alerts.html">Alerts</a>
</li>
......@@ -175,7 +179,7 @@
</div>
<div class="left-sidebar-footer">
<p>
<i class="fa fa-copyright"></i>
{% icon 'fa-copyright' %}
<a href="https://github.com/FabriceSalvaire/climbing-asso-portal">Climbing Asso Portal 2018</a>
</p>
<p><a href="{{ url('mentions-legales') }}">Mentions légales</a></p>
......@@ -188,9 +192,9 @@
{# {% block left_sidebar_menu %} #}
{# <li class="divider">Menu</li> #}
{# <li class="active"><a href="index.html"><i class="fas fa-home"></i><span>Dashboard</span></a> #}
{# <li class="active"><a href="index.html">{% icon 'fas.fa-home' %}<span>Dashboard</span></a> #}
{# </li> #}
{# <li class="parent"><a href="#"><i class="fas fa-home"></i><span>UI Elements</span></a> #}
{# <li class="parent"><a href="#">{% icon 'fas.fa-home' %}<span>UI Elements</span></a> #}
{# <ul class="sub-menu"> #}
{# <li><a href="ui-alerts.html">Alerts</a> #}
{# </li> #}
......@@ -254,7 +258,7 @@
{# </li> #}
{# </ul> #}
{# </li> #}
{# <li class="parent"><a href="#"><i class="fas fa-folder"></i><span>Menu Levels</span></a> #}
{# <li class="parent"><a href="#">{% icon 'fas.fa-folder' %}<span>Menu Levels</span></a> #}
{# <ul class="sub-menu"> #}
{# <li class="parent"><a href="#"><span>Level 1</span></a> #}
{# <ul class="sub-menu"> #}
......@@ -302,7 +306,7 @@
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item" aria-current="page">
<a href="/"><i class="fa fa-home"></i> {{ _('Home') }}{# Acceuil #}</a></li>
<a href="/">{% icon 'fa-home' %} {{ _('Home') }}{# Acceuil #}</a></li>
{% block breadcrumb_li %}{% endblock %}
</ol>
</nav>
......@@ -329,7 +333,7 @@
<hr />
<footer role="contentinfo" >
<p>
<i class="fa fa-copyright"></i>
{% icon 'fa-copyright' %}
<a href="https://github.com/FabriceSalvaire/climbing-asso-portal">
Climbing Asso Portal 2018</a>
/ <a href="{{ url('mentions-legales') }}">Mentions légales</a>
......
{# -*- mode: jinja2 -*- #}
<!DOCTYPE html>
{# <html lang="en"> #}
<html lang="fr" {% block ng_app %}{% endblock %}>
<html lang="fr" {% block ng_app %}{% endblock %} class="fontawesome-i2svg-pending">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
......
......@@ -7,7 +7,7 @@
<div class="alert alert-{{ message.tags }} alert-dismissible fade show" role="alert">
{# <strong>{{ message.tags|default:'error'|capfirst }}:</strong> #} {{ message }}
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true"><i class="fas fa-times"></i></span>
<span aria-hidden="true">{% icon 'fas.fa-times' %}</span>
</button>
</div>
{% endfor %}
......
......@@ -4,7 +4,7 @@
{% macro new_button_group(title, href) -%}
<a class="btn btn-primary" role="button" href="{{ href }}">
<i class="fa fa-plus"></i> {{ title }}
{% icon 'fa-plus' %} {{ title }}
</a>
{%- endmacro %}
......@@ -16,7 +16,7 @@
{% if field.label %}<label for="id_query">{{ field.label }}</label>{% endif %}
<input type="search" class="form-control mx-sm-2" id="id_query"
name={{ field.name }} placeholder="{{ field.help_text }}" value="{{ field.value() }}" style="width: 25em">
<button type="submit" class="btn btn-primary"><i class="fa fa-search"></i> {{ _('Search') }}</button>
<button type="submit" class="btn btn-primary">{% icon 'fa-search' %} {{ _('Search') }}</button>
</form>
{# double-click to select all the query #}
{% endwith %}
......@@ -26,9 +26,9 @@
{% macro update_delete_button_group(href, modal_id="deleteModal") -%}
<div class="btn-group m-b-1" role="group">
<a role="button" class="btn btn-primary" href="{{ href }}">
<i class="fa fa-pencil-alt"></i></a>
{% icon 'fa-pencil-alt' %}</a>
<a role="button" class="btn btn-danger" data-toggle="modal" data-target="#{{ modal_id }}">
<i class="fa fa-trash"></i></a>
{% icon 'fa-trash' %}</a>
</div>
{%- endmacro %}
......
......@@ -26,7 +26,7 @@
{# class="hidden-xs-down" #}
{% else %}
<a class="btn btn-primary btn-lg m-b-1" href="{{ url('account_login') }}" role="button">
<i class="fa fa-sign-in-alt"></i> Connexion</a></li>
{% icon 'fa-sign-in-alt' %} Connexion</a></li>
{% endif %}
{# <a class="btn btn-primary btn-lg m-b-1" href="{{ url('about') }}" role="button"> #}
......
......@@ -25,7 +25,7 @@
{# <img class="mx-auto d-block" src={{ url('member.age_histogram_error_svg') }}></img> #}
<p>
<a class="btn btn-primary" href={{ url('member.age_histogram_csv') }}><i class="fas fa-download"></i> {{ _('Age Histogram as CSV') }}</a>
<a class="btn btn-primary" href={{ url('member.age_histogram_csv') }}>{% icon 'fas.fa-download' %} {{ _('Age Histogram as CSV') }}</a>
</p>
{% endblock %}
......@@ -17,7 +17,7 @@
<p>
Cette application web a été écrite par
<a target="_blank" href="http://www.fabrice-salvaire.fr" itemprop="author" itemscope itemtype="http://schema.org/People">
<span itemprop="name">Fabrice Salvaire</span> <i class="fa fa-home"></i></a>.
<span itemprop="name">Fabrice Salvaire</span> {% icon 'fa-home' %}</a>.
<br>
Le <a target="_blank" href="https://github.com/bleaudb/bleau-database">code source</a> est sous licence
<a target="_blank" href="http://www.gnu.org/licenses/agpl.html">GNU Affero General Public License V3</a>.
......@@ -31,7 +31,7 @@
<h2>Responsable de publication</h2>
<p itemprop="author" itemscope itemtype="http://schema.org/People">
<a href="http://www.fabrice-salvaire.fr/personal/index.html">
<span itemprop="name">Fabrice Salvaire</span> <i class="fa fa-envelope"></i></a>
<span itemprop="name">Fabrice Salvaire</span> {% icon 'fa-envelope' %}</a>
</p>
<h2>Hébergement du site Internet</h2>
......
......@@ -5,9 +5,9 @@
{% endblock %}
{% block content %}
<h1><i class="fa fa-exclamation-triangle"></i> Page non trouvé </h1>
<h1>{% icon 'fa-exclamation-triangle' %} Page non trouvé </h1>
<p>La page que vous avez demandé n'a pas pu être trouvé. Soit l'adresse est erronée, soit le site est en derengement.</p>
<p>Retourner à l'<a href="/{{ lang_code }}">Accueil <i class="fa fa-home"></i></a></p>
<p>Retourner à l'<a href="/{{ lang_code }}">Accueil {% icon 'fa-home' %}</a></p>
{# The page you requested could not be found, either contact your webmaster or try again later. Use
your browsers <b>Back</b> button to navigate to the page you have previously come from. #}
</p>
......
####################################################################################################
#
# Climbing Asso Portal - A Portal for Climbing Club (Association)
# Copyright (C) 2018 Fabrice Salvaire
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
####################################################################################################
from django_jinja import library
from .jinja_extensions.i18n import DjangoI18n
from .jinja_extensions.icon import Icon
####################################################################################################
library.extension(DjangoI18n)
library.extension(Icon)
####################################################################################################
#
# Climbing Asso Portal - A Portal for Climbing Club (Association)
# Copyright (C) 2018 Fabrice Salvaire
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
####################################################################################################
####################################################################################################
from django.conf import settings
from django.utils import translation
from jinja2 import lexer, nodes, Markup
from jinja2.ext import Extension
####################################################################################################
class Icon(Extension):
tags = set(['icon'])
##############################################
def parse(self, parser):
stream = parser.stream
lineno = stream.expect('name:icon').lineno
name = stream.expect('string').value
additional_classes = []
while not stream.current.test('block_end'):
additional_classes = stream.expect('string').value
if '.' in name:
domain, name = name.split('.')
elif name.startswith('fa-'):
domain = 'fa'
else:
parser.fail('invalid icon name {}'.format(name), lineno)
call = self.call_method(
'_render',
[
nodes.Const(domain),
nodes.Const(name),
nodes.List(additional_classes),
],
lineno=lineno
)
return nodes.Output([nodes.MarkSafe(call)])
##############################################
def _render(self, domain, name, additional_classes):
if domain in ('fa', 'fas', 'far', 'fab'):
html_code = '<i class="{} {} {}"></i>'.format(domain, name, ' '.join(additional_classes))
return Markup(html_code)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment