Skip to content

Commit 5754f29

Browse files
author
Randy Zwitch
authored
Add docstrings (#1)
1 parent a1d6c34 commit 5754f29

File tree

2 files changed

+140
-1
lines changed

2 files changed

+140
-1
lines changed

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
recursive-include streamlit_victory/frontend/build *
1+

streamlit_embedcode/__init__.py

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,48 @@
22

33

44
def _clean_link(link):
5+
"""Strip trailing slash if present on link.
6+
7+
Parameters
8+
----------
9+
link : str
10+
URL from code sharing website
11+
12+
Returns
13+
-------
14+
str
15+
Returns value of `link` without trailing slash.
16+
17+
Example
18+
-------
19+
>>> _clean_link("https://gist.github.com/randyzwitch/be8c5e9fb5b8e7b046afebcac12e5087/")
20+
'https://gist.github.com/randyzwitch/be8c5e9fb5b8e7b046afebcac12e5087'
21+
22+
>>> _clean_link("https://gist.github.com/randyzwitch/be8c5e9fb5b8e7b046afebcac12e5087")
23+
'https://gist.github.com/randyzwitch/be8c5e9fb5b8e7b046afebcac12e5087'
24+
"""
25+
526
return link[:-1] if link[-1] == "/" else link
627

728

829
def github_gist(link, height=600, width=950, scrolling=True):
30+
"""Embed a GitHub gist.
31+
32+
Parameters
33+
----------
34+
link : str
35+
URL from https://gist.github.com/
36+
height: int
37+
Height of the resulting iframe
38+
width: int
39+
Width of the resulting iframe
40+
scrolling: bool
41+
If content is larger than iframe size, provide scrollbars?
42+
43+
Example
44+
-------
45+
>>> github_gist("https://gist.github.com/randyzwitch/be8c5e9fb5b8e7b046afebcac12e5087/")
46+
"""
947

1048
gistcreator, gistid = _clean_link(link).split("/")[-2:]
1149
return st.html(
@@ -17,6 +55,23 @@ def github_gist(link, height=600, width=950, scrolling=True):
1755

1856

1957
def gitlab_snippet(link, height=600, width=950, scrolling=True):
58+
"""Embed a Gitlab snippet.
59+
60+
Parameters
61+
----------
62+
link : str
63+
URL from https://gitlab.com/explore/snippets
64+
height: int
65+
Height of the resulting iframe
66+
width: int
67+
Width of the resulting iframe
68+
scrolling: bool
69+
If content is larger than iframe size, provide scrollbars?
70+
71+
Example
72+
-------
73+
>>> gitlab_snippet("https://gitlab.com/snippets/1990429/", height = 400)
74+
"""
2075

2176
snippetnumber = _clean_link(link).split("/")[-1]
2277
return st.html(
@@ -28,6 +83,23 @@ def gitlab_snippet(link, height=600, width=950, scrolling=True):
2883

2984

3085
def pastebin_snippet(link, height=600, width=950, scrolling=True):
86+
"""Embed a Pastebin snippet.
87+
88+
Parameters
89+
----------
90+
link : str
91+
URL from https://pastebin.com/
92+
height: int
93+
Height of the resulting iframe
94+
width: int
95+
Width of the resulting iframe
96+
scrolling: bool
97+
If content is larger than iframe size, provide scrollbars?
98+
99+
Example
100+
-------
101+
>>> pastebin_snippet("https://pastebin.com/AWYbziQF", width = 600, scrolling = False)
102+
"""
31103

32104
snippetnumber = _clean_link(link).split("/")[-1]
33105
return st.html(
@@ -41,6 +113,28 @@ def pastebin_snippet(link, height=600, width=950, scrolling=True):
41113
def codepen_snippet(
42114
link, height=600, width=950, scrolling=True, theme="light", preview=True
43115
):
116+
"""Embed a CodePen snippet.
117+
118+
Parameters
119+
----------
120+
link : str
121+
URL from https://codepen.io/
122+
height: int
123+
Height of the resulting iframe
124+
width: int
125+
Width of the resulting iframe
126+
scrolling: bool
127+
If content is larger than iframe size, provide scrollbars?
128+
theme: str
129+
Color theme of snippet (i.e. "light", "dark")
130+
preview: bool
131+
Require snippet to be clicked to load. Setting `preview=True` can improve load times.
132+
133+
134+
Example
135+
-------
136+
>>> pastebin_snippet("https://pastebin.com/AWYbziQF", width = 600, scrolling = False)
137+
"""
44138

45139
user, _, slughash = _clean_link(link).split("/")[-3:]
46140
return st.html(
@@ -62,6 +156,23 @@ def codepen_snippet(
62156

63157

64158
def ideone_snippet(link, height=600, width=950, scrolling=True):
159+
"""Embed a Ideone snippet.
160+
161+
Parameters
162+
----------
163+
link : str
164+
URL from https://ideone.com/
165+
height: int
166+
Height of the resulting iframe
167+
width: int
168+
Width of the resulting iframe
169+
scrolling: bool
170+
If content is larger than iframe size, provide scrollbars?
171+
172+
Example
173+
-------
174+
>>> ideone_snippet("https://ideone.com/vQ54cr")
175+
"""
65176

66177
snippetnumber = _clean_link(link).split("/")[-1]
67178
return st.html(
@@ -70,3 +181,31 @@ def ideone_snippet(link, height=600, width=950, scrolling=True):
70181
width=width,
71182
scrolling=scrolling,
72183
)
184+
185+
186+
def tagmycode_snippet(link, height=600, width=950, scrolling=True):
187+
"""Embed a TagMyCode snippet.
188+
189+
Parameters
190+
----------
191+
link : str
192+
URL from https://tagmycode.com/
193+
height: int
194+
Height of the resulting iframe
195+
width: int
196+
Width of the resulting iframe
197+
scrolling: bool
198+
If content is larger than iframe size, provide scrollbars?
199+
200+
Example
201+
-------
202+
>>> tagmycode_snippet("https://tagmycode.com/snippet/14040/css-structure#.XvYhunVKglU")
203+
"""
204+
205+
snippetnumber = _clean_link(link).split("/")[-2]
206+
return st.html(
207+
f"""<script src="https://tagmycode.com/embed/js/{snippetnumber}"></script>""",
208+
height=height,
209+
width=width,
210+
scrolling=scrolling,
211+
)

0 commit comments

Comments
 (0)