Class: JSC::JSCRef

Inherits:
Liquid::Tag
  • Object
show all
Includes:
Plugin
Defined in:
lib/JSCRef.rb

Instance Attribute Summary

Attributes included from Plugin

#ctx, #site

Instance Method Summary collapse

Methods included from Plugin

#config, #math_jax, #mj_config, #mj_local, #mj_local?, #mj_url, #set_ctx

Constructor Details

#initialize(tag_name, markup, tokens) ⇒ JSCRef

Returns a new instance of JSCRef.



9
10
11
12
13
# File 'lib/JSCRef.rb', line 9

def initialize(tag_name, markup, tokens)
  super
  @key    = markup
  @config = Hash.new
end

Instance Method Details

#render(ctx) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/JSCRef.rb', line 15

def render(ctx)
  set_ctx ctx
  ctx['jsc']          ||= {}
  ctx['jsc']['cited'] ||= []
  refs                = ctx['jsc']['cited'].uniq.map { |key|
    entries.detect { |e| e.key == key.to_s.strip }
  }
  bibliography        = refs.each_with_index.map { |entry, index|
    if entry == nil
       :li, missing_ref(ctx['jsc']['cited'][index])
    else
      citation = CiteProc.process entry.to_citeproc,
                                  :style  => config['bibtex']['style'],
                                  :locale => config['bibtex']['locale'],
                                  :format => config['bibtex']['format']

      reference = config['bibtex']['bib_template'] % {
          :reference => citation,
          :key       => entry.key,
          :type      => entry.type,
          :index     => index+1
      }

      #link_to "##{[prefix, key].compact.join('-')}", citation.join
       :li, reference
    end
  }.join("\n")
   :ol, bibliography
end