create a template builder function
This commit is contained in:
parent
133d90116d
commit
e2d3b7c7a2
@ -232,6 +232,50 @@ def init():
|
|||||||
return settings
|
return settings
|
||||||
|
|
||||||
|
|
||||||
|
def get_gallery_templates(theme, gallery_path="", parent_templates=None):
|
||||||
|
if theme:
|
||||||
|
theme_path = os.path.exists(
|
||||||
|
os.path.join(os.path.split(os.path.realpath(__file__))[0], "themes", theme))
|
||||||
|
available_themes = theme, "', '".join(
|
||||||
|
os.listdir(os.path.join(os.path.split(os.path.realpath(__file__))[0],
|
||||||
|
"themes")))
|
||||||
|
|
||||||
|
error(theme_path, "'%s' is not an existing theme, available themes are '%s'" % available_themes)
|
||||||
|
|
||||||
|
templates_dir = [
|
||||||
|
os.path.realpath(os.path.join(os.getcwd(), "templates")),
|
||||||
|
os.path.join(os.path.split(os.path.realpath(__file__))[0], "themes", theme, "templates")
|
||||||
|
]
|
||||||
|
|
||||||
|
if theme != "exposure":
|
||||||
|
templates_dir.append(os.path.join(os.path.split(os.path.realpath(__file__))[0],
|
||||||
|
"themes", "exposure", "templates"))
|
||||||
|
|
||||||
|
subgallery_templates = Environment(loader=FileSystemLoader(templates_dir))
|
||||||
|
else:
|
||||||
|
if parent_templates:
|
||||||
|
theme = "exposure"
|
||||||
|
subgallery_templates = parent_templates
|
||||||
|
else:
|
||||||
|
templates_dir = [
|
||||||
|
os.path.realpath(os.path.join(os.getcwd(), "templates")),
|
||||||
|
os.path.join(os.path.split(os.path.realpath(__file__))[0], "themes", theme, "templates")
|
||||||
|
]
|
||||||
|
subgallery_templates = Environment(loader=FileSystemLoader(templates_dir))
|
||||||
|
|
||||||
|
# XXX recursively merge directories
|
||||||
|
if os.path.exists(os.path.join(os.getcwd(), "build", gallery_path, "static")):
|
||||||
|
shutil.rmtree(os.path.join(os.getcwd(), "build", gallery_path, "static"))
|
||||||
|
|
||||||
|
if os.path.exists(os.path.join(os.getcwd(), "static")):
|
||||||
|
shutil.copytree(os.path.join(os.getcwd(), "static"), os.path.join(os.getcwd(), "build", gallery_path, "static"))
|
||||||
|
else:
|
||||||
|
shutil.copytree(
|
||||||
|
os.path.join(os.path.split(os.path.realpath(__file__))[0], "themes", theme, "static"),
|
||||||
|
os.path.join(os.getcwd(), "build", gallery_path, "static"))
|
||||||
|
return subgallery_templates
|
||||||
|
|
||||||
|
|
||||||
def build_galleries(gallery, settings, templates, parent_galleries=False):
|
def build_galleries(gallery, settings, templates, parent_galleries=False):
|
||||||
|
|
||||||
if parent_galleries:
|
if parent_galleries:
|
||||||
@ -256,7 +300,6 @@ def build_galleries(gallery, settings, templates, parent_galleries=False):
|
|||||||
if not gallery_settings.get("public", True):
|
if not gallery_settings.get("public", True):
|
||||||
build_gallery(settings, gallery_settings, gallery_path, templates)
|
build_gallery(settings, gallery_settings, gallery_path, templates)
|
||||||
else:
|
else:
|
||||||
print "build :" + gallery_path + " : " + gallery
|
|
||||||
error(gallery_settings.get("title"), "Your gallery describe in %s need to have a "
|
error(gallery_settings.get("title"), "Your gallery describe in %s need to have a "
|
||||||
"title" % (os.path.join(gallery, "settings.yaml")))
|
"title" % (os.path.join(gallery, "settings.yaml")))
|
||||||
error(gallery_settings.get("cover"), "You should specify a path to a cover picture "
|
error(gallery_settings.get("cover"), "You should specify a path to a cover picture "
|
||||||
@ -285,38 +328,9 @@ def build_galleries(gallery, settings, templates, parent_galleries=False):
|
|||||||
}
|
}
|
||||||
|
|
||||||
if dirs:
|
if dirs:
|
||||||
subgallery_theme = gallery_settings.get("theme")
|
theme = gallery_settings.get("theme") if gallery_settings.get("theme") else settings.get("theme",
|
||||||
if subgallery_theme:
|
"exposure")
|
||||||
theme_path = os.path.exists(os.path.join(os.path.split(os.path.realpath(__file__))[0], "themes", subgallery_theme))
|
subgallery_templates = get_gallery_templates(theme, gallery_path, templates)
|
||||||
available_themes = subgallery_theme, "', '".join(os.listdir(os.path.join(os.path.split(os.path.realpath(__file__))[0],
|
|
||||||
"themes")))
|
|
||||||
|
|
||||||
error(theme_path, "'%s' is not an existing theme, available themes are '%s'" % available_themes)
|
|
||||||
|
|
||||||
templates_dir = [
|
|
||||||
os.path.realpath(os.path.join(os.getcwd(), "templates")),
|
|
||||||
os.path.join(os.path.split(os.path.realpath(__file__))[0], "themes", subgallery_theme, "templates")
|
|
||||||
]
|
|
||||||
|
|
||||||
if subgallery_theme != "exposure":
|
|
||||||
templates_dir.append(os.path.join(os.path.split(os.path.realpath(__file__))[0],
|
|
||||||
"themes", "exposure", "templates"))
|
|
||||||
|
|
||||||
subgallery_templates = Environment(loader=FileSystemLoader(templates_dir))
|
|
||||||
else:
|
|
||||||
subgallery_theme = settings.get("theme", "exposure")
|
|
||||||
subgallery_templates = templates
|
|
||||||
|
|
||||||
# XXX recursively merge directories
|
|
||||||
if os.path.exists(os.path.join(os.getcwd(), "build", gallery_path, "static")):
|
|
||||||
shutil.rmtree(os.path.join(os.getcwd(), "build", gallery_path, "static"))
|
|
||||||
|
|
||||||
if os.path.exists(os.path.join(os.getcwd(), "static")):
|
|
||||||
shutil.copytree(os.path.join(os.getcwd(), "static"), os.path.join(os.getcwd(), "build", gallery_path, "static"))
|
|
||||||
else:
|
|
||||||
shutil.copytree(os.path.join(os.path.split(os.path.realpath(__file__))[0], "themes", subgallery_theme, "static"),
|
|
||||||
os.path.join(os.getcwd(), "build", gallery_path,"static"))
|
|
||||||
|
|
||||||
sub_page_galleries_cover = []
|
sub_page_galleries_cover = []
|
||||||
|
|
||||||
for subgallery in dirs:
|
for subgallery in dirs:
|
||||||
@ -394,36 +408,10 @@ def main():
|
|||||||
os.makedirs("build")
|
os.makedirs("build")
|
||||||
|
|
||||||
theme = settings["settings"].get("theme", "exposure")
|
theme = settings["settings"].get("theme", "exposure")
|
||||||
|
templates = get_gallery_templates(theme)
|
||||||
theme_path = os.path.exists(os.path.join(os.path.split(os.path.realpath(__file__))[0], "themes", theme))
|
|
||||||
available_themes = theme, "', '".join(os.listdir(os.path.join(os.path.split(os.path.realpath(__file__))[0],
|
|
||||||
"themes")))
|
|
||||||
|
|
||||||
error(theme_path, "'%s' is not an existing theme, available themes are '%s'" % available_themes)
|
|
||||||
|
|
||||||
templates_dir = [
|
|
||||||
os.path.realpath(os.path.join(os.getcwd(), "templates")),
|
|
||||||
os.path.join(os.path.split(os.path.realpath(__file__))[0], "themes", theme, "templates")
|
|
||||||
]
|
|
||||||
|
|
||||||
if theme != "exposure":
|
|
||||||
templates_dir.append(os.path.join(os.path.split(os.path.realpath(__file__))[0],
|
|
||||||
"themes", "exposure", "templates"))
|
|
||||||
|
|
||||||
templates = Environment(loader=FileSystemLoader(templates_dir))
|
|
||||||
templates.add_extension('jinja2.ext.with_')
|
templates.add_extension('jinja2.ext.with_')
|
||||||
feed_template = templates.get_template("feed.xml")
|
feed_template = templates.get_template("feed.xml")
|
||||||
|
|
||||||
# XXX recursively merge directories
|
|
||||||
if os.path.exists(os.path.join(os.getcwd(), "build", "static")):
|
|
||||||
shutil.rmtree(os.path.join(os.getcwd(), "build", "static"))
|
|
||||||
|
|
||||||
if os.path.exists(os.path.join(os.getcwd(), "static")):
|
|
||||||
shutil.copytree(os.path.join(os.getcwd(), "static"), os.path.join(os.getcwd(), "build", "static"))
|
|
||||||
else:
|
|
||||||
shutil.copytree(os.path.join(os.path.split(os.path.realpath(__file__))[0], "themes", theme, "static"),
|
|
||||||
os.path.join(os.getcwd(), "build", "static"))
|
|
||||||
|
|
||||||
for gallery in dirs:
|
for gallery in dirs:
|
||||||
front_page_galleries_cover.append(build_galleries(gallery, settings, templates))
|
front_page_galleries_cover.append(build_galleries(gallery, settings, templates))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user