Create simple load_dialogs function
This function replaces the class since the class doesn't provide any functionalitypull/2422/head
parent
24071cdea0
commit
2697cb8d56
|
@ -133,8 +133,7 @@ class DialogLoader:
|
||||||
self.__renderer = renderer_factory()
|
self.__renderer = renderer_factory()
|
||||||
|
|
||||||
def load(self, dialog_dir):
|
def load(self, dialog_dir):
|
||||||
"""
|
"""Load all dialog files within the specified directory.
|
||||||
Load all dialog files within the specified directory.
|
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
dialog_dir (str): directory that contains dialog files
|
dialog_dir (str): directory that contains dialog files
|
||||||
|
@ -142,18 +141,32 @@ class DialogLoader:
|
||||||
Returns:
|
Returns:
|
||||||
a loaded instance of a dialog renderer
|
a loaded instance of a dialog renderer
|
||||||
"""
|
"""
|
||||||
directory = Path(dialog_dir)
|
return load_dialogs(dialog_dir, self.__renderer)
|
||||||
if not directory.exists() or not directory.is_dir():
|
|
||||||
LOG.warning("No dialog files found: {}".format(dialog_dir))
|
|
||||||
return self.__renderer
|
|
||||||
|
|
||||||
for path, _, files in os.walk(str(directory)):
|
|
||||||
for f in files:
|
def load_dialogs(dialog_dir, renderer=None):
|
||||||
if f.endswith(".dialog"):
|
"""Load all dialog files within the specified directory.
|
||||||
self.__renderer.load_template_file(
|
|
||||||
f.replace('.dialog', ''),
|
Arguments:
|
||||||
join(path, f))
|
dialog_dir (str): directory that contains dialog files
|
||||||
return self.__renderer
|
|
||||||
|
Returns:
|
||||||
|
a loaded instance of a dialog renderer
|
||||||
|
"""
|
||||||
|
if renderer is None:
|
||||||
|
renderer = MustacheDialogRenderer()
|
||||||
|
|
||||||
|
directory = Path(dialog_dir)
|
||||||
|
if not directory.exists() or not directory.is_dir():
|
||||||
|
LOG.warning("No dialog files found: {}".format(dialog_dir))
|
||||||
|
return renderer
|
||||||
|
|
||||||
|
for path, _, files in os.walk(str(directory)):
|
||||||
|
for f in files:
|
||||||
|
if f.endswith(".dialog"):
|
||||||
|
renderer.load_template_file(f.replace('.dialog', ''),
|
||||||
|
join(path, f))
|
||||||
|
return renderer
|
||||||
|
|
||||||
|
|
||||||
def get(phrase, lang=None, context=None):
|
def get(phrase, lang=None, context=None):
|
||||||
|
|
Loading…
Reference in New Issue