Skip to content

Commit

Permalink
Resolve issues with inline resources on save (#2794)
Browse files Browse the repository at this point in the history
* Fix saving using inline resources

* Add tests
  • Loading branch information
philippjfr committed Sep 30, 2021
1 parent bc6b0c2 commit 3624b5f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion panel/io/save.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def save(panel, filename, title=None, resources=None, template=None,
resources = Resources.from_bokeh(resources)

# Set resource mode
with set_resource_mode(mode):
with set_resource_mode(resources):
html = file_html(doc, resources, title, **kwargs)
if hasattr(filename, 'write'):
if isinstance(filename, io.BytesIO):
Expand Down
24 changes: 23 additions & 1 deletion panel/tests/io/test_save.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import re

from io import StringIO

from panel.pane import Vega
from panel.pane import Alert, Vega
from panel.models.vega import VegaPlot


Expand Down Expand Up @@ -30,3 +32,23 @@ def test_save_external():
html = sio.read()
for js in VegaPlot.__javascript_raw__:
assert js in html


def test_save_inline_resources():
alert = Alert('# Save test')

sio = StringIO()
alert.save(sio, resources='inline')
sio.seek(0)
html = sio.read()
assert '.bk.alert-primary' in html


def test_save_cdn_resources():
alert = Alert('# Save test')

sio = StringIO()
alert.save(sio, resources='cdn')
sio.seek(0)
html = sio.read()
assert re.findall('https://unpkg.com/@holoviz/panel@(.*)/dist/css/alerts.css', html)

0 comments on commit 3624b5f

Please sign in to comment.