Skip to content

Commit

Permalink
remove non-essential page information
Browse files Browse the repository at this point in the history
  • Loading branch information
kjaymiller committed Aug 21, 2019
1 parent f2bf484 commit e781d49
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 21 deletions.
28 changes: 14 additions & 14 deletions render_engine/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import logging



class Page():
"""Base component used to make web pages"""
def __init__(
Expand All @@ -33,13 +32,14 @@ def __init__(

# Set Content from content and/or content_path
self.content_path = content_path if content_path else None

if self.content_path:
_ = Path(self.content_path)
else:
_ = _load_content(content)
content = Path(self.content_path).read_text()

_ = load_content(content)

kwargs.update(_['attrs'])
self.content += _.get('content', None)
self.content = _.get('content', None)
self.template = template

# make properties for all attrs
Expand All @@ -56,20 +56,20 @@ def __init__(
or Path(getattr(self, 'content_path', '/')).stem()
self.slug = slug

@staticmethod
def _load_content(content):
matcher = r'^\w+:'
md_content = content.splitlines()
attrs = {}
def load_content(content):
matcher = r'^\w+:'
md_content = content.splitlines()
attrs = {}

if md_content:
while re.match(matcher, md_content[0]):
line = md_content.pop(0)
line_data = line.split(': ', 1)
key = line_data[0].lower()
value = line_data[-1].rstrip()
attrs[key] = value

return {
'attrs': attrs,
'content': '\n'.join(md_content).strip('\n'),
}
return {
'attrs': attrs,
'content': '\n'.join(md_content).strip('\n'),
}
2 changes: 0 additions & 2 deletions tests/unit_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ def base_page(site_url):
url_suffix = '.html'
return Page(
slug=slug,
url_root=site_url,
url_suffix=url_suffix,
content=content,
custom_val='custom',
)
Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/test_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_engine_route_adds_route_items(base_engine):
def about():
pass

assert base_engine.routes[0].url == 'https://example.com/about.html'
assert base_engine.routes[0].slug == 'about'

def test_engine_config_path_added_to_env(mocker):
"""When a config_path is provided parse the yaml file and add it to configs
Expand Down
4 changes: 0 additions & 4 deletions tests/unit_tests/test_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ def test_page_slug_variants(page):
"""
assert page.slug == 'test'

def test_page_url(base_page):
"""page object has a relative and url"""
assert base_page.url== 'https://example.com/test.html'

def test_page_content_separated_from_attrs(base_page):
"""When given markdown for content convert it to html and return it as markup"""
assert """# Test Header
Expand Down

0 comments on commit e781d49

Please sign in to comment.