Skip to content

Commit

Permalink
Merge pull request #374 from plotly/fix-assets-url-path
Browse files Browse the repository at this point in the history
Use `assets_url_path` in `get_asset_url`.
  • Loading branch information
T4rk1n committed Sep 10, 2018
2 parents cc85eb4 + 7e075d1 commit dbcb2a1
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.26.5 - 2018-09-10
## Fixed
- Fix `get_asset_url` with a different `assets_url_path`. [#374](https://github.com/plotly/dash/pull/374)

## 0.26.4 - 2018-08-28
## Fixed
- Set `url_base_pathname` to `None` in `Dash.__init__`. Fix [#364](https://github.com/plotly/dash/issues/364)
Expand Down
9 changes: 7 additions & 2 deletions dash/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,19 @@ def format_tag(tag_name, attributes, inner='', closed=False, opened=False):
'{}="{}"'.format(k, v) for k, v in attributes.items()]))


def get_asset_path(requests_pathname, routes_pathname, asset_path):
def get_asset_path(
requests_pathname,
routes_pathname,
asset_path,
asset_url_path):

i = requests_pathname.rfind(routes_pathname)
req = requests_pathname[:i]

return '/'.join([
# Only take the first part of the pathname
req,
'assets',
asset_url_path,
asset_path
])

Expand Down
9 changes: 7 additions & 2 deletions dash/dash.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def __init__(
self._assets_folder = assets_folder or os.path.join(
flask.helpers.get_root_path(name), 'assets'
)
self._assets_url_path = assets_url_path

# allow users to supply their own flask server
self.server = server or Flask(name, static_folder=static_folder)
Expand Down Expand Up @@ -944,10 +945,14 @@ def add_resource(p, filepath):
self._favicon = path

def get_asset_url(self, path):
return _get_asset_path(
asset = _get_asset_path(
self.config.requests_pathname_prefix,
self.config.routes_pathname_prefix,
path)
path,
self._assets_url_path.lstrip('/')
)

return asset

def run_server(self,
port=8050,
Expand Down
2 changes: 1 addition & 1 deletion dash/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.26.4'
__version__ = '0.26.5'
6 changes: 3 additions & 3 deletions tests/test_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,16 @@ def test_pathname_prefix_environ_requests(self):
def test_pathname_prefix_assets(self):
req = '/'
routes = '/'
path = get_asset_path(req, routes, 'reset.css')
path = get_asset_path(req, routes, 'reset.css', 'assets')
self.assertEqual('/assets/reset.css', path)

req = '/requests/'
path = get_asset_path(req, routes, 'reset.css')
path = get_asset_path(req, routes, 'reset.css', 'assets')
self.assertEqual('/requests/assets/reset.css', path)

req = '/requests/routes/'
routes = '/routes/'
path = get_asset_path(req, routes, 'reset.css')
path = get_asset_path(req, routes, 'reset.css', 'assets')
self.assertEqual('/requests/assets/reset.css', path)


Expand Down
4 changes: 3 additions & 1 deletion tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,9 @@ def test_index_customization(self):
self.percy_snapshot('custom-index')

def test_assets(self):
app = dash.Dash(assets_folder='tests/assets',
app = dash.Dash(__name__,
assets_folder='tests/assets',
assets_url_path='/test-assets',
assets_ignore='.*ignored.*')
app.index_string = '''
<!DOCTYPE html>
Expand Down

0 comments on commit dbcb2a1

Please sign in to comment.