From 5b3e3b3e531aac3863824bb4688626096f1a3692 Mon Sep 17 00:00:00 2001 From: Enoc Date: Mon, 3 May 2021 01:35:12 -0600 Subject: [PATCH] Fix minor issues of the compatibility tables --- lib/docs/core/compat_tables.rb | 112 ++++++++++++++++++--------------- 1 file changed, 61 insertions(+), 51 deletions(-) diff --git a/lib/docs/core/compat_tables.rb b/lib/docs/core/compat_tables.rb index fcc1abeb..82fbac31 100644 --- a/lib/docs/core/compat_tables.rb +++ b/lib/docs/core/compat_tables.rb @@ -1,7 +1,6 @@ module CompatTables require 'json' require 'net/http' - require 'pry' BROWSERS = { 'chrome' => 'Chrome', @@ -36,7 +35,7 @@ module CompatTables uris = [] index_json['doc']['body'].each do |element| - uris.push(element['value']['dataURL']) if element['type'] == 'browser_compatibility' + uris.push(element['value']['dataURL']) if element['type'] == 'browser_compatibility' and element['value']['dataURL'] end uris.map! do |uri| @@ -94,7 +93,13 @@ module CompatTables last_table_entry = html_table.at_css('tbody').last_element_child - last_table_entry.add_child("#{key}") + if key == '__compat' + tmp = slug.split('/') + last_table_entry.add_child("#{tmp.last}") + else + last_table_entry.add_child("#{key}") + end + BROWSERS.keys.each do |browser_key| if key == '__compat' @@ -111,71 +116,76 @@ module CompatTables version_removed = [] notes = [] - if json.is_a?(Array) - json.each do |element| + if json + if json.is_a?(Array) + json.each do |element| - if element['version_added'] - version_added.push(element['version_added']) - else - version_added.push(false) - end + if element['version_added'] + version_added.push(element['version_added']) + else + version_added.push(false) + end + + if element['version_removed'] + version_removed.push(element['version_removed']) + else + version_removed.push(false) + end + + if element['notes'] + notes.push(element['notes']) + else + notes.push(false) + end - if element['version_removed'] - version_removed.push(element['version_removed']) - else - version_removed.push(false) end + else + version_added.push(json['version_added']) + version_removed.push(json['version_removed']) + notes.push(json['notes']) + end - if element['notes'] - notes.push(element['notes']) + version_added.map! do |version| + if version == true + version = 'Yes' + elsif version == false + version = 'No' + elsif version.is_a?(Numeric) else - notes.push(false) + version = '?' end + version end - else - version_added.push(json['version_added']) - version_removed.push(json['version_removed']) - notes.push(json['notes']) - end - - version_added.map! do |version| - if version == true - version = 'Yes' - elsif version == false - version = 'No' - elsif version.is_a?(Numeric) - else - version = '?' - end - - version - end - if version_removed[0] - format_string = "" - else - if version_added[0] == 'No' + if version_removed[0] format_string = "" else - format_string = "" + if version_added[0] == 'No' + format_string = "" + else + format_string = "" + end end - end - for value in (0..version_added.length-1) do - if version_removed[value] - format_string += "
#{version_added[value]}-#{version_removed[value]}
" - else - if version_added[value] == 'No' - format_string += "
#{version_added[value]}
" + for value in (0..version_added.length-1) do + if version_removed[value] + format_string += "
#{version_added[value]}-#{version_removed[value]}
" else - format_string += "
#{version_added[value]}
" + if version_added[value] == 'No' + format_string += "
#{version_added[value]}
" + else + format_string += "
#{version_added[value]}
" + end end - end - if notes[value] - format_string += "
#{notes[value]}
" + if notes[value] + format_string += "
#{notes[value]}
" + end end + + else + format_string = "
?
" end entry.add_child(format_string)