scripts: add modules to render helper

This commit is contained in:
Darks 2023-07-15 20:36:44 +02:00 committed by Eragon
parent 69dcff26ea
commit 4797433dcd
Signed by: Eragon
GPG Key ID: 087126EBFC725006
2 changed files with 14 additions and 4 deletions

View File

@ -1,5 +1,6 @@
{% for s in scripts %}
<script type="text/javascript" src={{url_for('static', filename=s)}}></script>
{% endfor %}
<script type="text/javascript" src='/v5shoutbox.js'></script>
<script type="module" src={{url_for('static', filename='scripts/emoji-picker-element/index.js')}}></script>
{% for m in modules %}
<script type="module" src={{url_for('static', filename=m)}}></script>
{% endfor %}

View File

@ -1,7 +1,7 @@
from flask import render_template
from flask_login import current_user
def render(*args, styles=[], scripts=[], **kwargs):
def render(*args, styles=[], scripts=[], modules=[], **kwargs):
# Pour jouer sur les feuilles de style ou les scripts :
# render('page.html', styles=['-css/form.css', '+css/admin/forms.css'])
@ -29,6 +29,9 @@ def render(*args, styles=[], scripts=[], **kwargs):
'scripts/tag_selector.js',
'scripts/editor.js',
]
modules_ = [
'scripts/emoji-picker-element/index.js',
]
# Apply theme from user settings
theme = current_user.theme if current_user.is_authenticated else ''
@ -56,4 +59,10 @@ def render(*args, styles=[], scripts=[], **kwargs):
if s[0] == '+':
scripts_.append(s[1:])
return render_template(*args, **kwargs, styles=styles_, scripts=scripts_)
for m in modules:
if m[0] == '-':
modules_.remove(m[1:])
if m[0] == '+':
modules_.append(m[1:])
return render_template(*args, **kwargs, styles=styles_, scripts=scripts_, modules=modules_)