Skip to content

Index

Index

Bases: BaseModel

Index markdown templates list class

Source code in src/task2md/template/index.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
class Index(BaseModel):
    """Index markdown templates list class"""

    task_files: list[File] = []

    def generate(self, out_dir: Dir) -> None:
        """Generate markdown file in output directory

        Args:
            out_dir (Dir): The dir object
        """
        (Path(out_dir.path) / "index.md").write_text(self.to_md())

    def to_md(self) -> str:
        """Return the content of the file in markdown

        Returns:
            str: Markdown content
        """
        output = """
# Available task templates

List of templates:

| Templates | Description | Tags   |
| --------- | ----------- | ------ |
"""
        for file in self.task_files:
            name = file.get_filename()
            description = file.header.description
            tags = ", ".join(file.header.tags)

            output += f"| [{name}]({name}.md) | {description} | {tags} |\n"

        return output + "\n"

generate(out_dir)

Generate markdown file in output directory

Parameters:

Name Type Description Default
out_dir Dir

The dir object

required
Source code in src/task2md/template/index.py
14
15
16
17
18
19
20
def generate(self, out_dir: Dir) -> None:
    """Generate markdown file in output directory

    Args:
        out_dir (Dir): The dir object
    """
    (Path(out_dir.path) / "index.md").write_text(self.to_md())

to_md()

Return the content of the file in markdown

Returns:

Name Type Description
str str

Markdown content

Source code in src/task2md/template/index.py
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
    def to_md(self) -> str:
        """Return the content of the file in markdown

        Returns:
            str: Markdown content
        """
        output = """
# Available task templates

List of templates:

| Templates | Description | Tags   |
| --------- | ----------- | ------ |
"""
        for file in self.task_files:
            name = file.get_filename()
            description = file.header.description
            tags = ", ".join(file.header.tags)

            output += f"| [{name}]({name}.md) | {description} | {tags} |\n"

        return output + "\n"