Add a class that represents a taxonomy of categories
This commit is contained in:
parent
91c9533b08
commit
762dc07a16
9
LICENCE
9
LICENCE
|
@ -0,0 +1,9 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2023
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@ -48,13 +48,28 @@ class Article:
|
|||
return self.html
|
||||
|
||||
|
||||
class Section:
|
||||
def __init__(self, key, path=None):
|
||||
self.key = key
|
||||
self.path = path
|
||||
self.parent = None
|
||||
self.sections = {}
|
||||
|
||||
def add(self, section):
|
||||
if section.key not in self.sections.keys():
|
||||
section.parent = self
|
||||
self.sections[section.key] = section
|
||||
|
||||
return self.sections[section.key]
|
||||
|
||||
|
||||
class Site:
|
||||
"""A site contains articles, categories and all related data.
|
||||
"""
|
||||
def __init__(self, root_directory: str):
|
||||
self.root_directory = root_directory
|
||||
self.articles = []
|
||||
self.categories = {}
|
||||
self.sections = {}
|
||||
self.tags = {}
|
||||
|
||||
def add(self, file_content: str):
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
"""Tests associated to the models"""
|
||||
|
||||
from jack.models import Article, Site
|
||||
from jack.models import Article, Section, Site
|
||||
|
||||
content = """---
|
||||
title: This is a test article
|
||||
|
@ -42,6 +42,26 @@ def test_article_fenced_code():
|
|||
assert """<pre><code class="language-python">""" in article.to_prose()
|
||||
|
||||
|
||||
def test_section_add():
|
||||
parent = Section("dev")
|
||||
child = Section("code")
|
||||
parent.add(child)
|
||||
|
||||
assert child.parent == parent
|
||||
assert child in parent.sections.values()
|
||||
assert child == parent.sections.get("code")
|
||||
|
||||
|
||||
def test_add_existing_section():
|
||||
parent = Section("dev")
|
||||
child = Section("code")
|
||||
parent.add(child)
|
||||
other_child = Section("code")
|
||||
parent.add(other_child)
|
||||
|
||||
assert len(parent.sections) == 1
|
||||
|
||||
|
||||
def test_site_append_article():
|
||||
site = Site(".")
|
||||
article = site.add(content)
|
||||
|
|
Loading…
Reference in New Issue