Utils for chapters
Project description
Chapters utils
This module contains utils which make work with Foliant chapter lists easier.
Installation
To use functions and classes from this module, install it with command
pip3 install foliantcontrib.utils.chapters
Usage
Right now this module offers only one useful class, called Chapters
. To start using it, import it:
>>> from foliant.contrib.chapters import Chapters
Let's assume we have the following list of chapters specified in foliant.yml:
chapters:
- introduction.md
- Overview:
- The Problem: problem.md
- Requirements: req.md
- Quick Start:
- qs/installation.md
- qs/first_steps.md
- qs/advanced_usage.md
- Specifications:
- specs/core.md
- specs/classes.md
If we want to interact wit this list of chapters, we will probably only need path to Markdown-files in the proper order. That's exactly what the Chapters
class offers. Let's translate this chapter list into Python and give it to the Chapters
class:
>>> chapters_list = {'chapters': ['introduction.md',{'Overview': [{'The Problem': 'problem.md'},{'Requirements': 'req.md'},{'Quick Start': ['qs/installation.md','qs/first_steps.md','qs/advanced_usage.md']}]},{'Specifications': ['specs/core.md', 'specs/classes.md']}]}
>>> chapters = Chapters(chapters_list)
The flat property
The flat
property of the Chapters
class contains the list of chapter filenames in the correct order, with all the original hierarchy neatly flattened.
>>> for chapter in chapters.flat:
... print(chapter)
introduction.md
problem.md
req.md
qs/installation.md
qs/first_steps.md
qs/advanced_usage.md
specs/core.md
specs/classes.md
The paths method
Usually when we work with chapters, we need not just ther names, as they stated in foliant.yml, but the paths to the actual files.
This is the work of the paths
method, which accepts one argument: root of the markdown-files directory (usually src
or __folianttmp__
).
This method returns a generator, which yields PosixPath
objects to each chapter in the proper order
>>> for path in chapters.paths('src'):
... print(repr(path))
PosixPath('src/introduction.md')
PosixPath('src/problem.md')
PosixPath('src/req.md')
PosixPath('src/qs/installation.md')
PosixPath('src/qs/first_steps.md')
PosixPath('src/qs/advanced_usage.md')
PosixPath('src/specs/core.md')
PosixPath('src/specs/classes.md')
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for foliantcontrib.utils.chapters-1.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 24d4bb731423d92ec10af024d086b6d7e5d1e46af3b7c8cc389fa0d4e2f1cc8a |
|
MD5 | 7586c1727868628dcd09273809cd58f8 |
|
BLAKE2b-256 | ddcf496cfa350484c04cd707416c50e9a1930bacba81044e7a79ec00cbaf723c |
Hashes for foliantcontrib.utils.chapters-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3d5c6d731e477e7574f635b4a5b565f2deebbb205bab6bbfc3eb5198ace45945 |
|
MD5 | dbe5f40aadbb0a9621cc0322ee13cfdd |
|
BLAKE2b-256 | 1bef04ed3e7f891bd95c3e866f4746264b78a959f0f042973042ad9bda9d06a3 |