Skip to content

Commit

Permalink
Updated turbo.js to v7-beta5
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelgrinberg committed May 1, 2021
1 parent 71deb03 commit 012948a
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions turbo_flask/turbo.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

_CDN = 'https://cdn.skypack.dev'
_PKG = '@hotwired/turbo'
_VER = 'v7.0.0-beta.4-TQFv5Y2xd4hn2VnTxVul'
_VER = 'v7.0.0-beta.5-LhgiwOUjafYu3bb8VbTv'


class Turbo:
Expand All @@ -18,7 +18,8 @@ def __init__(self, app=None):
self.init_app(app)

def init_app(self, app):
ws_route = app.config.get('TURBO_WEBSOCKET_ROUTE', '/turbo-stream')
ws_route = app.config.setdefault('TURBO_WEBSOCKET_ROUTE',
'/turbo-stream')
if ws_route:
self.sock = Sock()

Expand Down Expand Up @@ -58,9 +59,10 @@ def default_user_id(self):
return uuid.uuid4().hex

def turbo(self, version=_VER, url=None):
"""Add turbo.js to the template.
"""Add turbo.js to the page.
Add `{{ turbo() }}` in the `<head>` section of your main template.
You must add `{{ turbo() }}` in the `<head>` section of your main
template to activate turbo.js.
"""
if url is None:
url = f'{_CDN}/pin/{_PKG}@{version}/min/{_PKG}.js'
Expand All @@ -69,7 +71,7 @@ def turbo(self, version=_VER, url=None):
if ws_route:
return Markup(f'''<script type="module">
import * as Turbo from "{url}";
Turbo.connectStreamSource(new WebSocket(`ws://${{location.host}}/{ws_route}`));
Turbo.connectStreamSource(new WebSocket(`ws://${{location.host}}{ws_route}`));
</script>''')
else:
return Markup(f'<script type="module" src="{url}"></script>')
Expand Down

0 comments on commit 012948a

Please sign in to comment.