bibsonomy 0.4.8 → 0.4.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2dc63bd9e3b259ddf0c5808f4f7c2aaf70a86ae0
4
- data.tar.gz: 68b95dc7e2123f176cf04ee8df9bd959fa3d99e4
3
+ metadata.gz: a49f98d282f7af4fe43e57572ebed332a8edeeb0
4
+ data.tar.gz: b67833cb0964c9c5059b157d9aee5658935ee013
5
5
  SHA512:
6
- metadata.gz: 9946d9fb4ab157a8d5b2509b86cbb67ad46cc5458793a08878368b41d46c24f37b499a15fdc7d00853938e194431f348dce9527d39c152c3e3a42428f83dc9a5
7
- data.tar.gz: 1d9e13932a6e3e4d85f91a95b58d9487f89a824760f78888593a925e5c93881190c47e944bca32e60b0ffb155751e5d4de735af784039f5139d61f48129d764f
6
+ metadata.gz: ed3024658f649b2566b79ed6588fb89a986fb6daffaeec750c32e3c9520e50d05c24850ee993db04abfdccbff02fb029bf2bab57864a26c7389d9383767ed0b3
7
+ data.tar.gz: 5756909805eff1c0286018cf8745233db2909c55bc0451e12d9a097caf0866e7d04676badaaeec5deda258837e70cce509dc7def0c62d9feb50ad7bf41bd974b
data/README.md CHANGED
@@ -72,76 +72,12 @@ bundle exec rake test
72
72
 
73
73
  ## Jekyll
74
74
 
75
- A [Jekyll](http://jekyllrb.com/) plugin:
76
-
77
- ```ruby
78
- # coding: utf-8
79
- require 'time'
80
- require 'bibsonomy/csl'
81
-
82
- module Jekyll
83
-
84
- class BibSonomyPostList < Liquid::Tag
85
- def initialize(tag_name, text, tokens)
86
- super
87
- parts = text.split(/\s+/)
88
- @user = parts[0]
89
- @tag = parts[1]
90
- @count = Integer(parts[2])
91
- end
92
-
93
- def render(context)
94
- site = context.registers[:site]
95
-
96
- # user name and API key for BibSonomy
97
- user_name = site.config['bibsonomy_user']
98
- api_key = site.config['bibsonomy_apikey']
99
- csl = BibSonomy::CSL.new(user_name, api_key)
100
-
101
- # target directory for PDF documents
102
- pdf_dir = site.config['bibsonomy_document_directory']
103
- csl.pdf_dir = pdf_dir
104
-
105
- # CSL style for rendering
106
- style = site.config['bibsonomy_style']
107
- csl.style = style
108
-
109
- html = csl.render(@user, [@tag], @count)
110
-
111
- # set date to now
112
- context.registers[:page]["date"] = Time.new
113
-
114
- return html
115
- end
116
- end
117
-
118
- end
119
-
120
- Liquid::Template.register_tag('bibsonomy', Jekyll::BibSonomyPostList)
121
- ```
122
-
123
- The plugin can be used inside Markdown files as follows:
124
-
125
- ```Liquid
126
- {% bibsonomy jaeschke myown 100 %}
127
- ```
128
-
129
- Add the following options to your `_config.yml`:
130
-
131
- ```YAML
132
- bibsonomy_user: yourusername
133
- bibsonomy_apikey: yourapikey
134
- bibsonomy_document_directory: pdf
135
- # other: apa, acm-siggraph
136
- bibsonomy_style: springer-lecture-notes-in-computer-science
137
- ```
138
-
139
- For an example how to use the Jekyll plugin, have a look at
140
- [the demo project](https://github.com/rjoberon/bibsonomy-jekyll-demo)
141
- and for an example showing the output, have a look at
75
+ This gem is used by the
76
+ [BibSonomy plugin](https://github.com/rjoberon/bibsonomy-jekyll) for
77
+ [Jekyll](http://jekyllrb.com/) to render post lists in Jekyll web
78
+ sites. For an example output, have a look at
142
79
  [my publication list](http://www.kbs.uni-hannover.de/~jaeschke/publications.html).
143
80
 
144
-
145
81
  ## Contributing
146
82
 
147
83
  1. Fork it ( https://github.com/rjoberon/bibsonomy-ruby/fork )
@@ -21,12 +21,14 @@ require 'bibsonomy'
21
21
  # - group
22
22
  #
23
23
  # Changes:
24
- # 2017-05-31
24
+ # 2017-06-06 (rja)
25
+ # - added support for DOIs which are actually URLs (i.e., include the resolver)
26
+ # 2017-05-31 (rja)
25
27
  # - added support to get posts of a group
26
- # 2017-01-19
28
+ # 2017-01-19 (rja)
27
29
  # - added optional parameter group to control which posts are
28
30
  # included based on their viewability for a specific group (not yet activated!)
29
- # 2015-02-24
31
+ # 2015-02-24 (rja)
30
32
  # - initial version
31
33
  #
32
34
  # @todo escape data
@@ -41,7 +43,7 @@ require 'bibsonomy'
41
43
 
42
44
  module BibSonomy
43
45
  class CSL
44
-
46
+
45
47
  # @return [String] the output directory for downloaded PDF files. If set to `nil`, no documents are downloaded. (default: `nil`)
46
48
  attr_accessor :pdf_dir
47
49
 
@@ -59,7 +61,7 @@ module BibSonomy
59
61
 
60
62
  # @return [Boolean] whether URLs of posts shall be rendered. (default: `true`)
61
63
  attr_accessor :url_link
62
-
64
+
63
65
  # @return [Boolean] whether links to the BibTeX data of a post (in BibSonomy) shall be rendered. (default: `true`)
64
66
  attr_accessor :bibtex_link
65
67
 
@@ -77,12 +79,12 @@ module BibSonomy
77
79
 
78
80
  # @return [String] which posts shall be included, based on the groups they are viewable for
79
81
  attr_accessor :group
80
-
82
+
81
83
  #
82
84
  # Create a new BibSonomy instance.
83
85
  #
84
86
  # @param user_name [String] the BibSonomy user name
85
- # @param api_key [String] the API key of the user (get at http://www.bibsonomy.org/settings?selTab=1)
87
+ # @param api_key [String] the API key of the user (get at https://www.bibsonomy.org/settings?selTab=1)
86
88
  def initialize(user_name, api_key)
87
89
  super()
88
90
  @bibsonomy = BibSonomy::API.new(user_name, api_key, 'csl')
@@ -178,7 +180,8 @@ module BibSonomy
178
180
  # attach DOI
179
181
  doi = post["DOI"]
180
182
  if @doi_link and doi != ""
181
- options << "DOI:<a href='http://dx.doi.org/#{doi}'>#{doi}</a>"
183
+ doi, doi_url = get_doi(doi)
184
+ options << "DOI:<a href='#{doi_url}'>#{doi}</a>"
182
185
  end
183
186
  # attach URL
184
187
  url = post["URL"]
@@ -187,11 +190,11 @@ module BibSonomy
187
190
  end
188
191
  # attach BibTeX
189
192
  if @bibtex_link
190
- options << "<a href='http://www.bibsonomy.org/bib/publication/#{intra_hash}/#{user_name}'>BibTeX</a>"
193
+ options << "<a href='https://www.bibsonomy.org/bib/publication/#{intra_hash}/#{user_name}'>BibTeX</a>"
191
194
  end
192
195
  # attach link to BibSonomy
193
196
  if @bibsonomy_link
194
- options << "<a href='http://www.bibsonomy.org/publication/#{intra_hash}/#{user_name}'>BibSonomy</a>"
197
+ options << "<a href='https://www.bibsonomy.org/publication/#{intra_hash}/#{user_name}'>BibSonomy</a>"
195
198
  end
196
199
 
197
200
  # attach options
@@ -211,7 +214,22 @@ module BibSonomy
211
214
  # private methods follow
212
215
  #
213
216
  private
214
-
217
+
218
+ # given a DOI (or a URL with a DOI) return DOI and resolvable URL
219
+ def get_doi(doi)
220
+ # simplistic check whether DOI is a URL
221
+ if doi.start_with?("http")
222
+ # extract DOI, regex from https://www.crossref.org/blog/dois-and-matching-regular-expressions/
223
+ if doi =~ /(10.\d{4,9}\/[-._;()\/:A-Z0-9]+)/i
224
+ return $1, doi
225
+ else
226
+ return doi, doi
227
+ end
228
+ else
229
+ return doi, "https://dx.doi.org/#{doi}"
230
+ end
231
+ end
232
+
215
233
  def get_year(post)
216
234
  issued = post["issued"]
217
235
  # if the post contains only a "year" field, it is contained in
@@ -369,7 +387,7 @@ module BibSonomy
369
387
 
370
388
  # set defaults for optional arguments
371
389
  options[:user] = options[:user_name] unless options[:user]
372
-
390
+
373
391
  #
374
392
  # do the actual work
375
393
  #
@@ -1,3 +1,3 @@
1
1
  module BibSonomy
2
- VERSION = "0.4.8"
2
+ VERSION = "0.4.9"
3
3
  end
@@ -5,17 +5,31 @@ class BibSonomyCSLTest < Minitest::Test
5
5
  def setup
6
6
  @csl = BibSonomy::CSL.new(ENV['BIBSONOMY_USER_NAME'], ENV['BIBSONOMY_API_KEY'])
7
7
  end
8
-
8
+
9
9
  def test_exists
10
10
  assert BibSonomy::CSL
11
11
  end
12
-
12
+
13
13
  def test_render
14
14
  VCR.use_cassette('render') do
15
- html = @csl.render("user", "bibsonomy-ruby", [], 10)
15
+ html = @csl.render("user", "bibsonomy-ruby", ["doiok"], 10)
16
16
 
17
17
  assert_equal "<h3>2010</h3>", html[0..12]
18
18
  assert_equal "</ul>", html[-6..-2]
19
19
  end
20
20
  end
21
+
22
+ def test_render_doi
23
+ VCR.use_cassette('render') do
24
+ html = @csl.render("user", "bibsonomy-ruby", ["doiok"], 10)
25
+ # DOI is correct
26
+ assert_equal "DOI:<a href='https://dx.doi.org/10.1007/s00778-010-0208-4'>10.1007/s00778-010-0208-4</a>", html[338,88]
27
+
28
+ # DOI is a URL
29
+ html = @csl.render("user", "bibsonomy-ruby", ["brokendoi", "test"], 10)
30
+ # thus we have http not https!
31
+ assert_equal "DOI:<a href='http://dx.doi.org/10.1145/2786451.2786927'>10.1145/2786451.2786927</a>", html[373,83]
32
+ end
33
+ end
34
+
21
35
  end
@@ -29,7 +29,7 @@ class BibSonomyPostTest < Minitest::Test
29
29
  result = @api.get_posts_for_user("bibsonomy-ruby", "publication", ["test"], 0, 20)
30
30
 
31
31
  # Make sure we got all the posts
32
- assert_equal 1, result.length
32
+ assert_equal 2, result.length
33
33
 
34
34
  # Make sure that the JSON was parsed
35
35
  assert result.kind_of?(Array)
@@ -55,7 +55,7 @@ class BibSonomyPostTest < Minitest::Test
55
55
  result = @api.get_posts("user", "bibsonomy-ruby", "publication", ["test"], 0, 10)
56
56
 
57
57
  # Make sure we got all the posts
58
- assert_equal 1, result.length
58
+ assert_equal 2, result.length
59
59
 
60
60
  # Make sure that the JSON was parsed
61
61
  assert result.kind_of?(Array)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bibsonomy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.8
4
+ version: 0.4.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Jäschke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-31 00:00:00.000000000 Z
11
+ date: 2017-06-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler