mirror of
https://github.com/searx/searx
synced 2024-12-13 20:50:55 +01:00
[enh] plugins: client side dependency support
This commit is contained in:
parent
f59daa4a4b
commit
dd84814b68
@ -8,6 +8,9 @@ required_attrs = (('name', str),
|
||||
('description', str),
|
||||
('default_on', bool))
|
||||
|
||||
optional_attrs = (('js_dependencies', tuple),
|
||||
('css_dependencies', tuple))
|
||||
|
||||
|
||||
class Plugin():
|
||||
default_on = False
|
||||
@ -30,6 +33,9 @@ class PluginStore():
|
||||
if not hasattr(plugin, plugin_attr) or not isinstance(getattr(plugin, plugin_attr), plugin_attr_type):
|
||||
logger.critical('missing attribute "{0}", cannot load plugin: {1}'.format(plugin_attr, plugin))
|
||||
exit(3)
|
||||
for plugin_attr, plugin_attr_type in optional_attrs:
|
||||
if not hasattr(plugin, plugin_attr) or not isinstance(getattr(plugin, plugin_attr), plugin_attr_type):
|
||||
setattr(plugin, plugin_attr, plugin_attr_type())
|
||||
plugin.id = plugin.name.replace(' ', '_')
|
||||
self.plugins.append(plugin)
|
||||
|
||||
|
@ -9,17 +9,20 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1 , maximum-scale=1.0, user-scalable=1" />
|
||||
{% block meta %}{% endblock %}
|
||||
<title>{% block title %}{% endblock %}searx</title>
|
||||
|
||||
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap.min.css') }}" type="text/css" />
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='css/oscar.min.css') }}" type="text/css" />
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='css/oscar.min.css') }}" type="text/css" />
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='css/leaflet.min.css') }}" type="text/css" />
|
||||
{% for css in styles %}
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename=css) }}" type="text/css" />
|
||||
{% endfor %}
|
||||
|
||||
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
|
||||
<!--[if lt IE 9]>
|
||||
<script src="{{ url_for('static', filename='js/html5shiv.min.js') }}"></script>
|
||||
<script src="{{ url_for('static', filename='js/respond.min.js') }}"></script>
|
||||
<![endif]-->
|
||||
|
||||
|
||||
<link rel="shortcut icon" href="{{ url_for('static', filename='img/favicon.png') }}" />
|
||||
|
||||
{% block styles %}
|
||||
@ -28,7 +31,7 @@
|
||||
{% endblock %}
|
||||
|
||||
<link title="searx" type="application/opensearchdescription+xml" rel="search" href="{{ url_for('opensearch') }}"/>
|
||||
|
||||
|
||||
<script type="text/javascript">
|
||||
searx = {};
|
||||
searx.method = "{{ method or 'POST' }}";
|
||||
@ -79,5 +82,8 @@
|
||||
{% if autocomplete %}<script src="{{ url_for('static', filename='js/typeahead.bundle.min.js') }}"></script>{% endif %}
|
||||
<script src="{{ url_for('static', filename='js/require-2.1.15.min.js') }}"></script>
|
||||
<script src="{{ url_for('static', filename='js/searx.min.js') }}"></script>
|
||||
{% for script in scripts %}
|
||||
<script src="{{ url_for('static', filename=script) }}"></script>
|
||||
{% endfor %}
|
||||
</body>
|
||||
</html>
|
||||
|
@ -301,6 +301,16 @@ def render(template_name, override_theme=None, **kwargs):
|
||||
|
||||
kwargs['cookies'] = request.cookies
|
||||
|
||||
kwargs['scripts'] = set()
|
||||
for plugin in request.user_plugins:
|
||||
for script in plugin.js_dependencies:
|
||||
kwargs['scripts'].add(script)
|
||||
|
||||
kwargs['styles'] = set()
|
||||
for plugin in request.user_plugins:
|
||||
for css in plugin.css_dependencies:
|
||||
kwargs['styles'].add(css)
|
||||
|
||||
return render_template(
|
||||
'{}/{}'.format(kwargs['theme'], template_name), **kwargs)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user