bibsonomy-jekyll 0.2.3 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6189658aacd6fe9a752e12500841ac771c474fb08a8bc9b9833e1a2f595ab8f9
4
- data.tar.gz: 6410ac4082b59666035be76c81bc48dda4c591f25027b1e08c19d688f9e40d05
3
+ metadata.gz: c16c346ada2205c7469504045fac7583451abc04ede1c81369f4cdffb3bfbee4
4
+ data.tar.gz: 4486fee8623cd3704de3be97191b84aa4426e878b68490e6e71136112d1f947b
5
5
  SHA512:
6
- metadata.gz: 58fbe90a4d60d0110a74402f42338d8c4060976371510b562939baa8e264f1c64541d6e98e06497df6a597a89600a8e38e8a1e5bbee38cfaf4ecf0c22dbe329d
7
- data.tar.gz: 8e02ebd778233507fcbcacf5984cdc861929d72d070d9c66963c01c3497cfbbae8e67869f94b185e38f999a73dd83719b361d86ecf5e571390ffe7eedb4eab6a
6
+ metadata.gz: 21af83d7118c5957405e31d44b7c777a36993e233ae60690567645ff884a3c0bb54cddcf25379e4a32fc4ee62e79ba29ee8385c254e748ced15c81a82de7ab88
7
+ data.tar.gz: 6d33eede88e0357be5c27398c91a3fb6678bbd9cc8268199daea10d1c878202abc3f55000e21d715b8631b780dcb06338f718c4205ec765be65dca69784fcfbd
@@ -7,7 +7,7 @@ require 'bibsonomy/csl'
7
7
  #
8
8
  # Jekyll Tag to render posts from BibSonomy.
9
9
  #
10
- # Usage: {% bibsonomy GROUPING NAME TAG1 TAG2 ... TAGN COUNT %}
10
+ # Usage: {% bibsonomy [:OPTKEY OPTVAL] GROUPING NAME TAG1 TAG2 ... TAGN COUNT %}
11
11
  # where
12
12
  # GROUPING is either "user" or "group" and specifies the type of NAME
13
13
  # NAME is the name of the group or user
@@ -15,6 +15,8 @@ require 'bibsonomy/csl'
15
15
  # COUNT is an integer, the number of posts to return
16
16
  #
17
17
  # Changes:
18
+ # 2026-06-02 (rja)
19
+ # - added generic setting (and override) of csl configuration options
18
20
  # 2018-10-08 (rja)
19
21
  # - added liquid expansion
20
22
  # 2017-05-31 (rja)
@@ -24,23 +26,23 @@ require 'bibsonomy/csl'
24
26
  module Jekyll
25
27
 
26
28
  class BibSonomyPostList < Liquid::Tag
29
+
30
+ # these bibsonomy/csl configuration options are supported
31
+ CONFIG_OPTS = ['pdf_dir', 'altmetric_badge_type', 'style', 'year_headings', 'css_class']
32
+
27
33
  def initialize(tag_name, text, tokens)
28
34
  super
29
35
  @input = text
30
36
  end
31
37
 
38
+
32
39
  def render(context)
33
- # expand liquid variables
34
40
  rendered_input = Liquid::Template.parse(@input).render(context)
35
-
36
- bib_config = context.registers[:site].config['bibsonomy'].clone
37
- #bib_config = site.config['bibsonomy']
38
-
39
- # parse parameters
40
41
  parts = rendered_input.split(/\s+/)
41
- # parameters starting with : can override configuration options
42
- override_config(bib_config, parts)
43
42
 
43
+ # parameters starting with : can override csl configuration options
44
+ opts = get_opts(parts)
45
+ # use (remaining/actual) parameters
44
46
  grouping = parts.shift
45
47
  name = parts.shift
46
48
  # the last element is the number of posts
@@ -48,21 +50,10 @@ module Jekyll
48
50
  # everything else are the tags
49
51
  tags = parts
50
52
 
51
- # extract config
52
- site = context.registers[:site]
53
-
54
- # user name and API key for BibSonomy
55
- csl = BibSonomy::CSL.new(bib_config['user'], bib_config['apikey'])
56
-
57
- # target directory for PDF documents
58
- csl.pdf_dir = bib_config['document_directory']
59
-
60
- # Altmetric badge type
61
- csl.altmetric_badge_type = bib_config['altmetric_badge_type']
62
-
63
- # CSL style for rendering
64
- csl.style = bib_config['style']
65
- csl.year_headings = bib_config['year_headings'].to_s.downcase == "true"
53
+ # configure CSL
54
+ config = context.registers[:site].config['bibsonomy']
55
+ csl = BibSonomy::CSL.new(config['user'], config['apikey'])
56
+ configure(csl, config, opts)
66
57
 
67
58
  html = csl.render(grouping, name, tags, count)
68
59
 
@@ -72,12 +63,35 @@ module Jekyll
72
63
  return html
73
64
  end
74
65
 
75
- def override_config(config, parts)
66
+
67
+ def get_opts(parts)
68
+ opts = {}
76
69
  # parameters starting with : can override configuration options
77
70
  # only at the beginning → the first string without : stops loop
78
71
  while parts[0].start_with?(':')
79
- config[parts.shift[1..]] = parts.shift
72
+ opts[parts.shift[1..]] = parts.shift
80
73
  end
74
+ return opts
75
+ end
76
+
77
+
78
+ #
79
+ # set values in csl from config, possibly overriden by opts
80
+ #
81
+ def configure(csl, config, opts)
82
+ # work on a copy of the configuration and override using opts
83
+ config = config.clone.merge(opts)
84
+ # set values from config in CSL
85
+ (CONFIG_OPTS & config.keys()).each do |key, value|
86
+ # TODO: access attribute by string → ok or hack?
87
+ csl.instance_variable_set('@' + key, value)
88
+ end
89
+
90
+ # HACK: convert the only (so far) boolean variable to boolean
91
+ if csl.year_headings.is_a?(String)
92
+ csl.year_headings = csl.year_headings.downcase == "true"
93
+ end
94
+
81
95
  end
82
96
  end
83
97
 
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module BibSonomyJekyll
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bibsonomy-jekyll
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Jäschke