Browse Source

Issue #80: Added ability to ignore nodes as well

* Ignores .hg, .svn, .git by default
* Additional nodes can be ignored by adding to site.config.ignore
main
Lakshmi Vyasarajan 13 years ago
parent
commit
e4963b1c78
5 changed files with 38 additions and 11 deletions
  1. +2
    -2
      README.rst
  2. +1
    -1
      hyde/model.py
  3. +13
    -5
      hyde/site.py
  4. +1
    -1
      hyde/tests/test_model.py
  5. +21
    -2
      hyde/tests/test_site.py

+ 2
- 2
README.rst View File

@@ -134,8 +134,8 @@ A brief list of features
them in the templates. them in the templates.
3. Organization: The sorter, grouper and tagger plugins provide rich 3. Organization: The sorter, grouper and tagger plugins provide rich
meta-data driven organizational capabilities to hyde sites. meta-data driven organizational capabilities to hyde sites.
4. Publishing: Hyde sites can be published to variety of targets including: 4. Publishing: Hyde sites can be published to variety of targets including
github pages, Amazon S3 & SFTP. github pages, Amazon S3 & SFTP.


Links Links
----- -----


+ 1
- 1
hyde/model.py View File

@@ -150,7 +150,7 @@ class Config(Expando):
base_url="/", base_url="/",
not_found='404.html', not_found='404.html',
plugins = [], plugins = [],
ignore = [ "*~", "*.bak" ] ignore = [ "*~", "*.bak", ".hg", ".git", ".svn"]
) )
self.config_file = config_file self.config_file = config_file
self.config_dict = config_dict self.config_dict = config_dict


+ 13
- 5
hyde/site.py View File

@@ -351,16 +351,24 @@ class RootNode(Node):


with self.source_folder.walker as walker: with self.source_folder.walker as walker:


def dont_ignore(name):
for pattern in self.site.config.ignore:
if fnmatch.fnmatch(name, pattern):
return False
return True

@walker.folder_visitor @walker.folder_visitor
def visit_folder(folder): def visit_folder(folder):
self.add_node(folder) if dont_ignore(folder.name):
self.add_node(folder)
else:
logger.debug("Ignoring node: %s" % folder.name)
return False


@walker.file_visitor @walker.file_visitor
def visit_file(afile): def visit_file(afile):
for pattern in self.site.config.ignore: if dont_ignore(afile.name):
if fnmatch.fnmatch(afile.name, pattern): self.add_resource(afile)
return
self.add_resource(afile)


class Site(object): class Site(object):
""" """


+ 1
- 1
hyde/tests/test_model.py View File

@@ -111,7 +111,7 @@ class TestConfig(object):
assert hasattr(c, 'plugins') assert hasattr(c, 'plugins')
assert len(c.plugins) == 0 assert len(c.plugins) == 0
assert hasattr(c, 'ignore') assert hasattr(c, 'ignore')
assert c.ignore == ["*~", "*.bak"] assert c.ignore == ["*~", "*.bak", ".hg", ".git", ".svn"]
assert c.deploy_root_path == TEST_SITE.child_folder('deploy') assert c.deploy_root_path == TEST_SITE.child_folder('deploy')
assert c.not_found == '404.html' assert c.not_found == '404.html'




+ 21
- 2
hyde/tests/test_site.py View File

@@ -236,13 +236,32 @@ class TestSiteWithConfig(object):
assert resource.full_url == "/media/" + path assert resource.full_url == "/media/" + path


def test_config_ignore(self): def test_config_ignore(self):
s = Site(self.SITE_PATH, config=self.config) c = Config(self.SITE_PATH, config_dict=self.config.to_dict())
s = Site(self.SITE_PATH, config=c)
s.load() s.load()
path = 'apple-touch-icon.png' path = 'apple-touch-icon.png'
resource = s.content.resource_from_relative_path(path) resource = s.content.resource_from_relative_path(path)
assert resource assert resource
assert resource.full_url == "/" + path assert resource.full_url == "/" + path
s = Site(self.SITE_PATH, config=self.config) s = Site(self.SITE_PATH, config=c)
s.config.ignore.append('*.png') s.config.ignore.append('*.png')
resource = s.content.resource_from_relative_path(path) resource = s.content.resource_from_relative_path(path)
assert not resource assert not resource

def test_config_ignore_nodes(self):
c = Config(self.SITE_PATH, config_dict=self.config.to_dict())
git = self.SITE_PATH.child_folder('.git')
git.make()
s = Site(self.SITE_PATH, config=c)
s.load()
git_node = s.content.node_from_relative_path('.git')
assert not git_node
blog_node = s.content.node_from_relative_path('blog')
assert blog_node
assert blog_node.full_url == "/blog"
s = Site(self.SITE_PATH, config=c)
s.config.ignore.append('blog')
blog_node = s.content.node_from_relative_path('blog')
assert not blog_node
git_node = s.content.node_from_relative_path('.git')
assert not git_node

||||||
x
 
000:0
Loading…
Cancel
Save