Skip to content

Add assets_ignore init keyword, regex filter for the assets files. #318

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.26.0 - 2018-08-20
## Added
- Added `assets_ignore` init keyword, regex filter for the assets files. [#318](https://github.com/plotly/dash/pull/318)

## 0.25.1 - 2018-08-20
## Fixed
- Ensure CSS/JS external resources are loaded before the assets. [#335](https://github.com/plotly/dash/pull/335)
Expand Down
14 changes: 11 additions & 3 deletions dash/dash.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ def __init__(
static_folder='static',
assets_folder=None,
assets_url_path='/assets',
assets_ignore='',
include_assets_files=True,
url_base_pathname='/',
assets_external_path=None,
include_assets_files=None,
url_base_pathname=None,
requests_pathname_prefix=None,
routes_pathname_prefix=None,
compress=True,
Expand Down Expand Up @@ -158,6 +159,8 @@ def _handle_error(error):
self._external_scripts = external_scripts or []
self._external_stylesheets = external_stylesheets or []

self.assets_ignore = assets_ignore

self.registered_paths = {}

# urls
Expand Down Expand Up @@ -895,6 +898,8 @@ def _setup_server(self):
def _walk_assets_directory(self):
walk_dir = self._assets_folder
slash_splitter = re.compile(r'[\\/]+')
ignore_filter = re.compile(self.assets_ignore) \
if self.assets_ignore else None

def add_resource(p, filepath):
res = {'asset_path': p, 'filepath': filepath}
Expand All @@ -914,7 +919,10 @@ def add_resource(p, filepath):
else:
base = splitted[0]

for f in sorted(files):
files_gen = (x for x in files if not ignore_filter.search(x)) \
if ignore_filter else files

for f in sorted(files_gen):
if base:
path = '/'.join([base, f])
else:
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.25.1'
__version__ = '0.26.0'
1 change: 1 addition & 0 deletions tests/assets/load_ignored.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
window.tested = 'IGNORED'; // Break the chain.
3 changes: 2 additions & 1 deletion tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,8 @@ def test_index_customization(self):
self.percy_snapshot('custom-index')

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