A fork of hyde, the static site generation. Some patches will be pushed upstream.
 
 
 

62 lines
1.8 KiB

  1. # -*- coding: utf-8 -*-
  2. """
  3. Depends plugin
  4. /// Experimental: Not working yet.
  5. """
  6. from hyde._compat import basestring
  7. from hyde.plugin import Plugin
  8. class DependsPlugin(Plugin):
  9. """
  10. The plugin class setting explicit dependencies.
  11. """
  12. def __init__(self, site):
  13. super(DependsPlugin, self).__init__(site)
  14. def begin_site(self):
  15. """
  16. Initialize dependencies.
  17. Go through all the nodes and resources to initialize
  18. dependencies at each level.
  19. """
  20. for resource in self.site.content.walk_resources():
  21. self._update_resource(resource)
  22. def _update_resource(self, resource):
  23. """
  24. If the meta data for the resource contains a depends attribute,
  25. this plugin adds an entry to the depends property of the
  26. resource.
  27. The dependency can contain the following template variables:
  28. node, resource, site, context.
  29. The following strings are valid:
  30. '{node.module}/dependencies/{resource.source.name_without_extension}.inc'
  31. '{context.dependency_folder}/{resource.source.name_without_extension}.{site.meta.depext}'
  32. """
  33. depends = []
  34. try:
  35. depends = resource.meta.depends
  36. except AttributeError:
  37. return
  38. if not hasattr(resource, 'depends') or not resource.depends:
  39. resource.depends = []
  40. if isinstance(depends, basestring):
  41. depends = [depends]
  42. for dep in depends:
  43. resource.depends.append(dep.format(node=resource.node,
  44. resource=resource,
  45. site=self.site,
  46. context=self.site.context))
  47. resource.depends = list(set(resource.depends))