| @@ -50,15 +50,15 @@ class Generator(object): | |||
| logger.info("Configuring the template environment") | |||
| self.template.configure(self.site.config) | |||
| def rebuild_if_needed(self): | |||
| def reload_if_needed(self): | |||
| """ | |||
| Checks if the site requries a rebuild and builds if | |||
| Checks if the site requries a reload and loads if | |||
| necessary. | |||
| """ | |||
| #TODO: Perhaps this is better suited in Site | |||
| if not len(self.site.content.child_nodes): | |||
| logger.info("Reading site contents") | |||
| self.site.build() | |||
| self.site.load() | |||
| def generate_all(self): | |||
| """ | |||
| @@ -66,7 +66,7 @@ class Generator(object): | |||
| """ | |||
| logger.info("Reading site contents") | |||
| self.initialize_template_if_needed() | |||
| self.rebuild_if_needed() | |||
| self.reload_if_needed() | |||
| logger.info("Generating site to [%s]" % | |||
| self.site.config.deploy_root_path) | |||
| @@ -78,7 +78,7 @@ class Generator(object): | |||
| generates the entire site. | |||
| """ | |||
| self.initialize_template_if_needed() | |||
| self.rebuild_if_needed() | |||
| self.reload_if_needed() | |||
| node = None | |||
| if node_path: | |||
| node = self.site.content.node_from_path(node_path) | |||
| @@ -90,7 +90,7 @@ class Generator(object): | |||
| non-existent, generates the entire website. | |||
| """ | |||
| self.initialize_template_if_needed() | |||
| self.rebuild_if_needed() | |||
| self.reload_if_needed() | |||
| if not node: | |||
| return self.generate_all() | |||
| try: | |||
| @@ -104,7 +104,7 @@ class Generator(object): | |||
| generats the entire website. | |||
| """ | |||
| self.initialize_template_if_needed() | |||
| self.rebuild_if_needed() | |||
| self.reload_if_needed() | |||
| resource = None | |||
| if resource_path: | |||
| resource = self.site.content.resource_from_path(resource_path) | |||
| @@ -116,7 +116,7 @@ class Generator(object): | |||
| non-existent, generates the entire website. | |||
| """ | |||
| self.initialize_template_if_needed() | |||
| self.rebuild_if_needed() | |||
| self.reload_if_needed() | |||
| if not resource: | |||
| return self.generate_all() | |||
| try: | |||
| @@ -16,7 +16,7 @@ class Layout(object): | |||
| """ | |||
| @staticmethod | |||
| def find_layout(layout_name="basic"): | |||
| def find_layout(layout_name='basic'): | |||
| """ | |||
| Find the layout with a given name. | |||
| Search order: | |||
| @@ -33,7 +33,7 @@ class Layout(object): | |||
| return layout_folder | |||
| @staticmethod | |||
| def _get_layout_folder(root, layout_name="basic"): | |||
| def _get_layout_folder(root, layout_name='basic'): | |||
| """ | |||
| Finds the layout folder from the given root folder. | |||
| If it does not exist, return None | |||
| @@ -1,5 +1,78 @@ | |||
| # -*- coding: utf-8 -*- | |||
| # 1. start_node | |||
| # 2. start_resource | |||
| # 3. end_resource | |||
| # 4. end_node | |||
| """ | |||
| Contains definition for a plugin protocol and other utiltities. | |||
| """ | |||
| class Plugin(object): | |||
| """ | |||
| The plugin protocol | |||
| """ | |||
| def __init__(self, site): | |||
| super(Plugin, self).__init__() | |||
| self.site = site | |||
| def template_loaded(self, template): | |||
| """ | |||
| Called when the template for the site has been identified. | |||
| """ | |||
| pass | |||
| def prepare_site(self): | |||
| """ | |||
| Called when generation is about to take place. | |||
| """ | |||
| pass | |||
| def site_load_complete(self): | |||
| """ | |||
| Called when the site is built complete. This implies that all the | |||
| nodes and resources have been identified and are accessible in the | |||
| site variable. | |||
| """ | |||
| pass | |||
| def prepare_node(self, node): | |||
| """ | |||
| Called when a node is about to be processed for generation. | |||
| """ | |||
| pass | |||
| def prepare_resource(self, resource, text): | |||
| """ | |||
| Called when a resource is about to be processed for generation. | |||
| The `text` parameter contains the, resource text at this point | |||
| in its lifecycle. It is the text that has been loaded and any | |||
| plugins that are higher in the order may have tampered with it. | |||
| But the text has not been processed by the template yet. | |||
| If this function returns a value, it is used as the text for further | |||
| processing. | |||
| """ | |||
| return text | |||
| def process_resource(self, resource, text): | |||
| """ | |||
| Called when a resource has been processed by the template. | |||
| The `text` parameter contains the, resource text at this point | |||
| in its lifecycle. It is the text that has been processed by the | |||
| template and any plugins that are higher in the order may have | |||
| tampered with it. | |||
| If this function returns a value, it is used as the text for further | |||
| processing. | |||
| """ | |||
| return text | |||
| def node_complete(self, node): | |||
| """ | |||
| Called when all the resources in the node have been processed. | |||
| """ | |||
| pass | |||
| def site_complete(self): | |||
| """ | |||
| Called when the entire site has been processed. | |||
| """ | |||
| pass | |||
| @@ -243,9 +243,9 @@ class RootNode(Node): | |||
| (resource.relative_path, self.source_folder)) | |||
| return resource | |||
| def build(self): | |||
| def load(self): | |||
| """ | |||
| Walks the `source_folder` and builds the sitemap. | |||
| Walks the `source_folder` and loads the sitemap. | |||
| Creates nodes and resources, reads metadata and injects attributes. | |||
| This is the model for hyde. | |||
| """ | |||
| @@ -276,9 +276,9 @@ class Site(object): | |||
| self.config = config if config else Config(self.sitepath) | |||
| self.content = RootNode(self.config.content_root_path, self) | |||
| def build(self): | |||
| def load(self): | |||
| """ | |||
| Walks the content and media folders to build up the sitemap. | |||
| Walks the content and media folders to load up the sitemap. | |||
| """ | |||
| self.content.build() | |||
| self.content.load() | |||
| @@ -27,7 +27,7 @@ def delete_test_site(): | |||
| @with_setup(create_test_site, delete_test_site) | |||
| def test_generate_resource_from_path(): | |||
| site = Site(TEST_SITE) | |||
| site.build() | |||
| site.load() | |||
| gen = Generator(site) | |||
| gen.generate_resource_at_path(TEST_SITE.child('content/about.html')) | |||
| about = File(Folder(site.config.deploy_root_path).child('about.html')) | |||
| @@ -52,9 +52,9 @@ def test_node_relative_path(): | |||
| c = r.add_node(TEST_SITE_ROOT.child_folder('content/blog/2010/december')) | |||
| assert c.relative_path == 'blog/2010/december' | |||
| def test_build(): | |||
| def test_load(): | |||
| s = Site(TEST_SITE_ROOT) | |||
| s.build() | |||
| s.load() | |||
| path = 'blog/2010/december' | |||
| node = s.content.node_from_relative_path(path) | |||
| assert node | |||
| @@ -67,7 +67,7 @@ def test_build(): | |||
| def test_walk_resources(): | |||
| s = Site(TEST_SITE_ROOT) | |||
| s.build() | |||
| s.load() | |||
| pages = [page.name for page in s.content.walk_resources()] | |||
| expected = ["404.html", | |||
| "about.html", | |||
| @@ -98,9 +98,9 @@ class TestSiteWithConfig(object): | |||
| def teardown_class(cls): | |||
| cls.SITE_PATH.delete() | |||
| def test_build_with_config(self): | |||
| def test_load_with_config(self): | |||
| s = Site(self.SITE_PATH, config = self.config) | |||
| s.build() | |||
| s.load() | |||
| path = 'blog/2010/december' | |||
| node = s.content.node_from_relative_path(path) | |||
| assert node | |||