pydocmaker 2.2.0__tar.gz → 2.2.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. {pydocmaker-2.2.0/src/pydocmaker.egg-info → pydocmaker-2.2.2}/PKG-INFO +67 -6
  2. {pydocmaker-2.2.0 → pydocmaker-2.2.2}/README.md +66 -5
  3. {pydocmaker-2.2.0 → pydocmaker-2.2.2}/src/pydocmaker/__init__.py +2 -2
  4. {pydocmaker-2.2.0 → pydocmaker-2.2.2}/src/pydocmaker/backend/ex_tex.py +2 -2
  5. {pydocmaker-2.2.0 → pydocmaker-2.2.2}/src/pydocmaker/core.py +1 -1
  6. {pydocmaker-2.2.0 → pydocmaker-2.2.2}/src/pydocmaker/templating.py +17 -0
  7. {pydocmaker-2.2.0 → pydocmaker-2.2.2/src/pydocmaker.egg-info}/PKG-INFO +67 -6
  8. {pydocmaker-2.2.0 → pydocmaker-2.2.2}/LICENSE +0 -0
  9. {pydocmaker-2.2.0 → pydocmaker-2.2.2}/setup.cfg +0 -0
  10. {pydocmaker-2.2.0 → pydocmaker-2.2.2}/setup.py +0 -0
  11. {pydocmaker-2.2.0 → pydocmaker-2.2.2}/src/pydocmaker/backend/__init__.py +0 -0
  12. {pydocmaker-2.2.0 → pydocmaker-2.2.2}/src/pydocmaker/backend/baseformatter.py +0 -0
  13. {pydocmaker-2.2.0 → pydocmaker-2.2.2}/src/pydocmaker/backend/ex_docx.py +0 -0
  14. {pydocmaker-2.2.0 → pydocmaker-2.2.2}/src/pydocmaker/backend/ex_html.py +0 -0
  15. {pydocmaker-2.2.0 → pydocmaker-2.2.2}/src/pydocmaker/backend/ex_ipynb.py +0 -0
  16. {pydocmaker-2.2.0 → pydocmaker-2.2.2}/src/pydocmaker/backend/ex_markdown.py +0 -0
  17. {pydocmaker-2.2.0 → pydocmaker-2.2.2}/src/pydocmaker/backend/ex_redmine.py +0 -0
  18. {pydocmaker-2.2.0 → pydocmaker-2.2.2}/src/pydocmaker/backend/mdx_latex.py +0 -0
  19. {pydocmaker-2.2.0 → pydocmaker-2.2.2}/src/pydocmaker/backend/pandoc_api.py +0 -0
  20. {pydocmaker-2.2.0 → pydocmaker-2.2.2}/src/pydocmaker/backend/pdf_maker.py +0 -0
  21. {pydocmaker-2.2.0 → pydocmaker-2.2.2}/src/pydocmaker/util.py +0 -0
  22. {pydocmaker-2.2.0 → pydocmaker-2.2.2}/src/pydocmaker.egg-info/SOURCES.txt +0 -0
  23. {pydocmaker-2.2.0 → pydocmaker-2.2.2}/src/pydocmaker.egg-info/dependency_links.txt +0 -0
  24. {pydocmaker-2.2.0 → pydocmaker-2.2.2}/src/pydocmaker.egg-info/requires.txt +0 -0
  25. {pydocmaker-2.2.0 → pydocmaker-2.2.2}/src/pydocmaker.egg-info/top_level.txt +0 -0
  26. {pydocmaker-2.2.0 → pydocmaker-2.2.2}/tests/test_backend_pandoc.py +0 -0
  27. {pydocmaker-2.2.0 → pydocmaker-2.2.2}/tests/test_convert_all.py +0 -0
  28. {pydocmaker-2.2.0 → pydocmaker-2.2.2}/tests/test_core.py +0 -0
  29. {pydocmaker-2.2.0 → pydocmaker-2.2.2}/tests/test_ex_html.py +0 -0
  30. {pydocmaker-2.2.0 → pydocmaker-2.2.2}/tests/test_util.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pydocmaker
3
- Version: 2.2.0
3
+ Version: 2.2.2
4
4
  Summary: a minimal document maker to make docx, markdown, html, textile, redmine, and tex documents from python. Written in pure python.
5
5
  Home-page: https://github.com/TobiasGlaubach/pydocmaker
6
6
  Author: Tobias Glaubach
@@ -45,7 +45,7 @@ pip install pydocmaker
45
45
 
46
46
  ## TL;DR;
47
47
 
48
- ### Minimal Mini Example:
48
+ ### Snippet:
49
49
 
50
50
  ```python
51
51
 
@@ -53,7 +53,6 @@ import pydocmaker as pyd
53
53
 
54
54
  doc = pyd.Doc.get_example()
55
55
  doc.show()
56
-
57
56
  ```
58
57
 
59
58
  ### Minimal Usage Example:
@@ -70,7 +69,6 @@ doc.add_pre('this will be shown as preformatted') # preformatted
70
69
  doc.add_md('This is some *fancy* `markdown` **text**') # markdown
71
70
  doc.add_tex(r'\textbf{Hello, LaTeX!}') # latex
72
71
 
73
-
74
72
  # this is how to add an image from link
75
73
  doc.add_image("https://github.githubassets.com/assets/GitHub-Mark-ea2971cee799.png", caption='', children='', width=0.8)
76
74
 
@@ -132,10 +130,73 @@ import redminelib
132
130
  redmine = redminelib.Redmine('https://your-redmine-instance.com', key='your_redmine_token')
133
131
  page = doc.to_redmine_upload(redmine, 'your-test-project')
134
132
  ```
133
+ ### Using Template Folders
134
+
135
+ pydocmaker supports mounting Jinja2 Templates organized in folders together with (optional) default parameters and assets. Suppose you have the following folder structure
136
+
137
+ ```
138
+ home/jovyan/templates/
139
+ ├─ assets/
140
+ │ ├─ i_can_use_this_everywhere.png
141
+ ├─ fancy_tempate.assets/
142
+ │ ├─ fancy_logo.png
143
+ │ ├─ fancy_title_picture.png
144
+ ├─ fancy_template.params.json
145
+ ├─ fancy_template.tex.j2
146
+ ├─ normal_template.params.json
147
+ ├─ normal_template.tex.j2
148
+ ```
149
+
150
+ (NOTE: you can also check out the `templates` folder in this repository for an example).
151
+
152
+ You can then mount this folder in pydocmaker using
153
+
154
+ ```python
155
+ pyd.register_new_template_dir(r'home/jovyan/templates/')
156
+ ```
157
+
158
+ Which will give you two available templates to use for exporting tex and pdf documents:
159
+
160
+
161
+ ```python
162
+ print(pyd.get_available_template_ids())
163
+ ```
164
+ `>>> ["fancy_template", "normal_template"]`
165
+
166
+
167
+
168
+ You can mark the templates to be used for a doc by setting it to the reports metadata:
169
+ ```python
170
+ import pydocmaker as pyd
171
+ doc = pyd.get_example()
172
+ doc.set_template_to_meta('fancy_template')
173
+ ```
174
+
175
+ which will write all needed data to the documents "metadata". Specifically:
176
+ - `template_id` will hold the id with which the specific template can be loaded. In our case it will be `fancy_template`.
177
+ - `files_to_upload` will hold all assets as base64 encoded bytes in our case the following files:
178
+ - **key**: `fancy_logo.png` **value** content from `.../fancy_tempate.assets/fancy_logo.png`
179
+ - **key**: `fancy_title_picture.png` **value** content from `.../fancy_tempate.assets/fancy_title_picture.png`
180
+ - **key**: `i_can_use_this_everywhere.png` **value** content from `.../assets/i_can_use_this_everywhere.png` (content from `assets` will be made available shared for all templates)
181
+ - and all other fields loaded from `fancy_template.params.json` will be loaded to the metadata dictionary directly.
182
+
183
+ If you thereafter export your document to pdf (or html if you have an html type template), pydocmaker will automatically load the template and render it with parameters, attachments and your document as the body.
184
+
185
+ you can view the template and params by
186
+ ```python
187
+ print(doc.get_meta())
188
+ ```
189
+
190
+ and change them by:
191
+
192
+ ```python
193
+ doc.update_meta(author='Me!')
194
+ ```
195
+
135
196
 
136
- ### Using Jinja2 Templates for Exporting to HTML or PDF
197
+ ### Using Jinja2 Templates Directly for Exporting to HTML or PDF
137
198
 
138
- you can use Jinja2 Templates to make HTML or PDF (latex) documents. An example is given below:
199
+ you can also use Jinja2 Templates directly to make HTML or PDF (latex) documents. An example is given below:
139
200
 
140
201
  ```python
141
202
 
@@ -29,7 +29,7 @@ pip install pydocmaker
29
29
 
30
30
  ## TL;DR;
31
31
 
32
- ### Minimal Mini Example:
32
+ ### Snippet:
33
33
 
34
34
  ```python
35
35
 
@@ -37,7 +37,6 @@ import pydocmaker as pyd
37
37
 
38
38
  doc = pyd.Doc.get_example()
39
39
  doc.show()
40
-
41
40
  ```
42
41
 
43
42
  ### Minimal Usage Example:
@@ -54,7 +53,6 @@ doc.add_pre('this will be shown as preformatted') # preformatted
54
53
  doc.add_md('This is some *fancy* `markdown` **text**') # markdown
55
54
  doc.add_tex(r'\textbf{Hello, LaTeX!}') # latex
56
55
 
57
-
58
56
  # this is how to add an image from link
59
57
  doc.add_image("https://github.githubassets.com/assets/GitHub-Mark-ea2971cee799.png", caption='', children='', width=0.8)
60
58
 
@@ -116,10 +114,73 @@ import redminelib
116
114
  redmine = redminelib.Redmine('https://your-redmine-instance.com', key='your_redmine_token')
117
115
  page = doc.to_redmine_upload(redmine, 'your-test-project')
118
116
  ```
117
+ ### Using Template Folders
118
+
119
+ pydocmaker supports mounting Jinja2 Templates organized in folders together with (optional) default parameters and assets. Suppose you have the following folder structure
120
+
121
+ ```
122
+ home/jovyan/templates/
123
+ ├─ assets/
124
+ │ ├─ i_can_use_this_everywhere.png
125
+ ├─ fancy_tempate.assets/
126
+ │ ├─ fancy_logo.png
127
+ │ ├─ fancy_title_picture.png
128
+ ├─ fancy_template.params.json
129
+ ├─ fancy_template.tex.j2
130
+ ├─ normal_template.params.json
131
+ ├─ normal_template.tex.j2
132
+ ```
133
+
134
+ (NOTE: you can also check out the `templates` folder in this repository for an example).
135
+
136
+ You can then mount this folder in pydocmaker using
137
+
138
+ ```python
139
+ pyd.register_new_template_dir(r'home/jovyan/templates/')
140
+ ```
141
+
142
+ Which will give you two available templates to use for exporting tex and pdf documents:
143
+
144
+
145
+ ```python
146
+ print(pyd.get_available_template_ids())
147
+ ```
148
+ `>>> ["fancy_template", "normal_template"]`
149
+
150
+
151
+
152
+ You can mark the templates to be used for a doc by setting it to the reports metadata:
153
+ ```python
154
+ import pydocmaker as pyd
155
+ doc = pyd.get_example()
156
+ doc.set_template_to_meta('fancy_template')
157
+ ```
158
+
159
+ which will write all needed data to the documents "metadata". Specifically:
160
+ - `template_id` will hold the id with which the specific template can be loaded. In our case it will be `fancy_template`.
161
+ - `files_to_upload` will hold all assets as base64 encoded bytes in our case the following files:
162
+ - **key**: `fancy_logo.png` **value** content from `.../fancy_tempate.assets/fancy_logo.png`
163
+ - **key**: `fancy_title_picture.png` **value** content from `.../fancy_tempate.assets/fancy_title_picture.png`
164
+ - **key**: `i_can_use_this_everywhere.png` **value** content from `.../assets/i_can_use_this_everywhere.png` (content from `assets` will be made available shared for all templates)
165
+ - and all other fields loaded from `fancy_template.params.json` will be loaded to the metadata dictionary directly.
166
+
167
+ If you thereafter export your document to pdf (or html if you have an html type template), pydocmaker will automatically load the template and render it with parameters, attachments and your document as the body.
168
+
169
+ you can view the template and params by
170
+ ```python
171
+ print(doc.get_meta())
172
+ ```
173
+
174
+ and change them by:
175
+
176
+ ```python
177
+ doc.update_meta(author='Me!')
178
+ ```
179
+
119
180
 
120
- ### Using Jinja2 Templates for Exporting to HTML or PDF
181
+ ### Using Jinja2 Templates Directly for Exporting to HTML or PDF
121
182
 
122
- you can use Jinja2 Templates to make HTML or PDF (latex) documents. An example is given below:
183
+ you can also use Jinja2 Templates directly to make HTML or PDF (latex) documents. An example is given below:
123
184
 
124
185
  ```python
125
186
 
@@ -1,4 +1,4 @@
1
- __version__ = '2.2.0'
1
+ __version__ = '2.2.2'
2
2
 
3
3
  from pydocmaker.core import DocBuilder, construct, constr, buildingblocks, print_to_pdf, get_latex_compiler, set_latex_compiler, make_pdf_from_tex, show_pdf
4
4
  from pydocmaker.util import upload_report_to_redmine, bcolors, txtcolor, colors_dc
@@ -8,7 +8,7 @@ from pydocmaker.backend.ex_tex import can_run_pandoc
8
8
  from pydocmaker.backend.pdf_maker import get_all_installed_latex_compilers, get_latex_compiler
9
9
 
10
10
  from pydocmaker.core import DocBuilder as Doc
11
- from pydocmaker.templating import DocTemplate, TemplateDirSource, register_new_template_dir, get_registered_template_dirs, get_available_template_ids, test_template_exists
11
+ from pydocmaker.templating import DocTemplate, TemplateDirSource, register_new_template_dir, get_registered_template_dirs, get_available_template_ids, test_template_exists, remove_from_template_dir
12
12
 
13
13
  from latex import escape as tex_escape
14
14
 
@@ -115,13 +115,13 @@ def escape(s):
115
115
 
116
116
  def auto_escape_latex(params):
117
117
  if isinstance(params, str):
118
- return params if params.startswith('%%latex') else escape(params)
118
+ return params if params.startswith('%%latex') or params.startswith('%latex') or params.startswith('%tex') else escape(params)
119
119
  elif isinstance(params, dict):
120
120
  return {k:auto_escape_latex(v) for k, v in params.items()}
121
121
  elif isinstance(params, list):
122
122
  return [auto_escape_latex(v) for k, v in params.items()]
123
123
  else:
124
- raise ValueError('Can only auto escape strings, lists, or dicts as parameters!')
124
+ return params
125
125
 
126
126
 
127
127
 
@@ -51,7 +51,7 @@ def is_notebook() -> bool:
51
51
  return False # Probably standard Python interpreter
52
52
 
53
53
 
54
- def show_pdf(pdf_bytes:[bytes|str], width=1000, height=1200):
54
+ def show_pdf(pdf_bytes:bytes, width=1000, height=1200):
55
55
  """
56
56
  Display a PDF file within an IPython environment.
57
57
 
@@ -28,6 +28,23 @@ def register_new_template_dir(new_template_dir:str, check_exists=True) -> bool:
28
28
  registered_template_dirs.add(new_template_dir)
29
29
  return new_template_dir in registered_template_dirs
30
30
 
31
+ def remove_from_template_dir(to_remove:str) -> bool:
32
+ """Removes an existing template directory if it exists.
33
+
34
+ Args:
35
+ to_remove (str): The path to remove from the template dirs.
36
+
37
+ Returns:
38
+ bool: Always True
39
+ """
40
+
41
+ global registered_template_dirs
42
+ if to_remove in registered_template_dirs:
43
+ registered_template_dirs.remove(to_remove)
44
+ return True
45
+
46
+
47
+
31
48
  def get_registered_template_dirs(include_default=True):
32
49
  """Returns a list of registered template directories.
33
50
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pydocmaker
3
- Version: 2.2.0
3
+ Version: 2.2.2
4
4
  Summary: a minimal document maker to make docx, markdown, html, textile, redmine, and tex documents from python. Written in pure python.
5
5
  Home-page: https://github.com/TobiasGlaubach/pydocmaker
6
6
  Author: Tobias Glaubach
@@ -45,7 +45,7 @@ pip install pydocmaker
45
45
 
46
46
  ## TL;DR;
47
47
 
48
- ### Minimal Mini Example:
48
+ ### Snippet:
49
49
 
50
50
  ```python
51
51
 
@@ -53,7 +53,6 @@ import pydocmaker as pyd
53
53
 
54
54
  doc = pyd.Doc.get_example()
55
55
  doc.show()
56
-
57
56
  ```
58
57
 
59
58
  ### Minimal Usage Example:
@@ -70,7 +69,6 @@ doc.add_pre('this will be shown as preformatted') # preformatted
70
69
  doc.add_md('This is some *fancy* `markdown` **text**') # markdown
71
70
  doc.add_tex(r'\textbf{Hello, LaTeX!}') # latex
72
71
 
73
-
74
72
  # this is how to add an image from link
75
73
  doc.add_image("https://github.githubassets.com/assets/GitHub-Mark-ea2971cee799.png", caption='', children='', width=0.8)
76
74
 
@@ -132,10 +130,73 @@ import redminelib
132
130
  redmine = redminelib.Redmine('https://your-redmine-instance.com', key='your_redmine_token')
133
131
  page = doc.to_redmine_upload(redmine, 'your-test-project')
134
132
  ```
133
+ ### Using Template Folders
134
+
135
+ pydocmaker supports mounting Jinja2 Templates organized in folders together with (optional) default parameters and assets. Suppose you have the following folder structure
136
+
137
+ ```
138
+ home/jovyan/templates/
139
+ ├─ assets/
140
+ │ ├─ i_can_use_this_everywhere.png
141
+ ├─ fancy_tempate.assets/
142
+ │ ├─ fancy_logo.png
143
+ │ ├─ fancy_title_picture.png
144
+ ├─ fancy_template.params.json
145
+ ├─ fancy_template.tex.j2
146
+ ├─ normal_template.params.json
147
+ ├─ normal_template.tex.j2
148
+ ```
149
+
150
+ (NOTE: you can also check out the `templates` folder in this repository for an example).
151
+
152
+ You can then mount this folder in pydocmaker using
153
+
154
+ ```python
155
+ pyd.register_new_template_dir(r'home/jovyan/templates/')
156
+ ```
157
+
158
+ Which will give you two available templates to use for exporting tex and pdf documents:
159
+
160
+
161
+ ```python
162
+ print(pyd.get_available_template_ids())
163
+ ```
164
+ `>>> ["fancy_template", "normal_template"]`
165
+
166
+
167
+
168
+ You can mark the templates to be used for a doc by setting it to the reports metadata:
169
+ ```python
170
+ import pydocmaker as pyd
171
+ doc = pyd.get_example()
172
+ doc.set_template_to_meta('fancy_template')
173
+ ```
174
+
175
+ which will write all needed data to the documents "metadata". Specifically:
176
+ - `template_id` will hold the id with which the specific template can be loaded. In our case it will be `fancy_template`.
177
+ - `files_to_upload` will hold all assets as base64 encoded bytes in our case the following files:
178
+ - **key**: `fancy_logo.png` **value** content from `.../fancy_tempate.assets/fancy_logo.png`
179
+ - **key**: `fancy_title_picture.png` **value** content from `.../fancy_tempate.assets/fancy_title_picture.png`
180
+ - **key**: `i_can_use_this_everywhere.png` **value** content from `.../assets/i_can_use_this_everywhere.png` (content from `assets` will be made available shared for all templates)
181
+ - and all other fields loaded from `fancy_template.params.json` will be loaded to the metadata dictionary directly.
182
+
183
+ If you thereafter export your document to pdf (or html if you have an html type template), pydocmaker will automatically load the template and render it with parameters, attachments and your document as the body.
184
+
185
+ you can view the template and params by
186
+ ```python
187
+ print(doc.get_meta())
188
+ ```
189
+
190
+ and change them by:
191
+
192
+ ```python
193
+ doc.update_meta(author='Me!')
194
+ ```
195
+
135
196
 
136
- ### Using Jinja2 Templates for Exporting to HTML or PDF
197
+ ### Using Jinja2 Templates Directly for Exporting to HTML or PDF
137
198
 
138
- you can use Jinja2 Templates to make HTML or PDF (latex) documents. An example is given below:
199
+ you can also use Jinja2 Templates directly to make HTML or PDF (latex) documents. An example is given below:
139
200
 
140
201
  ```python
141
202
 
File without changes
File without changes
File without changes