diff --git a/hyde/server.py b/hyde/server.py index d46d94e..e956346 100644 --- a/hyde/server.py +++ b/hyde/server.py @@ -61,7 +61,7 @@ class HydeRequestHandler(SimpleHTTPRequestHandler): result = urlparse.urlparse(self.path) logger.info("Trying to load file based on request:[%s]" % result.path) path = result.path.lstrip('/') - res = site.content.resource_from_relative_path(path) + res = site.content.resource_from_relative_deploy_path(path) if not res: # Cannot find the source file using the given path. # Check if the target file exists in the deploy folder. @@ -132,9 +132,9 @@ class HydeWebServer(HTTPServer): Regenerates the entire site. """ try: - logger.info('Generating resource [%]' % resource) + logger.info('Generating resource [%s]' % resource) self.generator.generate_resource(resource) except Exception, exception: logger.error('Error [%s] occured when generating the resource [%s]' - % (resource, repr(exception))) - self.__reinit__() + % (repr(exception), resource)) + raise diff --git a/hyde/site.py b/hyde/site.py index 25b35bc..f6bfaf8 100644 --- a/hyde/site.py +++ b/hyde/site.py @@ -80,6 +80,7 @@ class Resource(Processable): after its been processed. """ self._relative_deploy_path = path + self.site.content.resource_deploy_path_changed(self) relative_deploy_path = property(get_relative_deploy_path, set_relative_deploy_path) @@ -192,7 +193,9 @@ class RootNode(Node): super(RootNode, self).__init__(source_folder) self.site = site self.node_map = {} + self.node_deploy_map = {} self.resource_map = {} + self.resource_deploy_map = {} def node_from_path(self, path): """ @@ -226,6 +229,22 @@ class RootNode(Node): return self.resource_from_path( self.source_folder.child(str(relative_path))) + def resource_deploy_path_changed(self, resource): + """ + Handles the case where the relative deploy path of a + resource has changed. + """ + self.resource_deploy_map[str(resource.relative_deploy_path)] = resource + + def resource_from_relative_deploy_path(self, relative_deploy_path): + """ + Gets the content resource whose deploy path maps to + the given relative path. If no match is found it returns None. + """ + if relative_deploy_path in self.resource_deploy_map: + return self.resource_deploy_map[relative_deploy_path] + return self.resource_from_relative_path(relative_deploy_path) + def add_node(self, a_folder): """ Adds a new node to this folder's hierarchy. diff --git a/hyde/tests/test_site.py b/hyde/tests/test_site.py index 1504990..75e62c5 100644 --- a/hyde/tests/test_site.py +++ b/hyde/tests/test_site.py @@ -53,7 +53,7 @@ def test_node_url(): c = r.add_node(TEST_SITE_ROOT.child_folder('content/blog/2010/december')) assert c.url == '/' + c.relative_path assert c.url == '/blog/2010/december' - + def test_node_full_url(): s = Site(TEST_SITE_ROOT) s.config.base_url = 'http://localhost' @@ -118,6 +118,16 @@ def test_get_resource(): resource = node.get_resource('merry-christmas.html') assert resource == s.content.resource_from_relative_path(Folder(path).child('merry-christmas.html')) +def test_get_resource_from_relative_deploy_path(): + s = Site(TEST_SITE_ROOT) + s.load() + path = 'blog/2010/december' + node = s.content.node_from_relative_path(path) + resource = node.get_resource('merry-christmas.html') + assert resource == s.content.resource_from_relative_deploy_path(Folder(path).child('merry-christmas.html')) + resource.relative_deploy_path = Folder(path).child('merry-christmas.php') + assert resource == s.content.resource_from_relative_deploy_path(Folder(path).child('merry-christmas.php')) + def test_is_processable_default_true(): s = Site(TEST_SITE_ROOT) s.load()