A fork of hyde, the static site generation. Some patches will be pushed upstream.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

44 lines
1.2 KiB

  1. # -*- coding: utf-8 -*-
  2. """
  3. Classes, functions and utilties related to hyde layouts
  4. """
  5. import os
  6. from hyde.fs import File, Folder
  7. HYDE_DATA = "HYDE_DATA"
  8. LAYOUTS = "layouts"
  9. class Layout(object):
  10. """
  11. Represents a layout package
  12. """
  13. @staticmethod
  14. def find_layout(layout_name='basic'):
  15. """
  16. Find the layout with a given name.
  17. Search order:
  18. 1. env(HYDE_DATA)
  19. 2. <hyde script path>/layouts/
  20. """
  21. layout_folder = None
  22. if HYDE_DATA in os.environ:
  23. layout_folder = Layout._get_layout_folder(
  24. os.environ[HYDE_DATA], layout_name)
  25. if not layout_folder:
  26. layout_folder = Layout._get_layout_folder(
  27. File(__file__).parent, layout_name)
  28. return layout_folder
  29. @staticmethod
  30. def _get_layout_folder(root, layout_name='basic'):
  31. """
  32. Finds the layout folder from the given root folder.
  33. If it does not exist, return None
  34. """
  35. layouts_folder = Folder(unicode(root)).child_folder(LAYOUTS)
  36. layout_folder = layouts_folder.child_folder(layout_name)
  37. return layout_folder if layout_folder.exists else None