Skip to content

Commit

Permalink
update doc
Browse files Browse the repository at this point in the history
  • Loading branch information
jdum committed Dec 15, 2023
1 parent 5e96c25 commit 04d9ca1
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 35 deletions.
51 changes: 31 additions & 20 deletions doc/document.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ <h1 class="title">Module <code>odfdo.document</code></h1>
# Jerome Dumonteil &lt;[email protected]&gt;
&#34;&#34;&#34;Document class, root of the ODF document
&#34;&#34;&#34;
import os
import posixpath
from copy import deepcopy
from mimetypes import guess_type
from operator import itemgetter
from pathlib import Path
from typing import Union
from uuid import uuid4

from .const import (
Expand All @@ -83,7 +83,14 @@ <h1 class="title">Module <code>odfdo.document</code></h1>

AUTOMATIC_PREFIX = &#34;odfdo_auto_&#34;

underline_lvl = [&#34;=&#34;, &#34;-&#34;, &#34;:&#34;, &#34;`&#34;, &#34;&#39;&#34;, &#39;&#34;&#39;, &#34;~&#34;, &#34;^&#34;, &#34;_&#34;, &#34;*&#34;, &#34;+&#34;]
UNDERLINE_LVL = [&#34;=&#34;, &#34;-&#34;, &#34;:&#34;, &#34;`&#34;, &#34;&#39;&#34;, &#39;&#34;&#39;, &#34;~&#34;, &#34;^&#34;, &#34;_&#34;, &#34;*&#34;, &#34;+&#34;]


def _underline_string(level: int, name: str) -&gt; str:
&#34;&#34;&#34;Underline string of the name.&#34;&#34;&#34;
if level &gt;= len(UNDERLINE_LVL):
return &#34;\n&#34;
return underline_lvl[level] * len(name)


def _show_styles(element, level=0):
Expand All @@ -95,10 +102,8 @@ <h1 class="title">Module <code>odfdo.document</code></h1>
return None
tag_name = element.tag
output.append(tag_name)
# Underline and Overline the name
underline = underline_lvl[level] * len(tag_name)
underline = underline if level &lt; len(underline_lvl) else &#34;\n&#34;
output.append(underline)
# Underline the name
output.append(_underline_string(level, tag_name))
# Add a separation between name and attributes
output[-1] += &#34;\n&#34;
attrs = []
Expand Down Expand Up @@ -146,7 +151,7 @@ <h1 class="title">Module <code>odfdo.document</code></h1>
class Document:
&#34;&#34;&#34;Abstraction of the ODF document.&#34;&#34;&#34;

def __init__(self, target=&#34;text&#34;):
def __init__(self, target: Union[str, bytes, Path, Container, None] = &#34;text&#34;):
# Cache of XML parts
self.__xmlparts = {}
# Cache of the body
Expand Down Expand Up @@ -420,8 +425,9 @@ <h1 class="title">Module <code>odfdo.document</code></h1>
return &#34;\n&#34;.join(result) + &#34;\n&#34;

def add_file(self, path_or_file):
&#34;&#34;&#34;Insert a file from a path or a fike-like object in the container.
Return the full path to reference it in the content.
&#34;&#34;&#34;Insert a file from a path or a file-like object in the container.

Return the full path to reference in the content.

Arguments:

Expand All @@ -442,6 +448,7 @@ <h1 class="title">Module <code>odfdo.document</code></h1>
if posixpath.join(&#34;Pictures&#34;, name) in medias:
name = f&#34;{path.stem}_{uuid4()}{extension}&#34;
else:
path = None
name = getattr(path_or_file, &#34;name&#34;, None)
if not name:
name = str(uuid4())
Expand All @@ -452,7 +459,7 @@ <h1 class="title">Module <code>odfdo.document</code></h1>
manifest.add_full_path(&#34;Pictures/&#34;)
full_path = posixpath.join(&#34;Pictures&#34;, name)
if path is None:
self.container.set_part(full_path, handler.read())
self.container.set_part(full_path, path_or_file.read())
else:
self.container.set_part(full_path, path.read_bytes())
manifest.add_full_path(full_path, media_type)
Expand Down Expand Up @@ -865,7 +872,7 @@ <h2 class="section-title" id="header-classes">Classes</h2>
<dl>
<dt id="odfdo.document.Document"><code class="flex name class">
<span>class <span class="ident">Document</span></span>
<span>(</span><span>target='text')</span>
<span>(</span><span>target: Union[str, bytes, pathlib.Path, <a title="odfdo.container.Container" href="container.html#odfdo.container.Container">Container</a>, ForwardRef(None)] = 'text')</span>
</code></dt>
<dd>
<div class="desc"><p>Abstraction of the ODF document.</p></div>
Expand All @@ -876,7 +883,7 @@ <h2 class="section-title" id="header-classes">Classes</h2>
<pre><code class="python">class Document:
&#34;&#34;&#34;Abstraction of the ODF document.&#34;&#34;&#34;

def __init__(self, target=&#34;text&#34;):
def __init__(self, target: Union[str, bytes, Path, Container, None] = &#34;text&#34;):
# Cache of XML parts
self.__xmlparts = {}
# Cache of the body
Expand Down Expand Up @@ -1150,8 +1157,9 @@ <h2 class="section-title" id="header-classes">Classes</h2>
return &#34;\n&#34;.join(result) + &#34;\n&#34;

def add_file(self, path_or_file):
&#34;&#34;&#34;Insert a file from a path or a fike-like object in the container.
Return the full path to reference it in the content.
&#34;&#34;&#34;Insert a file from a path or a file-like object in the container.

Return the full path to reference in the content.

Arguments:

Expand All @@ -1172,6 +1180,7 @@ <h2 class="section-title" id="header-classes">Classes</h2>
if posixpath.join(&#34;Pictures&#34;, name) in medias:
name = f&#34;{path.stem}_{uuid4()}{extension}&#34;
else:
path = None
name = getattr(path_or_file, &#34;name&#34;, None)
if not name:
name = str(uuid4())
Expand All @@ -1182,7 +1191,7 @@ <h2 class="section-title" id="header-classes">Classes</h2>
manifest.add_full_path(&#34;Pictures/&#34;)
full_path = posixpath.join(&#34;Pictures&#34;, name)
if path is None:
self.container.set_part(full_path, handler.read())
self.container.set_part(full_path, path_or_file.read())
else:
self.container.set_part(full_path, path.read_bytes())
manifest.add_full_path(full_path, media_type)
Expand Down Expand Up @@ -1685,8 +1694,8 @@ <h3>Methods</h3>
<span>def <span class="ident">add_file</span></span>(<span>self, path_or_file)</span>
</code></dt>
<dd>
<div class="desc"><p>Insert a file from a path or a fike-like object in the container.
Return the full path to reference it in the content.</p>
<div class="desc"><p>Insert a file from a path or a file-like object in the container.</p>
<p>Return the full path to reference in the content.</p>
<h2 id="arguments">Arguments</h2>
<p>path_or_file &ndash; str or Path or file-like</p>
<p>Return: str (URI)</p></div>
Expand All @@ -1695,8 +1704,9 @@ <h2 id="arguments">Arguments</h2>
<span>Expand source code</span>
</summary>
<pre><code class="python">def add_file(self, path_or_file):
&#34;&#34;&#34;Insert a file from a path or a fike-like object in the container.
Return the full path to reference it in the content.
&#34;&#34;&#34;Insert a file from a path or a file-like object in the container.

Return the full path to reference in the content.

Arguments:

Expand All @@ -1717,6 +1727,7 @@ <h2 id="arguments">Arguments</h2>
if posixpath.join(&#34;Pictures&#34;, name) in medias:
name = f&#34;{path.stem}_{uuid4()}{extension}&#34;
else:
path = None
name = getattr(path_or_file, &#34;name&#34;, None)
if not name:
name = str(uuid4())
Expand All @@ -1727,7 +1738,7 @@ <h2 id="arguments">Arguments</h2>
manifest.add_full_path(&#34;Pictures/&#34;)
full_path = posixpath.join(&#34;Pictures&#34;, name)
if path is None:
self.container.set_part(full_path, handler.read())
self.container.set_part(full_path, path_or_file.read())
else:
self.container.set_part(full_path, path.read_bytes())
manifest.add_full_path(full_path, media_type)
Expand Down
6 changes: 3 additions & 3 deletions doc/element.html
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ <h1 class="title">Module <code>odfdo.element</code></h1>

Return: int
&#34;&#34;&#34;
if isinstance(pattern, str):
if not isinstance(pattern, str):
# Fail properly if the pattern is an non-ascii bytestring
pattern = str(pattern)
cpattern = re.compile(pattern)
Expand Down Expand Up @@ -3641,7 +3641,7 @@ <h2 class="section-title" id="header-classes">Classes</h2>

Return: int
&#34;&#34;&#34;
if isinstance(pattern, str):
if not isinstance(pattern, str):
# Fail properly if the pattern is an non-ascii bytestring
pattern = str(pattern)
cpattern = re.compile(pattern)
Expand Down Expand Up @@ -9210,7 +9210,7 @@ <h2 id="arguments">Arguments</h2>

Return: int
&#34;&#34;&#34;
if isinstance(pattern, str):
if not isinstance(pattern, str):
# Fail properly if the pattern is an non-ascii bytestring
pattern = str(pattern)
cpattern = re.compile(pattern)
Expand Down
28 changes: 16 additions & 12 deletions doc/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5698,7 +5698,7 @@ <h3>Inherited members</h3>
</dd>
<dt id="odfdo.Document"><code class="flex name class">
<span>class <span class="ident">Document</span></span>
<span>(</span><span>target='text')</span>
<span>(</span><span>target: Union[str, bytes, pathlib.Path, <a title="odfdo.container.Container" href="container.html#odfdo.container.Container">Container</a>, ForwardRef(None)] = 'text')</span>
</code></dt>
<dd>
<div class="desc"><p>Abstraction of the ODF document.</p></div>
Expand All @@ -5709,7 +5709,7 @@ <h3>Inherited members</h3>
<pre><code class="python">class Document:
&#34;&#34;&#34;Abstraction of the ODF document.&#34;&#34;&#34;

def __init__(self, target=&#34;text&#34;):
def __init__(self, target: Union[str, bytes, Path, Container, None] = &#34;text&#34;):
# Cache of XML parts
self.__xmlparts = {}
# Cache of the body
Expand Down Expand Up @@ -5983,8 +5983,9 @@ <h3>Inherited members</h3>
return &#34;\n&#34;.join(result) + &#34;\n&#34;

def add_file(self, path_or_file):
&#34;&#34;&#34;Insert a file from a path or a fike-like object in the container.
Return the full path to reference it in the content.
&#34;&#34;&#34;Insert a file from a path or a file-like object in the container.

Return the full path to reference in the content.

Arguments:

Expand All @@ -6005,6 +6006,7 @@ <h3>Inherited members</h3>
if posixpath.join(&#34;Pictures&#34;, name) in medias:
name = f&#34;{path.stem}_{uuid4()}{extension}&#34;
else:
path = None
name = getattr(path_or_file, &#34;name&#34;, None)
if not name:
name = str(uuid4())
Expand All @@ -6015,7 +6017,7 @@ <h3>Inherited members</h3>
manifest.add_full_path(&#34;Pictures/&#34;)
full_path = posixpath.join(&#34;Pictures&#34;, name)
if path is None:
self.container.set_part(full_path, handler.read())
self.container.set_part(full_path, path_or_file.read())
else:
self.container.set_part(full_path, path.read_bytes())
manifest.add_full_path(full_path, media_type)
Expand Down Expand Up @@ -6518,8 +6520,8 @@ <h3>Methods</h3>
<span>def <span class="ident">add_file</span></span>(<span>self, path_or_file)</span>
</code></dt>
<dd>
<div class="desc"><p>Insert a file from a path or a fike-like object in the container.
Return the full path to reference it in the content.</p>
<div class="desc"><p>Insert a file from a path or a file-like object in the container.</p>
<p>Return the full path to reference in the content.</p>
<h2 id="arguments">Arguments</h2>
<p>path_or_file &ndash; str or Path or file-like</p>
<p>Return: str (URI)</p></div>
Expand All @@ -6528,8 +6530,9 @@ <h2 id="arguments">Arguments</h2>
<span>Expand source code</span>
</summary>
<pre><code class="python">def add_file(self, path_or_file):
&#34;&#34;&#34;Insert a file from a path or a fike-like object in the container.
Return the full path to reference it in the content.
&#34;&#34;&#34;Insert a file from a path or a file-like object in the container.

Return the full path to reference in the content.

Arguments:

Expand All @@ -6550,6 +6553,7 @@ <h2 id="arguments">Arguments</h2>
if posixpath.join(&#34;Pictures&#34;, name) in medias:
name = f&#34;{path.stem}_{uuid4()}{extension}&#34;
else:
path = None
name = getattr(path_or_file, &#34;name&#34;, None)
if not name:
name = str(uuid4())
Expand All @@ -6560,7 +6564,7 @@ <h2 id="arguments">Arguments</h2>
manifest.add_full_path(&#34;Pictures/&#34;)
full_path = posixpath.join(&#34;Pictures&#34;, name)
if path is None:
self.container.set_part(full_path, handler.read())
self.container.set_part(full_path, path_or_file.read())
else:
self.container.set_part(full_path, path.read_bytes())
manifest.add_full_path(full_path, media_type)
Expand Down Expand Up @@ -9249,7 +9253,7 @@ <h3>Inherited members</h3>

Return: int
&#34;&#34;&#34;
if isinstance(pattern, str):
if not isinstance(pattern, str):
# Fail properly if the pattern is an non-ascii bytestring
pattern = str(pattern)
cpattern = re.compile(pattern)
Expand Down Expand Up @@ -14818,7 +14822,7 @@ <h2 id="arguments">Arguments</h2>

Return: int
&#34;&#34;&#34;
if isinstance(pattern, str):
if not isinstance(pattern, str):
# Fail properly if the pattern is an non-ascii bytestring
pattern = str(pattern)
cpattern = re.compile(pattern)
Expand Down

0 comments on commit 04d9ca1

Please sign in to comment.