Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Pascal MOLIN
lektor-admin-extra
Commits
4134bfa9
Commit
4134bfa9
authored
Mar 29, 2021
by
Pascal
Browse files
protect buttons, docs
parent
646f33f9
Changes
6
Hide whitespace changes
Inline
Side-by-side
README.md
View file @
4134bfa9
# admin-extra
Add facilities for the development server.
Add facilities for the
lektor
development server.
## Help pages
...
...
lektor_admin_extra.py
View file @
4134bfa9
...
...
@@ -4,7 +4,6 @@ from flask import Blueprint, \
url_for
,
\
render_template
from
lektor.pluginsystem
import
Plugin
from
lektor.context
import
get_ctx
from
lektor.admin.modules
import
serve
,
dash
utilsbp
=
Blueprint
(
'utils'
,
__name__
,
...
...
@@ -13,7 +12,7 @@ utilsbp = Blueprint('utils', __name__,
template_folder
=
'templates'
)
def
add_content
(
contents
,
extra_routes
=
[]
):
def
add_content
(
contents
,
extra_routes
=
None
):
"""
insert buttons in html pages
...
...
@@ -48,7 +47,15 @@ class AdminExtraPlugin(Plugin):
""" lektor bug, now fixed #859 """
return
self
.
env
.
plugin_controller
.
emit
(
self
.
id
+
"-"
+
event
,
**
kwargs
)
#pylint: disable=unused-variable
def
on_setup_env
(
self
,
*
args
,
**
extra
):
"""
initialize routes and buttons
top help page redirects to the directory
under self.get_config().get('help_pages')
(which default to /admin-pages)
or a default help page.
"""
config
=
self
.
get_config
()
help_dir
=
config
.
get
(
'help_pages'
,
None
)
...
...
@@ -57,7 +64,7 @@ class AdminExtraPlugin(Plugin):
def
setup_blueprint
():
app
=
current_app
app
.
register_blueprint
(
utilsbp
)
# only if no help pages
# only if no help pages
defined
if
help_dir
is
not
None
:
self
.
add_button
(
help_dir
,
'help'
,
'?'
,
index
=
0
)
else
:
...
...
@@ -80,15 +87,16 @@ class AdminExtraPlugin(Plugin):
return
response
@
utilsbp
.
route
(
'/help'
)
#pylint: disable=unused-variable
def
help
():
pad
=
self
.
env
.
new_pad
()
return
render_template
(
'help.html'
,
this
=
self
.
help_data
,
site
=
pad
)
return
render_template
(
'help.html'
,
this
=
self
.
help_data
,
site
=
pad
,
help_root
=
help_dir
)
#return self.env.render_template('help.html', this=self.help_data)
def
buttons
(
self
,
bp
,
**
kwargs
):
return
[
b
for
b
,
f
in
self
.
right_buttons
[
bp
]
if
f
is
None
or
f
(
**
kwargs
)
]
def
add_button
(
self
,
route
,
title
,
html_entity
,
bp
=
[
'serve'
,
'dash'
],
ignore
=
None
,
index
=
None
):
def
add_button
(
self
,
route
,
title
,
html_entity
,
bp
=
[
'serve'
,
'dash'
],
ignore
=
None
,
index
=
None
):
print
(
"register button %s -> %s"
%
(
title
,
route
))
for
b
in
bp
:
if
index
is
None
or
index
>
len
(
self
.
right_buttons
[
b
]):
...
...
setup.py
View file @
4134bfa9
...
...
@@ -17,18 +17,19 @@ setup(
author
=
'Pascal Molin'
,
author_email
=
'molin.maths@gmail.com'
,
description
=
description
,
keywords
=
'Lektor plugin'
,
keywords
=
'Lektor plugin
admin help
'
,
license
=
'MIT'
,
long_description
=
readme
,
long_description_content_type
=
'text/markdown'
,
name
=
'lektor-admin-extra'
,
packages
=
find_packages
(),
py_modules
=
[
'lektor_admin_extra'
],
#
url='
[link to your repository]
',
url
=
'
http://github.com/pascalmolin/lektor-admin-extra
'
,
version
=
'0.1'
,
classifiers
=
[
'Framework :: Lektor'
,
'Environment :: Plugins'
,
'License :: OSI Approved :: MIT License'
,
],
entry_points
=
{
'lektor.plugins'
:
[
...
...
templates/admin_buttons.html
View file @
4134bfa9
<div
class=
"auth-button-div"
>
{% if buttons %}
{% for (url, title, entity) in buttons %}
<a
href=
"{{ url }}"
title=
"{{ title }}"
>
{{ entity }}
</a>
{% endfor %}
{% endif %}
</div>
{# FIXME: try to remove buttons inside preview iframe... #}
<script>
...
...
templates/help.html
View file @
4134bfa9
...
...
@@ -2,16 +2,20 @@
{% block box %}
<h1>
Aide
</h1>
<div
class=
"container"
>
{% if this.index %}
<h2>
Rubriques
</h2>
<ul>
{% for url, item in this.index %}
<li><a
href=
"{{ url }}"
>
{{ item }}
</a></li>
{% endfor %}
</ul>
{% if site.get('/admin-pages') %}
{% else %}
Aucune page d'aide n'est enregistrée.
{% endif %}
{% if help_root and site.get(help_root) %}
<h2>
Documentation
</h2>
<ul>
{% with prefix =
'/admin-pages'
%}
{% with prefix =
help_root
%}
{% for page in site.get(prefix).children.include_undiscoverable(true) %}
{{ page }}
<li><a
href=
"{{ page.path }}/"
>
{{ page.title }}
</a></li>
...
...
test/test_lektor_admin_extra.py
View file @
4134bfa9
...
...
@@ -51,15 +51,16 @@ def test_webclient_add_serve_button(env, webclient):
def
test_webclient_add_dash_button
(
env
,
webclient
):
from
lektor.pluginsystem
import
get_plugin
plugin
=
get_plugin
(
'admin-extra'
,
env
)
plugin
.
add_dash_button
(
'/devnull'
,
'foobar'
,
'F'
)
plugin
.
add_dash_button
(
'/devnull'
,
'Rnd0m'
,
'F'
)
rv
=
webclient
.
get
(
'/'
)
print
(
rv
.
data
)
assert
b
'
foobar
'
not
in
rv
.
data
assert
b
'
Rnd0m
'
not
in
rv
.
data
rv
=
webclient
.
get
(
'/admin/edit'
)
print
(
rv
.
data
)
assert
b
'
foobar
'
in
rv
.
data
assert
b
'
Rnd0m
'
in
rv
.
data
def
test_server_started
(
anonymous
):
rv
=
anonymous
.
get
(
'/'
,
timeout
=
0.1
)
...
...
@@ -75,6 +76,5 @@ def test_static_file(anonymous):
def
test_help_page
(
anonymous
):
rv
=
anonymous
.
get
(
'/admin-pages/help'
,
timeout
=
0.1
)
assert
'<body>'
in
rv
.
text
assert
'Aide'
in
rv
.
text
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment