Commit ec02ecdc authored by Pascal's avatar Pascal
Browse files

initial commit

parents
dist
build
*.pyc
*.pyo
*.egg-info
# admin-extra
Add extra buttons and messages to lektor admin panel.
# -*- coding: utf-8 -*-
from lektor.pluginsystem import Plugin
from flask import Blueprint, \
current_app, \
url_for, \
render_template
from lektor.admin.modules import serve, dash
utilsbp = Blueprint('utils', __name__,
url_prefix='/admin-pages',
static_folder='static',
template_folder='templates'
)
@utilsbp.route('/help')
def help():
return render_template('help.html')
def add_content(contents, extra_routes=[]):
"""
insert buttons in html pages
see rewrite_html_for_editing in lektor/admin/modules/serve.py
"""
head_endpos = contents.find(b'</head>')
body_endpos = contents.find(b'</body>')
if head_endpos >= 0 and body_endpos >= 0:
# html page
return bytes(contents[:head_endpos] +
render_template('admin_style.html').encode('utf-8') +
contents[head_endpos:body_endpos] +
render_template('admin_messages.html').encode('utf-8') +
render_template('admin_buttons.html', buttons=extra_routes).encode('utf-8') +
contents[body_endpos:])
# dash or iframe ?
return bytes(contents +
render_template('admin_style.html').encode('utf-8') +
render_template('admin_buttons.html', buttons=extra_routes).encode('utf-8')
)
class AdminExtraPlugin(Plugin):
name = 'admin-extra'
description = u'Add buttons on lektor admin pages.'
states = ['all', 'dash' ]
right_buttons = [ ]
def on_setup_env(self, *args, **extra):
@serve.bp.before_app_first_request
def setup_blueprint():
app = current_app
app.register_blueprint(utilsbp)
self.add_button( url_for('utils.help'), 'help', '?' )
@serve.bp.after_request
#pylint: disable=unused-variable
def after_request_serve(response):
if response.mimetype == "text/html":
response.direct_passthrough = False
response.set_data(add_content(response.get_data(),self.buttons()))
return response
@dash.bp.after_request
#pylint: disable=unused-variable
def after_request_dash(response):
if response.mimetype == "text/html":
response.direct_passthrough = False
response.set_data(add_content(response.get_data(),self.buttons()))
return response
def add_button(self, route, title, html_entity, ignore = None):
self.right_buttons.append( ((route, title, html_entity), ignore) )
def buttons(self, **kwargs):
return [ b for b,f in self.right_buttons if f is None or f(**kwargs) ]
[bdist_wheel]
universal=1
[tool:pytest]
addopts = -v
testpaths =
test
project = /Users/pascal/git/lektor-test-site/
import ast
import io
import re
from setuptools import setup, find_packages
with io.open('README.md', 'rt', encoding="utf8") as f:
readme = f.read()
_description_re = re.compile(r'description\s+=\s+(?P<description>.*)')
with open('lektor_admin_extra.py', 'rb') as f:
description = str(ast.literal_eval(_description_re.search(
f.read().decode('utf-8')).group(1)))
setup(
author='Pascal Molin',
author_email='molin.maths@gmail.com',
description=description,
keywords='Lektor plugin',
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]',
version='0.1',
classifiers=[
'Framework :: Lektor',
'Environment :: Plugins',
],
entry_points={
'lektor.plugins': [
'admin-extra = lektor_admin_extra:AdminExtraPlugin',
]
}
)
.auth-button-div {
position: fixed;
z-index: 9999999;
right: 10px;
top: 60px;
position: fixed;
width: 50px;
}
.auth-button-div a {
display: block;
margin: 0;
font-family: 'Verdana', sans-serif;
background: #eee;
color: #77304c;
font-weight: normal;
font-size: 32px;
padding: 0;
text-decoration: none!important;
border: 1px solid #ccc!important;
width: 40px;
height: 40px;
line-height: 40px;
text-align: center;
opacity: 0.7;
}
.auth-button-div a:hover {
background: white!important;
opacity: 1.0;
border: 1px solid #aaa!important;
}
<div class="auth-button-div">
{% if session.get('token') %}
<a href="{{ url_for('auth.logout') }}" title="logout"><i class="fa fa-power-off"></i></a>
{#
<a href="{{ url_for('auth.logout') }}" title="logout">&#x23FB;</a>
<a href="{{ url_for('auth.logout') }}" title="logout">\uf011</a>
#}
{% endif %}
{% for (url, title, entity) in buttons %}
<a href="{{ url }}" title="{{ title }}">{{ entity }}</a>
{% endfor %}
</div>
{# and remove buttons inside preview iframe... #}
<script>
document.querySelector("iframe").addEventListener( "load", function(e) {
return;
var iframe = document.querySelector("iframe");
var inner = iframe.contentDocument || iframe.contentWindow.document;
var divs = inner.getElementsByClassName('auth-button-div');
if (divs) divs[0].parentNode.removeChild(divs[0]);
//var divs = inner.getElementsByClassName('auth-flashes');
//if (divs) divs[0].parentNode.removeChild(divs[0]);
});
</script>
{% with messages = get_flashed_messages(with_categories=True) %}
{% if messages %}
<ul class="auth-flashes">
{% for cat, message in messages %}
<li class="{{ cat }}">
<span aria-hidden="true" class="close-button" onclick='this.parentNode.parentNode.removeChild(this.parentNode); return false;'>
&times;</span>
{{ message }}
</li>
{% endfor %}
</ul>
{% endif %}
{% endwith %}
<style>
.auth-button-div {
position: fixed;
z-index: 9999999;
right: 10px;
top: 60px;
position: fixed;
width: 40px;
}
.auth-button-div a {
display: block;
margin: 0;
margin-bottom: 10px;
font-family: 'Verdana', sans-serif;
background: #eee;
color: #77304c;
font-weight: normal;
font-size: 32px;
padding: 0;
text-decoration: none!important;
border: 1px solid #ccc!important;
width: 40px;
height: 40px;
line-height: 40px;
text-align: center;
opacity: 0.7;
}
.auth-button-div a:hover {
background: white!important;
opacity: 1.0;
border: 1px solid #aaa!important;
}
.auth-flashes {
position: fixed;
z-index: 9999999;
right: 80px;
top: 10px;
position: fixed;
}
.auth-flashes li {
display: block;
background: #eee;
color: #77304c;
text-align: center;
margin-bottom: 10px;
font-family: 'Verdana', sans-serif;
padding: 10px;
font-weight: normal;
font-size: 14px;
}
.auth-flashes li.error {
color: #aa506c;
}
.auth-flashes li>span {
cursor: pointer;
float:right;
font-weight: 600;
margin: 0 4px 0 10px;
/*background:#ccc;*/
}
</style>
<!DOCTYPE HTML>
<html lang="fr">
<head>
<link rel="stylesheet" href="{{url_for('utils.static', filename='login.css')}}">
</head>
<body>
<div>
<h1>Aide</h1>
</div>
<div class="container">
Pour modifier ces pages, vous devez être enregistré
comme éditeur.
</div>
<body>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment