1
0
mirror of https://github.com/github/choosealicense.com synced 2024-07-05 01:39:38 +02:00

Merge pull request #569 from wking/fsf-api

spec_helper: Extract FSF approval from wking.github.io/fsf-api
This commit is contained in:
Mike Linksvayer 2018-01-03 11:57:21 -08:00 committed by GitHub
commit 156babeadf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 17 deletions

View File

@ -17,7 +17,6 @@ end
group :test do group :test do
gem 'html-proofer', '~> 3.0' gem 'html-proofer', '~> 3.0'
gem 'licensee' gem 'licensee'
gem 'nokogiri'
gem 'rake' gem 'rake'
gem 'rspec' gem 'rspec'
gem 'rubocop' gem 'rubocop'

View File

@ -4,7 +4,6 @@ require 'jekyll'
require 'json' require 'json'
require 'licensee' require 'licensee'
require 'open-uri' require 'open-uri'
require 'nokogiri'
module SpecHelper module SpecHelper
class << self class << self
@ -102,23 +101,15 @@ end
def fsf_approved_licenses def fsf_approved_licenses
SpecHelper.fsf_approved_licenses ||= begin SpecHelper.fsf_approved_licenses ||= begin
url = 'https://www.gnu.org/licenses/license-list.en.html' url = 'https://wking.github.io/fsf-api/licenses-full.json'
doc = Nokogiri::HTML(open(url).read) object = JSON.parse(open(url).read)
list = doc.css('.green dt')
licenses = {} licenses = {}
list.each do |license| object.each_value do |meta|
a = license.css('a').find { |link| !link.text.nil? && !link.text.empty? && link.attr('id') } next unless (meta.include? 'identifiers') && (meta['identifiers'].include? 'spdx') && (meta.include? 'tags') && (meta['tags'].include? 'libre')
next if a.nil? meta['identifiers']['spdx'].each do |identifier|
id = a.attr('id').downcase licenses[identifier.downcase] = meta['name']
name = a.text.strip end
licenses[id] = name
end end
# FSF approved the Clear BSD, but doesn't use its SPDX ID or Name
if licenses.keys.include? 'clearbsd'
licenses['bsd-3-clause-clear'] = licenses['clearbsd']
end
licenses licenses
end end
end end