Skip to content

Commit

Permalink
Fix _index generation
Browse files Browse the repository at this point in the history
  • Loading branch information
jpsca committed Feb 2, 2013
1 parent 30876d5 commit f73d92c
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 11 deletions.
2 changes: 1 addition & 1 deletion clay/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
from main import Clay


__version__ = '2.4.2'
__version__ = '2.4.3'
8 changes: 5 additions & 3 deletions clay/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,16 @@ def is_html_fragment(self, content):
return not (head.startswith('<!doctype ') or head.startswith('<html'))

def must_be_included(self, path):
return path in self.settings.get('INCLUDE', [])
return path in (self.settings.get('INCLUDE', []) or [])

def must_be_filtered(self, path):
filename = basename(path)
return filename.startswith('.') or path in self.settings.get('FILTER', [])
return filename.startswith('.') or path in \
(self.settings.get('FILTER', []) or [])

def must_filter_fragment(self, content):
return self.settings.get('FILTER_PARTIALS') and self.is_html_fragment(content)
return bool(self.settings.get('FILTER_PARTIALS', True)) \
and self.is_html_fragment(content)

def get_pages_list(self):
pages = []
Expand Down
7 changes: 7 additions & 0 deletions tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ def get_build_path(path):
return join(BUILD_DIR, path)


def create_page(name, content, encoding='utf8'):
sp = get_source_path(name)
make_dirs(dirname(sp))
content = content.encode(encoding)
create_file(sp, content, encoding=encoding)


def read_content(path, encoding='utf8'):
with io.open(path, 'r', encoding=encoding) as f:
return f.read().encode(encoding)
Expand Down
6 changes: 5 additions & 1 deletion tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
def setup_module():
remove_test_dirs()
make_dirs(SOURCE_DIR)
make_dirs(BUILD_DIR)


def teardown_module():
Expand Down Expand Up @@ -42,6 +43,7 @@ def test_build_dir_is_made(c):

def test_build_page(c):
setup_module()
c.settings['FILTER_PARTIALS'] = False

name = 'foo.html'
sp1, bp1 = get_file_paths(name)
Expand Down Expand Up @@ -89,6 +91,7 @@ def test_copy_if_source_is_newer(c):


def test_rename_tmpl_file(c):
c.settings['FILTER_PARTIALS'] = False
setup_module()

name = 'test.txt.tmpl'
Expand All @@ -104,7 +107,7 @@ def test_rename_tmpl_file(c):
def test_settings_as_template_build_context():
setup_module()

c = Clay(TESTS, {'who': u'world'})
c = Clay(TESTS, {'who': u'world', 'FILTER_PARTIALS': False})
t = c.get_test_client()

name = 'test.txt.tmpl'
Expand All @@ -117,6 +120,7 @@ def test_settings_as_template_build_context():


def test_build_all(c):
c.settings['FILTER_PARTIALS'] = False
remove_test_dirs()
make_dirs(SOURCE_DIR, 'sub')

Expand Down
13 changes: 13 additions & 0 deletions tests/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,16 @@ def test_make_dirs_wrong():
make_dirs('/etc/bla')


def test_fix_settings():
remove_test_dirs()
bad_settings = dict(
FILTER_PARTIALS = None,
FILTER = None,
INCLUDE = None,
HOST = None,
PORT = None,
)
c = Clay(TESTS, bad_settings)
create_page('test.html', HTML)
c.get_pages_index()

8 changes: 2 additions & 6 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,11 @@ def teardown_module():

def assert_page(t, name, content=HTML, url=None, encoding='utf8'):
remove_dir(SOURCE_DIR)
sp = get_source_path(name)
make_dirs(dirname(sp))
content = content.encode(encoding)
create_file(sp, content, encoding=encoding)
create_page(name, content, encoding)
url = url or '/' + name

resp = t.get(url)
assert resp.status_code == HTTP_OK
assert content == resp.data
assert content.encode(encoding) == resp.data


def test_setup_with_filename_as_root():
Expand Down

0 comments on commit f73d92c

Please sign in to comment.