-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Manage javascript and css import with Link objects ; embed notebook d…
…isplay in an iframe
- Loading branch information
Showing
3 changed files
with
71 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from six import Module_six_moves_urllib as urllib | ||
|
||
class Link(object): | ||
def __init__(self, url, download=False): | ||
"""Create a link object base on an url. | ||
Parameters | ||
---------- | ||
url : str | ||
The url to be linked | ||
download : bool, default False | ||
Whether the target document shall be loaded right now. | ||
""" | ||
self.url = url | ||
self.code = None | ||
if download: | ||
self.code = urllib.request.urlopen(self.url).read() | ||
|
||
class JavascriptLink(Link): | ||
def render(self, embedded=False): | ||
"""Renders the object. | ||
Parameters | ||
---------- | ||
embedded : bool, default False | ||
Whether the code shall be embedded explicitely in the render. | ||
""" | ||
if embedded: | ||
if self.code is None: | ||
self.code = urllib.request.urlopen(self.url).read() | ||
return '<script>{}</script>'.format(self.code) | ||
else: | ||
return '<script src="{}"></script>'.format(self.url) | ||
|
||
class CssLink(Link): | ||
def render(self, embedded=False): | ||
"""Renders the object. | ||
Parameters | ||
---------- | ||
embedded : bool, default False | ||
Whether the code shall be embedded explicitely in the render. | ||
""" | ||
if embedded: | ||
if self.code is None: | ||
self.code = urllib.request.urlopen(self.url).read() | ||
return '<style>{}</style>'.format(self.code) | ||
else: | ||
return '<link rel="stylesheet" href="{}" />'.format(self.url) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters