Class: Jekyll::BibSonomyPostList
- Inherits:
-
Liquid::Tag
- Object
- Liquid::Tag
- Jekyll::BibSonomyPostList
- Defined in:
- lib/bibsonomy-jekyll.rb
Constant Summary collapse
- CONFIG_OPTS =
these bibsonomy/csl configuration options are supported
['pdf_dir', 'altmetric_badge_type', 'style', 'year_headings', 'css_class']
Instance Method Summary collapse
-
#configure(csl, config, opts) ⇒ Object
set values in csl from config, possibly overriden by opts.
- #get_opts(parts) ⇒ Object
-
#initialize(tag_name, text, tokens) ⇒ BibSonomyPostList
constructor
A new instance of BibSonomyPostList.
- #render(context) ⇒ Object
Constructor Details
#initialize(tag_name, text, tokens) ⇒ BibSonomyPostList
Returns a new instance of BibSonomyPostList.
33 34 35 36 |
# File 'lib/bibsonomy-jekyll.rb', line 33 def initialize(tag_name, text, tokens) super @input = text end |
Instance Method Details
#configure(csl, config, opts) ⇒ Object
set values in csl from config, possibly overriden by opts
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/bibsonomy-jekyll.rb', line 81 def configure(csl, config, opts) # work on a copy of the configuration and override using opts config = config.clone.merge(opts) # set values from config in CSL (CONFIG_OPTS & config.keys()).each do |key| # TODO: access attribute by string → ok or hack? csl.instance_variable_set('@' + key, config[key]) end # HACK: convert the only (so far) boolean variable to boolean if csl.year_headings.is_a?(String) csl.year_headings = csl.year_headings.downcase == "true" end end |
#get_opts(parts) ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'lib/bibsonomy-jekyll.rb', line 67 def get_opts(parts) opts = {} # parameters starting with : can override configuration options # only at the beginning → the first string without : stops loop while parts[0].start_with?(':') opts[parts.shift[1..]] = parts.shift end return opts end |
#render(context) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/bibsonomy-jekyll.rb', line 39 def render(context) rendered_input = Liquid::Template.parse(@input).render(context) parts = rendered_input.split(/\s+/) # parameters starting with : can override csl configuration options opts = get_opts(parts) # use (remaining/actual) parameters grouping = parts.shift name = parts.shift # the last element is the number of posts count = Integer(parts.pop) # everything else are the tags = parts # configure CSL config = context.registers[:site].config['bibsonomy'] csl = BibSonomy::CSL.new(config['user'], config['apikey']) configure(csl, config, opts) html = csl.render(grouping, name, , count) # set date to now context.registers[:page]["date"] = Time.new return html end |