comparison piecrust/processing/tree.py @ 117:6827dcc9d3fb

Changes to the asset processing pipeline: * Add semi-functional RequireJS processor. * Processors now match on the relative path. * Support for processors that add more processors of their own. * A couple of related fixes.
author Ludovic Chabant <ludovic@chabant.com>
date Tue, 28 Oct 2014 08:20:38 -0700
parents 45828c4167ad
children 133845647083
comparison
equal deleted inserted replaced
116:1c13f3389fcb 117:6827dcc9d3fb
32 self.state = STATE_UNKNOWN 32 self.state = STATE_UNKNOWN
33 self._processor = None 33 self._processor = None
34 34
35 def getProcessor(self): 35 def getProcessor(self):
36 if self._processor is None: 36 if self._processor is None:
37 _, filename = os.path.split(self.path)
38 for p in self.available_procs: 37 for p in self.available_procs:
39 if p.matches(filename): 38 if p.matches(self.path):
40 self._processor = p 39 self._processor = p
41 self.available_procs.remove(p) 40 self.available_procs.remove(p)
42 break 41 break
43 else: 42 else:
44 raise ProcessorNotFoundError() 43 raise ProcessorNotFoundError()
83 proc = cur_node.getProcessor() 82 proc = cur_node.getProcessor()
84 83
85 # If the root tree node (and only that one) wants to bypass this 84 # If the root tree node (and only that one) wants to bypass this
86 # whole tree business, so be it. 85 # whole tree business, so be it.
87 if proc.is_bypassing_structured_processing: 86 if proc.is_bypassing_structured_processing:
88 if proc != tree_root: 87 if cur_node != tree_root:
89 raise ProcessingTreeError("Only root processors can " 88 raise ProcessingTreeError("Only root processors can "
90 "bypass structured processing.") 89 "bypass structured processing.")
91 break 90 break
92 91
93 # Get the destination directory and output files. 92 # Get the destination directory and output files.
143 proc = node.getProcessor() 142 proc = node.getProcessor()
144 if proc.is_bypassing_structured_processing: 143 if proc.is_bypassing_structured_processing:
145 try: 144 try:
146 start_time = time.clock() 145 start_time = time.clock()
147 proc.process(full_path, self.out_dir) 146 proc.process(full_path, self.out_dir)
148 print_node(format_timed(start_time, "(bypassing structured processing)")) 147 print_node(
148 node,
149 format_timed(
150 start_time, "(bypassing structured processing)"))
149 return True 151 return True
150 except Exception as e: 152 except Exception as e:
151 raise Exception("Error processing: %s" % node.path) from e 153 raise Exception("Error processing: %s" % node.path) from e
152 154
153 # All outputs of a node must go to the same directory, so we can get 155 # All outputs of a node must go to the same directory, so we can get