diff --git a/utils/html/__init__.py b/utils/html/__init__.py
index 66fd076..1a94621 100644
--- a/utils/html/__init__.py
+++ b/utils/html/__init__.py
@@ -3,3 +3,4 @@
from utils.html.tag import *
from utils.html.doc import *
from utils.html.jslibs import *
+from utils.html.csslibs import *
diff --git a/utils/html/base.py b/utils/html/base.py
index 7753c88..d32bff1 100644
--- a/utils/html/base.py
+++ b/utils/html/base.py
@@ -220,17 +220,14 @@ def proc_yt_opt(kwargs):
class Library(object):
__slots__ = (
- "path",
+ "path", "options",
)
- def __init__(self, path):
+ def __init__(self, path, *args, **kwargs):
self.path = path
-
+ self.options = kwargs
-class CSSLib(Library):
- pass
-
class Presentation(HTML):
def slide(self, *args, **kwargs):
kwargs["klass"] = "slide"
diff --git a/utils/html/csslibs.py b/utils/html/csslibs.py
new file mode 100644
index 0000000..dadf304
--- /dev/null
+++ b/utils/html/csslibs.py
@@ -0,0 +1,29 @@
+from utils import namespace
+from utils.html import Library, st
+
+__all__ = (
+ "css",
+)
+
+class CSSLib(Library):
+ def __init__(self, path, *args, **kwargs):
+ Library.__init__(self, path, *args, **kwargs)
+
+
+ def add(self, *args, **kwargs):
+ kwargs.update(self.options)
+
+ kwargs["rel"] = "stylesheet"
+ kwargs["href"] = self.path
+
+ return st.link(**kwargs)
+
+
+
+css = namespace(
+ bootstrap = CSSLib(
+ "https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css",
+ integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh",
+ crossorigin="anonymous",
+ ),
+)
diff --git a/utils/html/doc.py b/utils/html/doc.py
index e666c44..d1ed888 100644
--- a/utils/html/doc.py
+++ b/utils/html/doc.py
@@ -21,20 +21,23 @@ def __init__(self, **kwargs):
class Doc(Children):
__slots__ = (
"filename", "children", "description", "keywords", "author",
- "viewport", "encoder",
+ "viewport", "encoder", "libs",
)
def __init__(self, *args, filename=None, desc="", keywords=[],
author="", viewport={}, encoder=None, title=""):
self.filename, self.description, self.keywords, self.author, \
- self.viewport, self.encoder, self.title = (
+ self.viewport, self.encoder, self.title, self.libs = (
filename, desc, keywords, author,
- Viewport(**viewport), encoder, title
+ Viewport(**viewport), encoder, title, None
)
self.children = [""] + list(args)
+ def use(self, *args):
+ self.libs = args
+
def meta(self):
kw = self.keywords
@@ -43,6 +46,14 @@ def meta(self):
else:
kw = ",".join(kw)
+ l = self.libs
+
+ if len(l) == 0:
+ l = ""
+ else:
+ l = t.div(id="libraries")
+ l(lib.add() for lib in self.libs)
+
return (
t.title(self.title),
st.meta(charset="utf-8"),
@@ -50,6 +61,7 @@ def meta(self):
st.meta(name="keywords", content=kw),
st.meta(name="author", content=self.author),
st.meta(name="viewport", content=self.viewport.parse_options()),
+ l,
)
def write_to(self, writer):
@@ -66,4 +78,4 @@ def to_file(self, filename=None):
with open(filename, "w") as f:
self.write_to(f)
-
+
diff --git a/utils/html/jslibs.py b/utils/html/jslibs.py
index 6204e42..33b8738 100644
--- a/utils/html/jslibs.py
+++ b/utils/html/jslibs.py
@@ -2,7 +2,7 @@
from utils.html import Library, t
__all__ = (
- "libs", "plotly", "Plotly",
+ "js", "plotly", "Plotly",
)
class JSLib(Library):
@@ -10,26 +10,31 @@ class JSLib(Library):
"_async",
)
- def __init__(self, *args, **kwargs):
+ def __init__(self, path, *args, **kwargs):
self._async = bool(kwargs.get("async", True))
- Library.__init__(self, kwargs["path"])
+ Library.__init__(self, path, *args, **kwargs)
- def add(self, *args, **kwargs):
- args = set(args)
+ def add(self, **kwargs):
+ kwargs.update(self.options)
if self._async:
- args.add("async")
+ kwargs["async"] = True
kwargs["src"] = self.path
return t.script(**kwargs)
-libs = namespace(
+js = namespace(
shower=JSLib(path="https://shwr.me/shower/shower.min.js"),
mathjax=JSLib(path="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"),
jquery=JSLib(path="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"),
+ bootstrap = JSLib(
+ path="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js",
+ integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6",
+ crossorigin="anonymous",
+ ),
)
class Plotly(JSLib):
@@ -47,9 +52,7 @@ def __init__(self, *args, **kwargs):
else:
path = self.base.format(version=version)
- kwargs["path"] = path
-
- JSLib.__init__(self, *args, **kwargs)
+ JSLib.__init__(self, path, *args, **kwargs)
plotly = namespace(
diff --git a/utils/html/tag.py b/utils/html/tag.py
index 62573fe..ee21a58 100644
--- a/utils/html/tag.py
+++ b/utils/html/tag.py
@@ -3,6 +3,7 @@
__all__ = (
"tags", "t", "stags", "st", "Children", "Options", "url", "doi",
+ "collapsable",
)
@@ -155,6 +156,15 @@ def url(address, txt, **kwargs):
def doi(number, **kwargs):
return url("https://doi.org/%s" % number, **kwargs)
+def collapsable(name, id, **kwargs):
+ b = t.button(name, **{
+ "data-toggle":"collapse",
+ "data_target":id
+ })
+
+ d = t.div(id=id, klass="collapse")
+
+ return b, d
symbols = namespace(
linebreak = "
",