1
0
mirror of https://github.com/github/choosealicense.com synced 2024-12-22 04:40:09 +01:00

Merge branch 'gh-pages' into jekyll-3-0-3

This commit is contained in:
Ben Balter 2016-02-09 12:26:24 -05:00
commit 2fb71d284a
16 changed files with 187 additions and 153 deletions

17
.rubocop.yml Normal file
View File

@ -0,0 +1,17 @@
AllCops:
TargetRubyVersion: 2.1
Exclude:
- _site/**/*
- vendor/**/*
Metrics/LineLength:
Enabled: false
Metrics/MethodLength:
Enabled: false
Metrics/AbcSize:
Enabled: false
Style/Documentation:
Enabled: false

13
Gemfile
View File

@ -1,7 +1,7 @@
source "https://rubygems.org" source 'https://rubygems.org'
gem "github-pages" gem 'github-pages'
gem "jekyll-seo-tag" gem 'jekyll-seo-tag'
group :development do group :development do
gem 'colored' gem 'colored'
@ -11,7 +11,8 @@ end
group :test do group :test do
gem 'html-proofer', '2.5.2' gem 'html-proofer', '2.5.2'
gem "rake" gem 'rake'
gem "rspec" gem 'rspec'
gem "nokogiri" gem 'nokogiri'
gem 'rubocop'
end end

View File

@ -1,18 +1,18 @@
require "html/proofer" require 'html/proofer'
require 'rspec/core/rake_task' require 'rspec/core/rake_task'
desc "Run specs" desc 'Run specs'
RSpec::Core::RakeTask.new do |t| RSpec::Core::RakeTask.new do |t|
t.pattern = 'spec/**/*_spec.rb' t.pattern = 'spec/**/*_spec.rb'
t.rspec_opts = ["--order", "rand", "--color"] t.rspec_opts = ['--order', 'rand', '--color']
end end
task :test do task :test do
sh "bundle exec jekyll build --trace" sh 'bundle exec jekyll build'
Rake::Task["spec"].invoke Rake::Task['spec'].invoke
HTML::Proofer.new("./_site", :check_html => true, HTML::Proofer.new('./_site', check_html: true,
:validation => { :ignore_script_embeds => true }, validation: { ignore_script_embeds: true },
:href_swap => { %r{http://choosealicense.com} => "" }).run href_swap: { %r{http://choosealicense.com} => '' }).run
end end
task :approved_licenses do task :approved_licenses do
@ -20,10 +20,10 @@ task :approved_licenses do
approved = approved_licenses approved = approved_licenses
approved.select! { |l| spdx_ids.include?(l) } approved.select! { |l| spdx_ids.include?(l) }
puts "#{approved.count} approved licenses:" puts "#{approved.count} approved licenses:"
puts approved.join(", ") puts approved.join(', ')
puts "\n" puts "\n"
potential = approved - licenses.map { |l| l["id"] } potential = approved - licenses.map { |l| l['id'] }
puts "#{potential.count} potential additions:" puts "#{potential.count} potential additions:"
puts potential.join(", ") puts potential.join(', ')
end end

View File

@ -42,9 +42,3 @@ forbidden:
- description: Software is provided without warranty and the software author/license owner cannot be held liable for damages. - description: Software is provided without warranty and the software author/license owner cannot be held liable for damages.
label: Hold Liable label: Hold Liable
tag: no-liability tag: no-liability
- description: This software may not be modified.
label: Modification
tag: modifications
- description: You may not distribute this software.
label: Distribution
tag: distribution

View File

@ -10,52 +10,52 @@ require 'fuzzy_match'
# Display usage instructions # Display usage instructions
if ARGV.count != 1 if ARGV.count != 1
puts File.open(__FILE__).read.scan(/^# .*/)[0...3].join("\n").gsub(/^# /,"") puts File.open(__FILE__).read.scan(/^# .*/)[0...3].join("\n").gsub(/^# /, '')
end end
class TrueClass class TrueClass
def to_s def to_s
"Yes".green 'Yes'.green
end end
end end
class FalseClass class FalseClass
def to_s def to_s
"No".red 'No'.red
end end
end end
license = ARGV[0].downcase.strip license = ARGV[0].downcase.strip
approvals = { approvals = {
"OSI": osi_approved_licenses, 'OSI' => osi_approved_licenses,
"FSF": fsf_approved_licenses, 'FSF' => fsf_approved_licenses,
"OD": od_approved_licenses 'OD' => od_approved_licenses
} }
id, spdx = find_spdx(license) id, spdx = find_spdx(license)
rows = [] rows = []
if spdx.nil? if spdx.nil?
id = "Invalid".red id = 'Invalid'.red
name = "None".red name = 'None'.red
else else
id = id.green id = id.green
name = spdx["name"].green name = spdx['name'].green
end end
rows << ["SPDX ID", id] rows << ['SPDX ID', id]
rows << ["SPDX Name", name] rows << ['SPDX Name', name]
approvals.each do |name, licenses| approvals.each do |approver, licenses|
rows << ["#{name} approved", licenses.include?(license)] rows << ["#{approver} approved", licenses.include?(license)]
end end
current = license_ids.include?(license) current = license_ids.include?(license)
rows << ["Current license", current] rows << ['Current license', current]
rows << :separator rows << :separator
eligible = !!(!current && spdx && approved_licenses.include?(license)) eligible = (!current && spdx && approved_licenses.include?(license))
rows << ["Eligible", eligible] rows << ['Eligible', eligible]
puts Terminal::Table.new title: "License: #{license}", rows: rows puts Terminal::Table.new title: "License: #{license}", rows: rows
puts puts
@ -63,7 +63,7 @@ puts "Code search: https://github.com/search?q=#{license}+filename%3ALICENSE&typ
if spdx.nil? if spdx.nil?
puts puts
puts "SPDX ID not found. Some possible matches:" puts 'SPDX ID not found. Some possible matches:'
puts puts
fm = FuzzyMatch.new(spdx_ids) fm = FuzzyMatch.new(spdx_ids)

View File

@ -4,3 +4,4 @@ set -e
echo "building the site..." echo "building the site..."
bundle exec rake test bundle exec rake test
bundle exec rubocop -D -S

View File

@ -1,7 +1,7 @@
#! /usr/bin/env ruby #! /usr/bin/env ruby
# downcases all licenses in a git-friendly way # downcases all licenses in a git-friendly way
Dir["_licenses/*"].each do |file| Dir['_licenses/*'].each do |file|
system "git mv #{file} #{file.downcase}2" system "git mv #{file} #{file.downcase}2"
system "git mv #{file.downcase}2 #{file.downcase}" system "git mv #{file.downcase}2 #{file.downcase}"
end end

View File

@ -5,32 +5,32 @@
require 'yaml' require 'yaml'
fields = YAML.load_file("_data/fields.yml") fields = YAML.load_file('_data/fields.yml')
meta = YAML.load_file("_data/meta.yml") meta = YAML.load_file('_data/meta.yml')
rules = YAML.load_file("_data/rules.yml") rules = YAML.load_file('_data/rules.yml')
puts "\n### Fields\n\n" puts "\n### Fields\n\n"
fields.each do |field| fields.each do |field|
puts "* `#{field["name"]}` - #{field["description"]}" puts "* `#{field['name']}` - #{field['description']}"
end end
puts "\n### YAML front matter\n" puts "\n### YAML front matter\n"
meta = meta.group_by { |m| m["required"] } meta = meta.group_by { |m| m['required'] }
puts "\n#### Required fields\n\n" puts "\n#### Required fields\n\n"
meta[true].each do |meta| meta[true].each do |field|
puts "* `#{meta["name"]}` - #{meta["description"]}" puts "* `#{field['name']}` - #{field['description']}"
end end
puts "\n#### Optional fields\n\n" puts "\n#### Optional fields\n\n"
meta[false].each do |meta| meta[false].each do |field|
puts "* `#{meta["name"]}` - #{meta["description"]}" puts "* `#{field['name']}` - #{field['description']}"
end end
puts "\n### Rules\n" puts "\n### Rules\n"
rules.each do |group, rules| rules.each do |group, group_rules|
puts "\n#### #{group.capitalize}\n\n" puts "\n#### #{group.capitalize}\n\n"
rules.each do |rule| group_rules.each do |rule|
puts "* `#{rule["tag"]}` - #{rule["description"]}" puts "* `#{rule['tag']}` - #{rule['description']}"
end end
end end

View File

@ -1,11 +1,11 @@
require 'spec_helper' require 'spec_helper'
describe "byte order marks" do describe 'byte order marks' do
Dir["#{licenses_path}/*.txt"].each do |file| Dir["#{licenses_path}/*.html"].each do |file|
context "the #{File.basename(file, ".txt")} license" do context "the #{File.basename(file, '.txt')} license" do
it "does not begin with a byte order mark" do it 'does not begin with a byte order mark' do
bom = !!(File.open(file).read =~ /\A\xEF\xBB\xBF/) bom = File.open(file).read.start_with?("\u0000EF\u0000BB\u0000BF")
msg = "License file begins with a Byte Order Mark. See http://stackoverflow.com/a/1068700." msg = 'License file begins with a Byte Order Mark. See http://stackoverflow.com/a/1068700.'
expect(bom).to eql(false), msg expect(bom).to eql(false), msg
end end
end end

View File

@ -1,30 +1,30 @@
require 'spec_helper' require 'spec_helper'
describe "license categories" do describe 'license categories' do
families.each do |family| families.each do |family|
context "the #{family} family" do context "the #{family} family" do
family_licenses = licenses.select { |l| l["family"] == family } family_licenses = licenses.select { |l| l['family'] == family }
primary = family_licenses.select { |l| l["variant"] == false } primary = family_licenses.select { |l| l['variant'] == false }
variants = family_licenses.select { |l| l["variant"] == true } variants = family_licenses.select { |l| l['variant'] == true }
it "should only have one primary license" do it 'should only have one primary license' do
expect(primary.count).to eql(1) expect(primary.count).to eql(1)
end end
it "all other licenses should be variants" do it 'all other licenses should be variants' do
expected = family_licenses.count - 1 expected = family_licenses.count - 1
expect(variants.count).to eql(expected) expect(variants.count).to eql(expected)
end end
family_licenses.each do |license| family_licenses.each do |license|
context "the #{license["title"]} license" do context "the #{license['title']} license" do
it "should have a unique slug" do it 'should have a unique slug' do
dupes = family_licenses.select { |l| l["tab-slug"] == license["tab-slug"] }.count dupes = family_licenses.count { |l| l['tab-slug'] == license['tab-slug'] }
expect(dupes).to eql(1) expect(dupes).to eql(1)
end end
it "should have a valid tab-slug" do it 'should have a valid tab-slug' do
expect(license["tab-slug"]).to match(/[a-z0-9_]/) expect(license['tab-slug']).to match(/[a-z0-9_]/)
end end
end end
end end

View File

@ -1,11 +1,11 @@
require 'spec_helper' require 'spec_helper'
describe "license fillable fields" do describe 'license fillable fields' do
licenses.each do |license| licenses.each do |license|
context "The #{license["title"]} license" do context "The #{license['title']} license" do
it "should only contain supported fillable fields" do it 'should only contain supported fillable fields' do
matches = license["content"].scan(/\[([a-z]+)\]/) matches = license['content'].scan(/\[([a-z]+)\]/)
extra_fields = matches.flatten - fields.map { |f| f["name"] } extra_fields = matches.flatten - fields.map { |f| f['name'] }
expect(extra_fields).to be_empty expect(extra_fields).to be_empty
end end
end end

View File

@ -1,31 +1,30 @@
require 'spec_helper' require 'spec_helper'
describe "license meta" do describe 'license meta' do
licenses.each do |license| licenses.each do |license|
# Manually load the raw license so we don't get the defaults
raw_fields = SafeYAML.load_file("_licenses/#{license['id']}.txt")
# Manually load the raw license so we don't get thed defaults context "The #{license['title']} license" do
raw_fields = SafeYAML.load_file("_licenses/#{license["id"]}.txt") it 'should only contain supported meta fields' do
extra_fields = raw_fields.keys - meta.map { |m| m['name'] }
context "The #{license["title"]} license" do
it "should only contain supported meta fields" do
extra_fields = raw_fields.keys - meta.map { |m| m["name"] }
expect(extra_fields).to be_empty expect(extra_fields).to be_empty
end end
it "should contain all required meta fields" do it 'should contain all required meta fields' do
required = meta.select { |m| m["required"] }.map { |m| m["name"] } required = meta.select { |m| m['required'] }.map { |m| m['name'] }
missing = required - raw_fields.keys missing = required - raw_fields.keys
expect(missing).to be_empty expect(missing).to be_empty
end end
if license["family"] if license['family']
it "should contain the required license variant fields" do it 'should contain the required license variant fields' do
missing = ["family", "tab-slug"] - license.keys missing = ['family', 'tab-slug'] - license.keys
expect(missing).to be_empty expect(missing).to be_empty
end end
else else
it "should not contain license family specific fields" do it 'should not contain license family specific fields' do
extra = ["variant", "family", "tab-slug"].select{ |f| raw_fields.keys.include?(f) } extra = ['variant', 'family', 'tab-slug'].select { |f| raw_fields.keys.include?(f) }
expect(extra).to be_empty expect(extra).to be_empty
end end
end end

View File

@ -1,21 +1,19 @@
require 'spec_helper' require 'spec_helper'
describe "license rules" do describe 'license rules' do
licenses.each do |license| licenses.each do |license|
groups = rules.keys groups = rules.keys
context "The #{license["title"]} license" do context "The #{license['title']} license" do
groups.each do |group| groups.each do |group|
valid_tags = rules[group].map { |r| r['tag'] }
valid_tags = rules[group].map { |r| r["tag"] }
context "the #{group} group" do context "the #{group} group" do
it "should exist" do it 'should exist' do
expect(license[group]).to_not be_nil expect(license[group]).to_not be_nil
end end
it "should only contain valid tags" do it 'should only contain valid tags' do
extra = license[group] - valid_tags extra = license[group] - valid_tags
expect(extra).to be_empty expect(extra).to be_empty
end end

View File

@ -1,10 +1,9 @@
require 'spec_helper' require 'spec_helper'
describe "shown licenses" do describe 'shown licenses' do
# Whitelist of popular licenses that are shown (non-hidden) # Whitelist of popular licenses that are shown (non-hidden)
# Note: most new licenses that are added should be hidden by default # Note: most new licenses that are added should be hidden by default
SHOWN_LICENSES = %w[ SHOWN_LICENSES = %w(
agpl-3.0 agpl-3.0
apache-2.0 apache-2.0
artistic-2.0 artistic-2.0
@ -20,16 +19,16 @@ describe "shown licenses" do
mit mit
mpl-2.0 mpl-2.0
unlicense unlicense
] ).freeze
it "has the expected number of shown licenses" do it 'has the expected number of shown licenses' do
expect(shown_licenses.count).to eql(15) expect(shown_licenses.count).to eql(15)
end end
shown_licenses.each do |license| shown_licenses.each do |license|
context "the #{license["title"]} license" do context "the #{license['title']} license" do
it "is whitelisted to be shown" do it 'is whitelisted to be shown' do
expect(SHOWN_LICENSES).to include(license["id"]) expect(SHOWN_LICENSES).to include(license['id'])
end end
end end
end end

View File

@ -1,30 +1,46 @@
require 'spec_helper' require 'spec_helper'
describe "licenses" do describe 'licenses' do
it 'matches the number of files in the _licenses folder' do
it "matches the number of files in the _licenses folder" do
expect(licenses.count).to eql(Dir["#{licenses_path}/*.txt"].count) expect(licenses.count).to eql(Dir["#{licenses_path}/*.txt"].count)
end end
licenses.each do |license| licenses.each do |license|
context "The #{license['title']} license" do
let(:id) { license['id'] }
context "The #{license["title"]} license" do it 'has an SPDX ID' do
let(:id) { license["id"] }
it "has an SPDX ID" do
expect(spdx_ids).to include(id) expect(spdx_ids).to include(id)
end end
it "uses its SPDX name" do it 'uses its SPDX name' do
spdx = find_spdx(id) spdx = find_spdx(id)
expect(spdx).to_not be_nil expect(spdx).to_not be_nil
expect(spdx[1]["name"].gsub(/ only$/,"")).to eql(license["title"]) expect(spdx[1]['name'].gsub(/ only$/, '')).to eql(license['title'])
end end
context "industry approval" do context 'industry approval' do
it "should be approved by OSI or FSF or OD" do it 'should be approved by OSI or FSF or OD' do
expect(approved_licenses).to include(id), "See https://git.io/vzCTV." expect(approved_licenses).to include(id), 'See https://git.io/vzCTV.'
end
end
context 'minimum permissions' do
let(:permissions) { license['permitted'] }
it 'should allow commercial use' do
expect(permissions).to include('commercial-use')
end
it 'should allow modification' do
expect(permissions).to include('modifications')
end
it 'should allow distribution' do
expect(permissions).to include('distribution')
end
it 'should allow private use' do
expect(permissions).to include('private-use')
end end
end end
end end

View File

@ -4,51 +4,60 @@ require 'json'
require 'open-uri' require 'open-uri'
require 'nokogiri' require 'nokogiri'
module SpecHelper
class << self
attr_accessor :config, :licenses, :site, :spdx
attr_accessor :osi_approved_licenses, :fsf_approved_licenses, :od_approved_licenses
end
end
def config_file def config_file
File.expand_path "./_config.yml", source File.expand_path './_config.yml', source
end end
def source def source
File.expand_path("../", File.dirname(__FILE__)) File.expand_path('../', File.dirname(__FILE__))
end end
def licenses_path def licenses_path
File.expand_path "_licenses", source File.expand_path '_licenses', source
end end
def config def config
config = Jekyll::Configuration.new.read_config_file config_file SpecHelper.config ||= begin
config = Jekyll::Utils.deep_merge_hashes(config, {:source => source}) config = Jekyll::Configuration.new.read_config_file config_file
Jekyll::Utils.deep_merge_hashes(Jekyll::Configuration::DEFAULTS, config) config = Jekyll::Utils.deep_merge_hashes(config, source: source)
Jekyll::Utils.deep_merge_hashes(Jekyll::Configuration::DEFAULTS, config)
end
end end
def licenses def licenses
$licenses ||= begin SpecHelper.licenses ||= begin
site.collections["licenses"].docs.map do |license| site.collections['licenses'].docs.map do |license|
id = File.basename(license.basename, ".txt") id = File.basename(license.basename, '.txt')
license.to_liquid.merge("id" => id) license.to_liquid.merge('id' => id)
end end
end end
end end
def hidden_licenses def hidden_licenses
licenses.select { |l| l["hidden"] } licenses.select { |l| l['hidden'] }
end end
def shown_licenses def shown_licenses
licenses.select { |l| !l["hidden"] } licenses.select { |l| !l['hidden'] }
end end
def license_ids def license_ids
licenses.map { |l| l["id"] } licenses.map { |l| l['id'] }
end end
def families def families
licenses.map { |l| l["family"] }.compact.uniq licenses.map { |l| l['family'] }.compact.uniq
end end
def site def site
$site ||= begin SpecHelper.site ||= begin
site = Jekyll::Site.new(config) site = Jekyll::Site.new(config)
site.reset site.reset
site.read site.read
@ -57,62 +66,62 @@ def site
end end
def rules def rules
site.data["rules"] site.data['rules']
end end
def fields def fields
site.data["fields"] site.data['fields']
end end
def meta def meta
site.data["meta"] site.data['meta']
end end
def rule?(tag, group) def rule?(tag, group)
rules[group].any? { |r| r["tag"] == tag } rules[group].any? { |r| r['tag'] == tag }
end end
def spdx_list def spdx_list
url = "https://raw.githubusercontent.com/sindresorhus/spdx-license-list/master/spdx.json" url = 'https://raw.githubusercontent.com/sindresorhus/spdx-license-list/master/spdx.json'
$spdx ||= JSON.parse(open(url).read) SpecHelper.spdx ||= JSON.parse(open(url).read)
end end
def spdx_ids def spdx_ids
spdx_list.map { |name, properties| name.downcase } spdx_list.map { |name, _properties| name.downcase }
end end
def find_spdx(license) def find_spdx(license)
spdx_list.find { |name, properties| name.downcase == license } spdx_list.find { |name, _properties| name.casecmp(license).zero? }
end end
def osi_approved_licenses def osi_approved_licenses
$osi_approved_licenses ||= begin SpecHelper.osi_approved_licenses ||= begin
licenses = {} licenses = {}
list = spdx_list.select { |id, meta| meta["osiApproved"] } list = spdx_list.select { |_id, meta| meta['osiApproved'] }
list.each do |id, meta| list.each do |id, meta|
licenses[id.downcase] = meta["name"] licenses[id.downcase] = meta['name']
end end
licenses licenses
end end
end end
def fsf_approved_licenses def fsf_approved_licenses
$fsf_approved_licenses ||= begin SpecHelper.fsf_approved_licenses ||= begin
url = "https://www.gnu.org/licenses/license-list.en.html" url = 'https://www.gnu.org/licenses/license-list.en.html'
doc = Nokogiri::HTML(open(url).read) doc = Nokogiri::HTML(open(url).read)
list = doc.css(".green dt") list = doc.css('.green dt')
licenses = {} licenses = {}
list.each do |license| list.each do |license|
a = license.css("a").find { |link| !link.text.nil? && !link.text.empty? && link.attr("id") } a = license.css('a').find { |link| !link.text.nil? && !link.text.empty? && link.attr('id') }
next if a.nil? next if a.nil?
id = a.attr("id").downcase id = a.attr('id').downcase
name = a.text.strip name = a.text.strip
licenses[id] = name licenses[id] = name
end end
# FSF approved the Clear BSD, but doesn't use its SPDX ID or Name # FSF approved the Clear BSD, but doesn't use its SPDX ID or Name
if licenses.keys.include? "clearbsd" if licenses.keys.include? 'clearbsd'
licenses["bsd-3-clause-clear"] = licenses["clearbsd"] licenses['bsd-3-clause-clear'] = licenses['clearbsd']
end end
licenses licenses
@ -120,13 +129,13 @@ def fsf_approved_licenses
end end
def od_approved_licenses def od_approved_licenses
$od_approved_licenses ||= begin SpecHelper.od_approved_licenses ||= begin
url = "http://licenses.opendefinition.org/licenses/groups/od.json" url = 'http://licenses.opendefinition.org/licenses/groups/od.json'
data = open(url).read data = open(url).read
data = JSON.parse(data) data = JSON.parse(data)
licenses = {} licenses = {}
data.each do |id, meta| data.each do |id, meta|
licenses[id.downcase] = meta["title"] licenses[id.downcase] = meta['title']
end end
licenses licenses
end end