Skip to content

Commit 57a5318

Browse files
kjaymillerRuff
and
Ruff
authored
Create a New Entry (#11)
* create_new_entry * Format and lint with Ruff * add tests * Format and lint with Ruff --------- Co-authored-by: Ruff <[email protected]>
1 parent 9beedc4 commit 57a5318

File tree

4 files changed

+57
-1
lines changed

4 files changed

+57
-1
lines changed

Diff for: README.md

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ Some pages will be looking for information that is provided in the frontmatter.
1313
> **NOTE**
1414
> These attributes **CANNOT** be used in the content itself, but you can use them in the template generation.
1515
16-
1716
## Parsing the Data
1817

1918
The base parser doesn't is a pass-thru parser meaning the content input will be passed through.

Diff for: render_engine_parser/base_parsers.py

+16
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,19 @@ def parse(
6262
extras: dictionary with extras to augment attributes
6363
"""
6464
return content
65+
66+
@staticmethod
67+
def create_entry(*, filepath: pathlib.Path | None, content: str = "Hello World", **kwargs) -> str:
68+
"""
69+
Writes the content type that would be parsed to the content_path.
70+
71+
attrs:
72+
filepath: Only used if reading from an existing path
73+
"""
74+
75+
post = frontmatter.Post(content)
76+
77+
for key, val in kwargs.items():
78+
post[key] = val
79+
80+
return frontmatter.dumps(post)

Diff for: requirements.txt

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#
2+
# This file is autogenerated by pip-compile with Python 3.13
3+
# by the following command:
4+
#
5+
# pip-compile --extra=dev
6+
#
7+
coverage[toml]==7.6.1
8+
# via pytest-cov
9+
iniconfig==2.0.0
10+
# via pytest
11+
packaging==24.1
12+
# via pytest
13+
pluggy==1.5.0
14+
# via pytest
15+
pytest==8.3.2
16+
# via
17+
# pytest-cov
18+
# render_engine_parser (pyproject.toml)
19+
pytest-cov==5.0.0
20+
# via render_engine_parser (pyproject.toml)
21+
python-frontmatter==1.1.0
22+
# via render_engine_parser (pyproject.toml)
23+
pyyaml==6.0.2
24+
# via python-frontmatter
25+
ruff==0.6.4
26+
# via render_engine_parser (pyproject.toml)

Diff for: tests/test_base_parser.py

+15
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import frontmatter
12
import pytest
23

34
from render_engine_parser.base_parsers import BasePageParser, parse_content
@@ -52,3 +53,17 @@ def test_base_parser_parse_content_path(base_content_path):
5253

5354
expected_result = ({"title": "This is a Test"}, "# This is a Test")
5455
assert expected_result == BasePageParser.parse_content_path(base_content_path)
56+
57+
58+
def test_base_parser_net_entry():
59+
data = BasePageParser.create_entry(
60+
filepath=None, # reminder this is ignored in the base case
61+
content="This is a Test",
62+
title="Untitled Entry",
63+
slug="untitled-entry",
64+
)
65+
66+
post = frontmatter.loads(data)
67+
assert post["title"] == "Untitled Entry"
68+
assert post["slug"] == "untitled-entry"
69+
assert post.content == "This is a Test"

0 commit comments

Comments
 (0)