diff --git a/src/turbo_flask/turbo.py b/src/turbo_flask/turbo.py
index 7496f5c..b8307a0 100644
--- a/src/turbo_flask/turbo.py
+++ b/src/turbo_flask/turbo.py
@@ -4,9 +4,9 @@
from markupsafe import Markup
-_CDN = 'https://cdn.skypack.dev'
+_CDN = 'https://cdn.jsdelivr.net'
_PKG = '@hotwired/turbo'
-_VER = 'v7.2.2-RBjb2wnkmosSQVoP27jT'
+_VER = '7.2.2'
class Turbo:
@@ -52,14 +52,16 @@ def turbo(self, version=_VER, url=None):
default version and CDN.
"""
if url is None:
- url = f'{_CDN}/pin/{_PKG}@{version}/min/{_PKG}.js'
+ v = ''
+ if version is not None:
+ v = f'@{version}'
+ url = f'{_CDN}/npm/{_PKG}{v}/dist/turbo.es2017-umd.js'
ws_route = current_app.config.get('TURBO_WEBSOCKET_ROUTE',
'/turbo-stream')
if ws_route:
- return Markup(f'''''') # noqa: E501
+ return Markup(f'''
+
+''') # noqa: E501
else:
return Markup(f'')
diff --git a/tests/test_turbo.py b/tests/test_turbo.py
index d959e5c..6eabc78 100644
--- a/tests/test_turbo.py
+++ b/tests/test_turbo.py
@@ -20,7 +20,7 @@ def test():
('__flask_sock.turbo_stream', {})
rv = app.test_client().get('/test')
- assert b'@hotwired/turbo.js' in rv.data
+ assert b'@hotwired/turbo@' in rv.data
assert b'Turbo.connectStreamSource' in rv.data
def test_indirect_create(self):
@@ -37,7 +37,7 @@ def test():
('__flask_sock.turbo_stream', {})
rv = app.test_client().get('/test')
- assert b'@hotwired/turbo.js' in rv.data
+ assert b'@hotwired/turbo@' in rv.data
assert b'Turbo.connectStreamSource' in rv.data
def test_create_custom_ws(self):
@@ -56,7 +56,7 @@ def test():
('__flask_sock.turbo_stream', {})
rv = app.test_client().get('/test')
- assert b'@hotwired/turbo.js' in rv.data
+ assert b'@hotwired/turbo@' in rv.data
assert b'Turbo.connectStreamSource' in rv.data
def test_create_no_ws(self):
@@ -73,7 +73,7 @@ def test():
url_adapter.match('/turbo-stream', websocket=True)
rv = app.test_client().get('/test')
- assert b'@hotwired/turbo.js' in rv.data
+ assert b'@hotwired/turbo@' in rv.data
assert b'Turbo.connectStreamSource' not in rv.data
def test_create_custom_turbo_version(self):
@@ -82,14 +82,30 @@ def test_create_custom_turbo_version(self):
@app.route('/test')
def test():
- return render_template_string('{{ turbo(version="v1.2.3") }}')
+ return render_template_string('{{ turbo(version="1.2.3") }}')
url_adapter = app.url_map.bind('localhost', '/')
assert url_adapter.match('/turbo-stream', websocket=True) == \
('__flask_sock.turbo_stream', {})
rv = app.test_client().get('/test')
- assert b'@hotwired/turbo@v1.2.3' in rv.data
+ assert b'@hotwired/turbo@1.2.3/dist' in rv.data
+ assert b'Turbo.connectStreamSource' in rv.data
+
+ def test_create_latest_turbo_version(self):
+ app = Flask(__name__)
+ turbo_flask.Turbo(app)
+
+ @app.route('/test')
+ def test():
+ return render_template_string('{{ turbo(version=None) }}')
+
+ url_adapter = app.url_map.bind('localhost', '/')
+ assert url_adapter.match('/turbo-stream', websocket=True) == \
+ ('__flask_sock.turbo_stream', {})
+
+ rv = app.test_client().get('/test')
+ assert b'@hotwired/turbo/dist' in rv.data
assert b'Turbo.connectStreamSource' in rv.data
def test_create_custom_turbo_url(self):