mirror of https://github.com/huashengdun/webssh
Added class Font
parent
dcbd4a575a
commit
8901eb0580
|
@ -10,7 +10,7 @@ import tornado.options as options
|
|||
from tests.utils import make_tests_data_path
|
||||
from webssh.policy import load_host_keys
|
||||
from webssh.settings import (
|
||||
get_host_keys_settings, get_policy_setting, base_dir, get_font_setting,
|
||||
get_host_keys_settings, get_policy_setting, base_dir, get_font_filename,
|
||||
get_ssl_context, get_trusted_downstream, get_origin_setting, print_version
|
||||
)
|
||||
from webssh.utils import UnicodeType
|
||||
|
@ -170,11 +170,11 @@ class TestSettings(unittest.TestCase):
|
|||
def test_get_font_setting(self):
|
||||
font_dir = os.path.join(base_dir, 'tests', 'data', 'fonts')
|
||||
font = ''
|
||||
self.assertEqual(get_font_setting(font, font_dir), 'fake-font')
|
||||
self.assertEqual(get_font_filename(font, font_dir), 'fake-font')
|
||||
|
||||
font = 'fake-font'
|
||||
self.assertEqual(get_font_setting(font, font_dir), 'fake-font')
|
||||
self.assertEqual(get_font_filename(font, font_dir), 'fake-font')
|
||||
|
||||
font = 'wrong-name'
|
||||
with self.assertRaises(ValueError):
|
||||
get_font_setting(font, font_dir)
|
||||
get_font_filename(font, font_dir)
|
||||
|
|
|
@ -478,8 +478,7 @@ class IndexHandler(MixinHandler, tornado.web.RequestHandler):
|
|||
pass
|
||||
|
||||
def get(self):
|
||||
self.render('index.html', debug=self.debug, font_filename=self.font,
|
||||
font_family=self.font.split('.')[0])
|
||||
self.render('index.html', debug=self.debug, font=self.font)
|
||||
|
||||
@tornado.gen.coroutine
|
||||
def post(self):
|
||||
|
|
|
@ -49,9 +49,23 @@ define('version', type=bool, help='Show version information',
|
|||
|
||||
|
||||
base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
font_dirs = ['webssh', 'static', 'css', 'fonts']
|
||||
max_body_size = 1 * 1024 * 1024
|
||||
|
||||
|
||||
class Font(object):
|
||||
|
||||
def __init__(self, filename, dirs):
|
||||
self.family = self.get_family(filename)
|
||||
self.url = self.get_url(filename, dirs)
|
||||
|
||||
def get_family(self, filename):
|
||||
return filename.split('.')[0]
|
||||
|
||||
def get_url(self, filename, dirs):
|
||||
return os.path.join(*(dirs + [filename]))
|
||||
|
||||
|
||||
def get_app_settings(options):
|
||||
settings = dict(
|
||||
template_path=os.path.join(base_dir, 'webssh', 'templates'),
|
||||
|
@ -59,9 +73,10 @@ def get_app_settings(options):
|
|||
websocket_ping_interval=options.wpintvl,
|
||||
debug=options.debug,
|
||||
xsrf_cookies=options.xsrf,
|
||||
font=get_font_setting(
|
||||
options.font,
|
||||
os.path.join(base_dir, 'webssh', 'static', 'css', 'fonts')
|
||||
font=Font(
|
||||
get_font_filename(options.font,
|
||||
os.path.join(base_dir, *font_dirs)),
|
||||
font_dirs[1:]
|
||||
),
|
||||
origin_policy=get_origin_setting(options)
|
||||
)
|
||||
|
@ -157,7 +172,7 @@ def get_origin_setting(options):
|
|||
return origins
|
||||
|
||||
|
||||
def get_font_setting(font, font_dir):
|
||||
def get_font_filename(font, font_dir):
|
||||
filenames = {f for f in os.listdir(font_dir) if not f.startswith('.')
|
||||
and os.path.isfile(os.path.join(font_dir, f))}
|
||||
if font:
|
||||
|
|
|
@ -24,14 +24,14 @@
|
|||
.btn-danger {
|
||||
margin-left: 5px;
|
||||
}
|
||||
{% if font_filename %}
|
||||
{% if font.url %}
|
||||
@font-face {
|
||||
font-family: '{{font_family}}';
|
||||
src: url('static/css/fonts/{{font_filename}}');
|
||||
font-family: '{{ font.family }}';
|
||||
src: url('{{ font.url }}');
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: '{{font_family}}';
|
||||
font-family: '{{ font.family }}';
|
||||
}
|
||||
{% end %}
|
||||
</style>
|
||||
|
|
Loading…
Reference in New Issue