Skip to content
This repository has been archived by the owner on Nov 10, 2017. It is now read-only.

Commit

Permalink
bug 1128525 - Move browser name fixes to data
Browse files Browse the repository at this point in the history
This code is going to get more complicated. Move the ugliness to
mdn/data.py in preparation.
  • Loading branch information
jwhitlock committed Oct 2, 2015
1 parent 69aa182 commit 8747b27
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
13 changes: 1 addition & 12 deletions mdn/compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,21 +219,10 @@ def extract_feature_header(self, element):
self.add_issue('feature_header', element, header=header)
self.columns.append(header)

browser_name_fixes = {
'Firefox (Gecko)': 'Firefox',
'Firefox Mobile (Gecko)': 'Firefox Mobile',
'Firefox OS (Gecko)': 'Firefox OS',
'Safari (WebKit)': 'Safari',
'Windows Phone': 'IE Mobile',
'IE Phone': 'IE Mobile',
'IE': 'Internet Explorer',
}

def extract_browser_name(self, element):
colspan = int(element.attributes.get('colspan', 1))
raw_name = element.to_text()
fixed_name = self.browser_name_fixes.get(raw_name, raw_name)
browser_params = self.data.lookup_browser_params(fixed_name)
browser_params = self.data.lookup_browser_params(raw_name)
browser, browser_id, name, slug = browser_params
if not browser:
self.add_issue('unknown_browser', element, name=raw_name)
Expand Down
23 changes: 18 additions & 5 deletions mdn/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ def __init__(self):
BrowserParams = namedtuple(
'BrowserParams', ['browser', 'browser_id', 'name', 'slug'])

browser_name_fixes = {
'Firefox (Gecko)': 'Firefox',
'Firefox Mobile (Gecko)': 'Firefox Mobile',
'Firefox OS (Gecko)': 'Firefox OS',
'Safari (WebKit)': 'Safari',
'Windows Phone': 'IE Mobile',
'IE Phone': 'IE Mobile',
'IE': 'Internet Explorer',
}

def lookup_browser_params(self, name, locale='en'):
"""Get or create the browser ID, name, and slug given a raw name.
Expand All @@ -41,13 +51,16 @@ def lookup_browser_params(self, name, locale='en'):
self.browser_data[key] = self.BrowserParams(
browser, browser.pk, key, browser.slug)

# Handle common alternate names
fixed_name = self.browser_name_fixes.get(name, name)

# Select the Browser ID and slug
if name not in self.browser_data:
browser_id = '_' + name
if fixed_name not in self.browser_data:
browser_id = '_' + fixed_name
# TODO: unique slugify instead of browser_id
self.browser_data[name] = self.BrowserParams(
None, browser_id, name, browser_id)
return self.browser_data[name]
self.browser_data[fixed_name] = self.BrowserParams(
None, browser_id, fixed_name, browser_id)
return self.browser_data[fixed_name]

FeatureParams = namedtuple(
'FeatureParams', ['feature', 'feature_id', 'slug'])
Expand Down

0 comments on commit 8747b27

Please sign in to comment.