Skip to content

Commit

Permalink
v0.13.5 - Feature/add conf template var download dir (#39)
Browse files Browse the repository at this point in the history
* Add template var download_dir.

* v0.13.5
  • Loading branch information
zhaoye authored Sep 21, 2018
1 parent 5a2751c commit 38749a6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
4 changes: 2 additions & 2 deletions lyrebird/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def update_conf(self, path):
def read(self):
template_env = jinja2.Environment(loader=jinja2.FileSystemLoader(str(self.root)))
template = template_env.get_template(self.conf_file.name)
custom_config = json.loads(template.render(current_dir=str(self.root)))
custom_config = json.loads(template.render(current_dir=str(self.root), download_dir=str(self.ROOT/'downloads')))
self.config.update(custom_config)

def save(self):
Expand All @@ -86,7 +86,7 @@ def write_base_config(self):
def read_base_config(self):
template_env = jinja2.Environment(loader=jinja2.FileSystemLoader(str(self.ROOT)))
template = template_env.get_template('conf.json')
base_config = json.loads(template.render(current_dir=str(self.root)))
base_config = json.loads(template.render(current_dir=str(self.root), download_dir=str(self.ROOT/'downloads')))
return base_config


Expand Down
27 changes: 16 additions & 11 deletions lyrebird/mock/blueprints/ui.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import os
from flask import render_template, Blueprint

import traceback
from lyrebird.mock import context
from lyrebird import log
from ... import version
from .. import plugin_manager
from bs4 import BeautifulSoup
Expand All @@ -11,21 +12,25 @@

ui = Blueprint('ui', __name__, url_prefix='/ui', template_folder='../templates', static_folder='../static')

logger = log.get_logger()

def render_with_plugin(template_name_or_list, **context):
web_plugins = []
icon = ''
for web_plugin_name in plugin_manager.web_plugins:
obj = plugin_manager.web_plugins[web_plugin_name]
if hasattr(obj, "index") and not obj.index():
continue
if hasattr(obj, "get_icon"):
icon = obj.get_icon()
if hasattr(obj, 'get_title'):
title = obj.get_title()
else:
title = web_plugin_name.capitalize()
web_plugins.append({'name': web_plugin_name, 'icon': icon, 'title': title})
try:
obj = plugin_manager.web_plugins[web_plugin_name]
if hasattr(obj, "index") and not obj.index():
continue
if hasattr(obj, "get_icon"):
icon = obj.get_icon()
if hasattr(obj, 'get_title'):
title = obj.get_title()
else:
title = web_plugin_name.capitalize()
web_plugins.append({'name': web_plugin_name, 'icon': icon, 'title': title})
except Exception:
logger.error(f'Load web plugin error. {traceback.format_exc()}')
return render_template(template_name_or_list, web_plugins=web_plugins, version=version.VERSION, **context)


Expand Down
2 changes: 1 addition & 1 deletion lyrebird/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
IVERSION = (0, 13, 4)
IVERSION = (0, 13, 5)
VERSION = ".".join(str(i) for i in IVERSION)
LYREBIRD = "Lyrebird " + VERSION

0 comments on commit 38749a6

Please sign in to comment.