mirror of
https://github.com/webrecorder/pywb.git
synced 2025-03-24 06:59:52 +01:00
templates: ensure shared templates are loaded from root templates/ subdir
manager: add shared templates to templates subdir, not root dir #55 and #74
This commit is contained in:
parent
138aed3ddd
commit
4b45e789df
@ -1,8 +1,3 @@
|
|||||||
#collections:
|
|
||||||
# pywb: ./sample_archive/cdx/
|
|
||||||
|
|
||||||
#archive_paths: ./sample_archive/warcs/
|
|
||||||
|
|
||||||
collections_root: collections
|
collections_root: collections
|
||||||
|
|
||||||
paths:
|
paths:
|
||||||
|
@ -217,17 +217,20 @@ directory structure expected by pywb
|
|||||||
'a collection name: template <coll> --{1} {0}')
|
'a collection name: template <coll> --{1} {0}')
|
||||||
raise IOError(msg.format(template_name, verb))
|
raise IOError(msg.format(template_name, verb))
|
||||||
|
|
||||||
full_path = os.path.join(self.templates_dir,
|
full_path = os.path.join(self.templates_dir, os.path.basename(filename))
|
||||||
os.path.basename(filename))
|
|
||||||
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
try:
|
try:
|
||||||
filename = shared_templates[template_name]
|
filename = shared_templates[template_name]
|
||||||
full_path = os.path.join(os.getcwd(),
|
full_path = os.path.join(os.getcwd(), filename)
|
||||||
os.path.basename(filename))
|
|
||||||
|
# Create templates dir on demand
|
||||||
|
dir_ = os.path.dirname(full_path)
|
||||||
|
if not os.path.isdir(dir_):
|
||||||
|
os.makedirs(dir_)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
msg = 'template name must be one of {0} or {1}'
|
msg = 'template name must be one of {0} or {1}'
|
||||||
msg.format(templates.keys(), shared_templates.keys())
|
msg = msg.format(templates.keys(), shared_templates.keys())
|
||||||
raise KeyError(msg)
|
raise KeyError(msg)
|
||||||
|
|
||||||
return full_path, filename
|
return full_path, filename
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<body>
|
||||||
<h2>pywb Wayback Machine</h2>
|
<h2>pywb Wayback Machine</h2>
|
||||||
|
|
||||||
This archive contains the following collections:
|
This archive contains the following collections:
|
||||||
@ -14,4 +17,5 @@ This archive contains the following collections:
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
@ -274,17 +274,13 @@ class TestManagedColls(object):
|
|||||||
resp = self.testapp.get('/test/20140103030321/http://example.com?example=1')
|
resp = self.testapp.get('/test/20140103030321/http://example.com?example=1')
|
||||||
assert resp.status_int == 200
|
assert resp.status_int == 200
|
||||||
|
|
||||||
def test_add_default_templates(self):
|
def test_add_default_coll_templates(self):
|
||||||
""" Test add default templates: shared, collection,
|
""" Test add default templates: collection,
|
||||||
and overwrite collection template
|
and overwrite collection template
|
||||||
"""
|
"""
|
||||||
# list
|
# list
|
||||||
main(['template', 'foo', '--list'])
|
main(['template', 'foo', '--list'])
|
||||||
|
|
||||||
# Add shared template
|
|
||||||
main(['template', '--add', 'home_html'])
|
|
||||||
assert os.path.isfile(os.path.join(self.root_dir, 'index.html'))
|
|
||||||
|
|
||||||
# Add collection template
|
# Add collection template
|
||||||
main(['template', 'foo', '--add', 'query_html'])
|
main(['template', 'foo', '--add', 'query_html'])
|
||||||
assert os.path.isfile(os.path.join(self.root_dir, 'collections', 'foo', 'templates', 'query.html'))
|
assert os.path.isfile(os.path.join(self.root_dir, 'collections', 'foo', 'templates', 'query.html'))
|
||||||
@ -292,6 +288,24 @@ class TestManagedColls(object):
|
|||||||
# overwrite -- force
|
# overwrite -- force
|
||||||
main(['template', 'foo', '--add', 'query_html', '-f'])
|
main(['template', 'foo', '--add', 'query_html', '-f'])
|
||||||
|
|
||||||
|
def test_add_modify_home_template(self):
|
||||||
|
# Add shared template
|
||||||
|
main(['template', '--add', 'home_html'])
|
||||||
|
|
||||||
|
filename = os.path.join(self.root_dir, 'templates', 'index.html')
|
||||||
|
assert os.path.isfile(filename)
|
||||||
|
|
||||||
|
with open(filename, 'r+b') as fh:
|
||||||
|
buf = fh.read()
|
||||||
|
buf = buf.replace('</html>', 'Custom Test Homepage</html>')
|
||||||
|
fh.seek(0)
|
||||||
|
fh.write(buf)
|
||||||
|
|
||||||
|
self._create_app()
|
||||||
|
resp = self.testapp.get('/')
|
||||||
|
assert resp.content_type == 'text/html'
|
||||||
|
assert 'Custom Test Homepage</html>' in resp.body, resp.body
|
||||||
|
|
||||||
@patch('pywb.manager.manager.get_input', lambda x: 'y')
|
@patch('pywb.manager.manager.get_input', lambda x: 'y')
|
||||||
def test_add_template_input_yes(self):
|
def test_add_template_input_yes(self):
|
||||||
""" Test answer 'yes' to overwrite
|
""" Test answer 'yes' to overwrite
|
||||||
|
Loading…
x
Reference in New Issue
Block a user