rename journal module to pages
this better represents the general purpose of this module, rather than just "journal" stuff (though that will likely be a use)
This commit is contained in:
parent
a5b15d8187
commit
fe0ca7d90b
@ -35,7 +35,7 @@ def create_app(instance_path=None, test_config=None):
|
||||
def log_request():
|
||||
logger.info("REQUEST: [ %s ]", request.path)
|
||||
|
||||
from . import journal
|
||||
app.register_blueprint(journal.bp)
|
||||
from . import pages
|
||||
app.register_blueprint(pages.bp)
|
||||
|
||||
return app
|
||||
|
@ -1,4 +1,4 @@
|
||||
"""Journal functionality."""
|
||||
"""General page functionality."""
|
||||
import logging
|
||||
|
||||
import markdown
|
||||
@ -6,15 +6,15 @@ from flask import Blueprint, Markup, abort, current_app as app, render_template
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
bp = Blueprint('journal', __name__, url_prefix='/')
|
||||
bp = Blueprint('pages', __name__, url_prefix='/')
|
||||
md = markdown.Markdown(extensions=['meta'])
|
||||
|
||||
|
||||
@bp.route('/', defaults={'path': 'index'})
|
||||
@bp.route('/<path:path>')
|
||||
def display_journal_entry(path):
|
||||
def display_page(path):
|
||||
"""Get the file contents of the requested path and render the file."""
|
||||
resolved_path = journal_file_resolver(path)
|
||||
resolved_path = page_file_resolver(path)
|
||||
logger.info("received request for path '%s', resolved to '%s'", path, resolved_path)
|
||||
try:
|
||||
with app.open_instance_resource(resolved_path, 'r') as entry_file:
|
||||
@ -30,8 +30,8 @@ def display_journal_entry(path):
|
||||
return render_template('base.html', title=title, content=content)
|
||||
|
||||
|
||||
def journal_file_resolver(path):
|
||||
"""Manipulate the request path to find appropriate journal files.
|
||||
def page_file_resolver(path):
|
||||
"""Manipulate the request path to find appropriate page file.
|
||||
|
||||
* convert dir requests to index files
|
||||
|
||||
@ -40,5 +40,5 @@ def journal_file_resolver(path):
|
||||
"""
|
||||
if path.endswith('/'):
|
||||
path = f'{path}index'
|
||||
path = f'journal/{path}.md'
|
||||
path = f'pages/{path}.md'
|
||||
return path
|
@ -13,7 +13,7 @@ LOGGING = {
|
||||
},
|
||||
},
|
||||
'loggers': {
|
||||
'incorporealcms.journal': {
|
||||
'incorporealcms.pages': {
|
||||
'level': 'DEBUG',
|
||||
'handlers': ['console'],
|
||||
},
|
||||
|
@ -1,38 +0,0 @@
|
||||
"""Test journal views and helper methods."""
|
||||
from incorporealcms.journal import journal_file_resolver
|
||||
|
||||
|
||||
def test_journal_file_resolver_dir_to_index():
|
||||
assert journal_file_resolver('foo/') == 'journal/foo/index.md'
|
||||
|
||||
|
||||
def test_journal_file_resolver_subdir_to_index():
|
||||
assert journal_file_resolver('foo/bar/') == 'journal/foo/bar/index.md'
|
||||
|
||||
|
||||
def test_journal_file_resolver_other_requests_fine():
|
||||
assert journal_file_resolver('foo/baz') == 'journal/foo/baz.md'
|
||||
|
||||
|
||||
def test_journal_file_that_exists(client):
|
||||
response = client.get('/')
|
||||
assert response.status_code == 200
|
||||
assert b'<h1>test index</h1>' in response.data
|
||||
|
||||
|
||||
def test_journal_file_that_doesnt_exist(client):
|
||||
response = client.get('/ohuesthaoeusth')
|
||||
assert response.status_code == 404
|
||||
|
||||
|
||||
def test_journal_file_with_title_metadata(client):
|
||||
response = client.get('/')
|
||||
assert response.status_code == 200
|
||||
assert b'<title>Index - incorporeal.org</title>' in response.data
|
||||
|
||||
|
||||
def test_journal_file_without_title_metadata(client):
|
||||
response = client.get('/no-title')
|
||||
assert response.status_code == 200
|
||||
assert b'<title>incorporeal.org</title>' in response.data
|
||||
assert b'<h1>this page doesn\'t have a title!</h1>' in response.data
|
38
tests/test_pages.py
Normal file
38
tests/test_pages.py
Normal file
@ -0,0 +1,38 @@
|
||||
"""Test page views and helper methods."""
|
||||
from incorporealcms.pages import page_file_resolver
|
||||
|
||||
|
||||
def test_page_file_resolver_dir_to_index():
|
||||
assert page_file_resolver('foo/') == 'pages/foo/index.md'
|
||||
|
||||
|
||||
def test_page_file_resolver_subdir_to_index():
|
||||
assert page_file_resolver('foo/bar/') == 'pages/foo/bar/index.md'
|
||||
|
||||
|
||||
def test_page_file_resolver_other_requests_fine():
|
||||
assert page_file_resolver('foo/baz') == 'pages/foo/baz.md'
|
||||
|
||||
|
||||
def test_page_that_exists(client):
|
||||
response = client.get('/')
|
||||
assert response.status_code == 200
|
||||
assert b'<h1>test index</h1>' in response.data
|
||||
|
||||
|
||||
def test_page_that_doesnt_exist(client):
|
||||
response = client.get('/ohuesthaoeusth')
|
||||
assert response.status_code == 404
|
||||
|
||||
|
||||
def test_page_with_title_metadata(client):
|
||||
response = client.get('/')
|
||||
assert response.status_code == 200
|
||||
assert b'<title>Index - incorporeal.org</title>' in response.data
|
||||
|
||||
|
||||
def test_page_without_title_metadata(client):
|
||||
response = client.get('/no-title')
|
||||
assert response.status_code == 200
|
||||
assert b'<title>incorporeal.org</title>' in response.data
|
||||
assert b'<h1>this page doesn\'t have a title!</h1>' in response.data
|
Loading…
Reference in New Issue
Block a user