Skip to content

Commit 520d00b

Browse files
committed
Add assets_ignore init keyword, regex filter for the assets files.
1 parent 5fc998a commit 520d00b

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

dash/dash.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,10 @@ def __init__(
7373
static_folder='static',
7474
assets_folder=None,
7575
assets_url_path='/assets',
76+
assets_ignore='',
77+
include_assets_files=True,
78+
url_base_pathname='/',
7679
assets_external_path=None,
77-
include_assets_files=None,
78-
url_base_pathname=None,
7980
requests_pathname_prefix=None,
8081
routes_pathname_prefix=None,
8182
compress=True,
@@ -158,6 +159,8 @@ def _handle_error(error):
158159
self._external_scripts = external_scripts or []
159160
self._external_stylesheets = external_stylesheets or []
160161

162+
self.assets_ignore = assets_ignore
163+
161164
self.registered_paths = {}
162165

163166
# urls
@@ -898,6 +901,8 @@ def _setup_server(self):
898901
def _walk_assets_directory(self):
899902
walk_dir = self._assets_folder
900903
slash_splitter = re.compile(r'[\\/]+')
904+
ignore_filter = re.compile(self.assets_ignore) \
905+
if self.assets_ignore else None
901906

902907
def add_resource(p, filepath):
903908
res = {'asset_path': p, 'filepath': filepath}
@@ -917,7 +922,10 @@ def add_resource(p, filepath):
917922
else:
918923
base = splitted[0]
919924

920-
for f in sorted(files):
925+
files_gen = (x for x in files if not ignore_filter.search(x)) \
926+
if ignore_filter else files
927+
928+
for f in sorted(files_gen):
921929
if base:
922930
path = '/'.join([base, f])
923931
else:

tests/assets/load_ignored.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
window.tested = 'IGNORED'; // Break the chain.

tests/test_integration.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,8 @@ def test_index_customization(self):
363363
self.percy_snapshot('custom-index')
364364

365365
def test_assets(self):
366-
app = dash.Dash(assets_folder='tests/assets')
366+
app = dash.Dash(assets_folder='tests/assets',
367+
assets_ignore='.*ignored.*')
367368
app.index_string = '''
368369
<!DOCTYPE html>
369370
<html>

0 commit comments

Comments
 (0)