Skip to content
Browse files

Merge remote-tracking branch 'origin/master'

  • Loading branch information...
2 parents 013d61a + d1b2bc8 commit 075231fc490b8a99dba57a8ce0781a6848019f93 @rmzelle rmzelle committed
Showing with 319 additions and 1 deletion.
  1. +2 −0 .rspec
  2. +10 −0 .travis.yml
  3. +6 −0 Gemfile
  4. +24 −0 Gemfile.lock
  5. +17 −0 Rakefile
  6. +1 −1 law1-de.csl
  7. +89 −0 spec/dependent_styles_spec.rb
  8. +84 −0 spec/independent_styles_spec.rb
  9. +19 −0 spec/repository_spec.rb
  10. +67 −0 spec/spec_helper.rb
View
2 .rspec
@@ -0,0 +1,2 @@
+--color
+--require spec_helper.rb
View
10 .travis.yml
@@ -0,0 +1,10 @@
+language: ruby
+rvm:
+ - 1.9.3
+notifications:
+ email:
+ recipients:
+ - rintze.zelle@gmail.com
+ - i@nukshuk.io
+ on_success: change
+ on_failure: always
View
6 Gemfile
@@ -0,0 +1,6 @@
+source :rubygems
+
+gem 'rake'
+gem 'rspec'
+gem 'nokogiri'
+gem 'csl', '1.0.0.pre5'
View
24 Gemfile.lock
@@ -0,0 +1,24 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ csl (1.0.0.pre5)
+ diff-lcs (1.1.3)
+ nokogiri (1.5.5)
+ rake (0.9.2.2)
+ rspec (2.11.0)
+ rspec-core (~> 2.11.0)
+ rspec-expectations (~> 2.11.0)
+ rspec-mocks (~> 2.11.0)
+ rspec-core (2.11.0)
+ rspec-expectations (2.11.1)
+ diff-lcs (~> 1.1.3)
+ rspec-mocks (2.11.0)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ csl (= 1.0.0.pre5)
+ nokogiri
+ rake
+ rspec
View
17 Rakefile
@@ -0,0 +1,17 @@
+
+require 'bundler'
+begin
+ Bundler.setup
+rescue Bundler::BundlerError => e
+ $stderr.puts e.message
+ $stderr.puts "Run `bundle install' to install missing gems"
+ exit e.status_code
+end
+
+require 'rspec/core'
+require 'rspec/core/rake_task'
+RSpec::Core::RakeTask.new(:spec) do |spec|
+ spec.rspec_opts = %w{ --require spec_helper.rb --format progress --color }
+end
+
+task :default => [:spec]
View
2 law1-de.csl
@@ -22,7 +22,7 @@
</contributor>
<summary>Law generic style, german variant, based on Chicago format with short notes and
full bibliography</summary>
- <category field="generic-base"/>
+ <category field="law"/>
<category citation-format="numeric"/>
<updated>2008-01-01T11:11:11+00:00</updated>
<rights>This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 License: http://creativecommons.org/licenses/by-sa/3.0/</rights>
View
89 spec/dependent_styles_spec.rb
@@ -0,0 +1,89 @@
+Dependents.each_pair do |id, (filename, path, style)|
+
+ describe "dependent style #{id}" do
+
+ it "is a valid CSL 1.0 style" do
+ CSL.validate(path).should == []
+ end
+
+ it "has a conventional file name" do
+ filename.should match(/^[a-z\d]+(-[a-z\d]+)*\.csl$/)
+ end
+
+ it "was successfully parsed" do
+ style.should be_a(CSL::Style)
+ end
+
+ unless style.nil?
+ it "is dependent" do
+ style.should be_dependent
+ end
+
+ it "has an info element" do
+ style.should have_info
+ end
+
+ it "does not have any rendering elements" do
+ style.should_not have_macro
+ style.should_not have_citation
+ style.should_not have_bibliography
+ end
+
+ it "the self-link (if present) is a valid style repository link" do
+ if style.has_self_link?
+ style.self_link.should == "http://www.zotero.org/styles/#{id}"
+ end
+ end
+
+ it "the self-link (if present) matches the style id" do
+ if style.has_self_link?
+ style.id.should == style.self_link
+ end
+ end
+
+ it "does not have a template-link" do
+ style.should_not have_template_link
+ end
+
+ it "has an id" do
+ style.should have_id
+ end
+
+ it "the id is a valid style repository link" do
+ style.id.should == "http://www.zotero.org/styles/#{id}"
+ end
+
+ it "has and info/rights element" do
+ style.info.should have_rights
+ end
+
+ it "is licensed under a CC BY-SA license" do
+ style.info.rights.to_s.strip.should ==
+ 'This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 License: http://creativecommons.org/licenses/by-sa/3.0/'
+ end
+
+ it "its independent-parent link points to an existing style" do
+ link = style.independent_parent_link
+
+ link.should match(%r{http://www.zotero.org/styles/([a-z-]+)})
+ Independents.should have_key(link[/[^\/]+$/])
+ end
+
+ it "has at least one info/category" do
+ style.info.should have_categories
+ end
+
+ it "has a citation-format" do
+ style.citation_format.should_not be_nil
+ end
+
+ it "has the same citation-format as its independent-parent" do
+ parent = style.independent_parent_link[/[^\/]+$/]
+ parent = Independents[parent][-1]
+
+ style.citation_format.should == parent.citation_format
+ end
+
+ end
+ end
+end
View
84 spec/independent_styles_spec.rb
@@ -0,0 +1,84 @@
+Independents.each_pair do |id, (filename, path, style)|
+
+ describe "independent style #{id}" do
+
+ it "is a valid CSL 1.0 style" do
+ CSL.validate(path).should == []
+ end
+
+ it "has a conventional file name" do
+ filename.should match(/^[a-z\d]+(-[a-z\d]+)*\.csl$/)
+ end
+
+ it "was successfully parsed" do
+ style.should be_a(CSL::Style)
+ end
+
+ unless style.nil?
+ it "is independent" do
+ style.should be_independent
+ end
+
+ it "has an info element" do
+ style.should have_info
+ end
+
+ it "has a self-link" do
+ style.should have_self_link
+ end
+
+ it "has an id" do
+ style.info.should have_id
+ end
+
+ it "the self-link is a valid style repository link" do
+ style.self_link.should == "http://www.zotero.org/styles/#{id}"
+ end
+
+ it "the self-link matches the style id" do
+ style.id.should == style.self_link
+ end
+
+ it "has and info/rights element" do
+ style.info.should have_rights
+ end
+
+ it "is licensed under a CC BY-SA license" do
+ style.info.rights.to_s.strip.should ==
+ 'This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 License: http://creativecommons.org/licenses/by-sa/3.0/'
+ end
+
+ it "its template-link (if present) points to an existing independent style" do
+ if style.has_template_link?
+ link = style.template_link
+
+ link.should match(%r{http://www.zotero.org/styles/([a-z-]+)})
+ Independents.should have_key(link[/[^\/]+$/])
+ end
+ end
+
+ unless %w{ all bibtex blank national-archives-of-australia }.include?(id)
+ it "has at least one info/category" do
+ style.info.should have_categories
+ end
+
+ it "has a citation-format" do
+ style.citation_format.should_not be_nil
+ end
+
+ it "its citation-format is valid" do
+ style.citation_format.to_s.should match(/^author(-date)?|numeric|label|note/)
+ end
+ end
+
+ it "defines all macros that are referenced by text or key nodes" do
+ style.descendants!.each do |node|
+ if node.matches?(/^key|text$/, :macro => /./)
+ style.macros.should have_key(node[:macro])
+ end
+ end
+ end
+ end
+
+ end
+end
View
19 spec/repository_spec.rb
@@ -0,0 +1,19 @@
+describe "The CSL Style Repository" do
+
+ it "contains independent styles" do
+ Independents.should_not be_empty
+ end
+
+ it "contains dependent styles" do
+ Dependents.should_not be_empty
+ end
+
+ it "does not contain any duplicate file names" do
+ (Independents.keys & Dependents.keys).should be_empty
+ end
+
+ it "contains no duplicate ISSNs" do
+ ISSN.select { |_, styles| styles.length > 1 }.should == {}
+ end
+
+end
View
67 spec/spec_helper.rb
@@ -0,0 +1,67 @@
+require 'csl'
+
+STYLE_ROOT = File.expand_path('../..', __FILE__)
+
+ISSN = Hash.new { |h,k| h[k] = [] }
+
+# These styles are ignored when checking for duplicate ISSNs
+ISSN_FILTER = %w{
+ science science-without-title molecular-psychiatry
+ molecular-psychiatry-letters frontiers-in-aging-neuroscience
+ frontiers-in-behavioral-neuroscience frontiers-in-evolutionary-neuroscience
+ frontiers-in-human-neuroscience frontiers-in-integrative-neuroscience
+ frontiers-in-molecular-neuroscience frontiers-in-neural-circuits
+ frontiers-in-neuroanatomy frontiers-in-neuroenergetics
+ frontiers-in-neuroengineering frontiers-in-neuroinformatics
+ frontiers-in-neurorobotics frontiers-in-synaptic-neuroscience
+ frontiers-in-systems-neuroscience frontiers-in-cellular-neuroscience
+ frontiers-in-computational-neuroscience
+}
+
+def load_style(path)
+ filename = File.basename(path)
+ id = filename[0..-5]
+
+ begin
+ style = CSL::Style.load(path)
+ rescue
+ # failed to parse the style. we'll report the error later
+ end
+
+ begin
+ unless ISSN_FILTER.include?(id)
+ if style.info.has_issn?
+ Array(style.info.issn).each do |issn|
+ ISSN[issn.to_s] << id
+ end
+ end
+
+ if style.info.has_eissn?
+ Array(style.info.eissn).each do |issn|
+ ISSN[issn.to_s] << id
+ end
+ end
+ end
+ rescue
+ warn "Failed to extract ISSN of style #{id}"
+ end
+
+ [id, [filename, path, style]]
+end
+
+
+print "\nLoading dependent styles"
+
+Dependents = Hash[Dir[File.join(STYLE_ROOT, 'dependent', '*.csl')].each_with_index.map { |path, i|
+ print '.' if i % 100 == 0
+ load_style(path)
+}]
+
+print "\nLoading independent styles"
+
+Independents = Hash[Dir[File.join(STYLE_ROOT, '*.csl')].each_with_index.map { |path, i|
+ print '.' if i % 100 == 0
+ load_style(path)
+}]
+
+puts

0 comments on commit 075231f

Please sign in to comment.
Something went wrong with that request. Please try again.