Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add the ability to remove combined resources from processing.

A new keyword `remove` allows to not deploy resources that have been
combined. Small rework on how the plugin work to remove one change
from hyde generator about dependencies handling.
  • Loading branch information...
commit 02d256f353de085a6c641008ff35453ad27821a7 1 parent a3c4e13
@vincentbernat vincentbernat authored committed
Showing with 53 additions and 19 deletions.
  1. +52 −18 hyde/ext/plugins/combine.py
  2. +1 −1  hyde/generator.py
View
70 hyde/ext/plugins/combine.py
@@ -17,41 +17,34 @@ class CombinePlugin(Plugin):
- ns1.*.js
- ns2.*.js
where: top
+ remove: yes
`files` is a list of resources (or just a resource) that should be
combined. Globbing is performed. `where` indicate where the
combination should be done. This could be `top` or `bottom` of the
- file.
+ file. `remove` tell if we should remove resources that have been
+ combined into the resource.
"""
def __init__(self, site):
super(CombinePlugin, self).__init__(site)
- def begin_text_resource(self, resource, text):
+ def _combined(self, resource):
"""
- When generating a resource, add combined file if needed.
+ Return the list of resources to combine to build this one.
"""
- # Grab configuration
try:
config = resource.meta.combine
except AttributeError:
- return
- # Grab file list
+ return [] # Not a combined resource
try:
files = config.files
except AttributeError:
raise "No resources to combine for [%s]" % resource
if type(files) is str:
files = [ files ]
- where = "bottom"
- try:
- where = config.where
- except AttributeError:
- pass
-
- if where not in [ "top", "bottom" ]:
- raise ValueError("%r should be either `top` or `bottom`" % where)
+ # Grab resources to combine
resources = []
for r in resource.node.resources:
for f in files:
@@ -60,14 +53,55 @@ def begin_text_resource(self, resource, text):
break
if not resources:
self.logger.debug("No resources to combine for [%s]" % resource)
+ return []
+
+ return resources
+
+ def begin_site(self):
+ """
+ Initialize the plugin and search for the combined resources
+ """
+ for node in self.site.content.walk():
+ for resource in node.resources:
+ resources = self._combined(resource)
+ if not resources:
+ continue
+
+ # Build depends
+ if not hasattr(resource, 'depends'):
+ resource.depends = []
+ resource.depends.extend(
+ [r.relative_path for r in resources
+ if r.relative_path not in resource.depends])
+
+ # Remove combined resources if needed
+ if hasattr(resource.meta.combine, "remove") and \
+ resource.meta.combine.remove:
+ for r in resources:
+ self.logger.debug(
+ "Resource [%s] removed because combined" % r)
+ r.is_processable = False
+
+ def begin_text_resource(self, resource, text):
+ """
+ When generating a resource, add combined file if needed.
+ """
+ resources = self._combined(resource)
+ if not resources:
return
+
+ where = "bottom"
+ try:
+ where = resource.meta.combine.where
+ except AttributeError:
+ pass
+
+ if where not in [ "top", "bottom" ]:
+ raise ValueError("%r should be either `top` or `bottom`" % where)
+
self.logger.debug(
"Combining %d resources for [%s]" % (len(resources),
resource))
- if not hasattr(resource, 'depends'):
- resource.depends = []
- resource.depends.extend([r.relative_path for r in resources
- if r.relative_path not in resource.depends])
if where == "top":
return "".join([r.source.read_all() for r in resources] + [text])
else:
View
2  hyde/generator.py
@@ -302,6 +302,7 @@ def __generate_resource__(self, resource, incremental=False):
logger.debug("Processing [%s]", resource)
with self.context_for_resource(resource) as context:
if resource.source_file.is_text:
+ self.update_deps(resource)
if resource.uses_template:
logger.debug("Rendering [%s]", resource)
try:
@@ -321,7 +322,6 @@ def __generate_resource__(self, resource, incremental=False):
resource.relative_deploy_path))
target.parent.make()
target.write(text)
- self.update_deps(resource)
else:
logger.debug("Copying binary file [%s]", resource)
self.events.begin_binary_resource(resource)
Please sign in to comment.
Something went wrong with that request. Please try again.