Skip to content

Commit fe4e34a

Browse files
committed
Add PlotSource tag, commence on line tag
1 parent 71911c6 commit fe4e34a

5 files changed

Lines changed: 1556 additions & 1 deletion

File tree

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ classifiers = [
1414
]
1515
license = {text = "MIT"}
1616
dependencies = [
17-
"typer"
17+
"air>=0.30.0",
18+
"typer",
1819
]
1920
requires-python = ">= 3.10"
2021

src/airplot/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22

33
__author__ = """Daniel Roy Greenfeld"""
44
__email__ = 'daniel@feldroy.com'
5+
6+
from .airplot import PlotSource as PlotSource

src/airplot/airplot.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,77 @@
11
"""Main module."""
2+
3+
import air
4+
5+
from typing import TYPE_CHECKING, Literal, override
6+
7+
from air.tags.utils import locals_cleanup
8+
9+
10+
class PlotSource(air.UnSafeTag):
11+
"""Provides the plotly dependency"""
12+
13+
@override
14+
def __init__(
15+
self,
16+
/,
17+
*,
18+
version: str = '3.4.0',
19+
library: str = 'plotly',
20+
**custom_attributes,
21+
):
22+
self.version = version
23+
super().__init__('', **custom_attributes | locals_cleanup(locals()))
24+
25+
@override
26+
def _render(self) -> str:
27+
"""Wraps the comment text with HTML comment delimiters.
28+
29+
Returns:
30+
The serialized comment node.
31+
"""
32+
return f'<script charset="utf-8" src="https://cdn.plot.ly/plotly-{self.version}.min.js"></script>'
33+
34+
35+
36+
class BaseAirPlotTag(air.UnSafeTag):
37+
"""Defines a client-side script.
38+
Warning: Script tag does not protect against code injection.
39+
40+
Args:
41+
text_child: Inline script code. Use an empty string when providing ``src``.
42+
src: URI of the external script.
43+
type_: Script type. Examples: ``module``, ``importmap``, ``speculationrules``,
44+
a JavaScript MIME type (e.g. ``text/javascript``), or empty for classic scripts.
45+
async_: Fetch in parallel and execute as soon as ready; order is not guaranteed.
46+
defer: Execute after parsing (classic scripts only; modules defer by default).
47+
nomodule: Do not execute on browsers that support ES modules.
48+
crossorigin: CORS mode. One of ``"anonymous"`` or ``"use-credentials"``.
49+
integrity: Subresource Integrity hash (e.g. ``"sha384-..."``).
50+
referrerpolicy: Which referrer to send. One of:
51+
``"no-referrer"``, ``"no-referrer-when-downgrade"``, ``"origin"``,
52+
``"origin-when-cross-origin"``, ``"same-origin"``, ``"strict-origin"``,
53+
``"strict-origin-when-cross-origin"``, ``"unsafe-url"``.
54+
fetchpriority: Network priority hint. One of ``"high"``, ``"low"``, ``"auto"``.
55+
blocking: Space-separated tokens that block operations; currently ``"render"``.
56+
attributionsrc: Space-separated URLs for Attribution Reporting (experimental).
57+
nonce: CSP nonce (meaning: one-time token) to allow this inline script.
58+
class_: Substituted as the DOM ``class`` attribute.
59+
id_: DOM ``id`` attribute.
60+
style: Inline style attribute.
61+
custom_attributes: Keyword arguments transformed into tag attributes.
62+
"""
63+
64+
class Line(air.UnSafeTag):
65+
"""Provides the plotly dependency"""
66+
67+
@override
68+
def __init__(
69+
self,
70+
/,
71+
*,
72+
version: str = '3.4.0',
73+
library: str = 'plotly',
74+
**custom_attributes,
75+
):
76+
self.version = version
77+
super().__init__(**custom_attributes | locals_cleanup(locals()))

tests/test_plot_source.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from airplot import PlotSource
2+
3+
4+
def test_plot_source():
5+
assert PlotSource().render() == '<script charset="utf-8" src="https://cdn.plot.ly/plotly-3.4.0.min.js"></script>'

0 commit comments

Comments
 (0)