Skip to content

Commit

Permalink
Merge pull request #318 from plotly/assets-ignore
Browse files Browse the repository at this point in the history
Add `assets_ignore` init keyword, regex filter for the assets files.
  • Loading branch information
T4rk1n authored Aug 20, 2018
2 parents 936bd6a + 20b0405 commit e5f7d20
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 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.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

0 comments on commit e5f7d20

Please sign in to comment.