Skip to content

Commit

Permalink
Merge pull request #316 from plotly/ie-compat-meta-tag
Browse files Browse the repository at this point in the history
Add meta http-equiv for ie compatibility to the index by default.
  • Loading branch information
T4rk1n authored Aug 1, 2018
2 parents 8a9820c + 0b3b55c commit e3a5486
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
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">')
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

0 comments on commit e3a5486

Please # to comment.