Skip to content
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

Add meta http-equiv for ie compatibility to the index by default. #316

Merged
merged 1 commit into from
Aug 1, 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
9 changes: 7 additions & 2 deletions dash/dash.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,16 +339,21 @@ def _generate_config_html(self):
).format(json.dumps(self._config()))

def _generate_meta_html(self):
has_ie_compat = any(
x.get('http-equiv', '') == 'X-UA-Compatible'
for x in self._meta_tags)
has_charset = any('charset' in x for x in self._meta_tags)

tags = []
if not has_ie_compat:
tags.append('<meta equiv="X-UA-Compatible" content="IE=edge">')
Copy link
Contributor

@ngnpope ngnpope Oct 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. Should this be http-equiv="..."?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it should.

if not has_charset:
tags.append('<meta charset="UTF-8"/>')
tags.append('<meta charset="UTF-8">')
for meta in self._meta_tags:
attributes = []
for k, v in meta.items():
attributes.append('{}="{}"'.format(k, v))
tags.append('<meta {} />'.format(' '.join(attributes)))
tags.append('<meta {}>'.format(' '.join(attributes)))

return '\n '.join(tags)

Expand Down
14 changes: 7 additions & 7 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,10 @@ def display_output(react_value, flow_value):
self.percy_snapshot(name='flowtype')

def test_meta_tags(self):
metas = (
metas = [
{'name': 'description', 'content': 'my dash app'},
{'name': 'custom', 'content': 'customized'}
)
{'name': 'custom', 'content': 'customized'},
]

app = dash.Dash(meta_tags=metas)

Expand All @@ -285,12 +285,12 @@ def test_meta_tags(self):

meta = self.driver.find_elements_by_tag_name('meta')

# -1 for the meta charset.
self.assertEqual(len(metas), len(meta) - 1, 'Not enough meta tags')
# -2 for the meta charset and http-equiv.
self.assertEqual(len(metas), len(meta) - 2, 'Not enough meta tags')

for i in range(1, len(meta)):
for i in range(2, len(meta)):
meta_tag = meta[i]
meta_info = metas[i - 1]
meta_info = metas[i - 2]
name = meta_tag.get_attribute('name')
content = meta_tag.get_attribute('content')
self.assertEqual(name, meta_info['name'])
Expand Down