Class: Jekyll::Scholar::BibliographyTag

Inherits:
Liquid::Tag
  • Object
show all
Includes:
Utilities
Defined in:
lib/jekyll/scholar/tags/bibliography.rb

Instance Attribute Summary

Attributes included from Utilities

#config, #context, #max, #offset, #prefix, #site, #text

Instance Method Summary collapse

Methods included from Utilities

#base_url, #bibliography, #bibliography_tag, #bibliography_template, #bibtex_file, #bibtex_files, #bibtex_filters, #bibtex_options, #bibtex_path, #bibtex_paths, #citation_item_for, #citation_number, #cite, #cite_details, #cited_keys, #cited_only?, #cited_references, #content_tag, #details_file_for, #details_link_for, #details_path, #entries, #extend_path, #generate_details?, #group, #group?, #group_by, #group_compare, #group_keys, #group_name, #group_order, #group_order=, #group_tags, #group_value, #grouper, #interpolate, #join_strings?, #keys, #labels, #limit_entries?, #link_target_for, #link_to, #liquid_template, #liquidify, #load_repository, #locators, #missing_reference, #month_names, #optparse, #query, #raw_bibtex?, #reference_data, #reference_tag, #reference_tagname, #relative, #render_bibliography, #render_citation, #renderer, #replace_strings?, #repository, #repository?, #repository_link_for, #repository_links_for, #repository_path, #scholar_source, #set_context_to, #skip_sort?, #sort, #sort_keys, #sort_order, #split_arguments, #style, #suppress_author?, #type_aliases, #type_names, #type_order

Constructor Details

#initialize(tag_name, arguments, tokens) ⇒ BibliographyTag

Returns a new instance of BibliographyTag.



7
8
9
10
11
12
13
# File 'lib/jekyll/scholar/tags/bibliography.rb', line 7

def initialize(tag_name, arguments, tokens)
  super

  @config = Scholar.defaults.dup

  optparse(arguments)
end

Instance Method Details

#group_renderer(groupsOrItems, keys, order, tags) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/jekyll/scholar/tags/bibliography.rb', line 57

def group_renderer(groupsOrItems,keys,order,tags)
  if keys.count == 0
    renderer(force = true)
    render_items(groupsOrItems)
  else
    groupsOrItems
      .sort do |e1,e2|
        if (order.first || group_order.last) =~ /^(desc|reverse)/i
          group_compare(keys.first,e2[0],e1[0])
        else
          group_compare(keys.first,e1[0],e2[0])
        end
      end
      .map do |e|
        bibhead = (tags.first || group_tags.last,
                              group_name(keys.first, e[0]),
                              :class => config['bibliography_class'])
        bibentries = group_renderer(e[1], keys.drop(1), order.drop(1), tags.drop(1))
        bibhead + "\n" + bibentries
      end
      .join("\n")
  end
end

#render(context) ⇒ 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
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/jekyll/scholar/tags/bibliography.rb', line 15

def render(context)
  set_context_to context

  # Add bibtex files to dependency tree
  if context.registers[:page] and context.registers[:page].has_key? "path"
    bibtex_paths.each do |bibtex_path|
      site.regenerator.add_dependency(
        site.in_source_dir(context.registers[:page]["path"]),
        bibtex_path
      )
    end
  end

  items = entries

  if cited_only?
    items = if skip_sort?
      cited_references.uniq.map do |key|
        items.detect { |e| e.key == key }
      end
    else
      entries.select do |e|
        cited_references.include? e.key
      end
    end

    # See #90
    cited_keys.clear
  end

  if group?
    groups = group(items)
    bibliography = render_groups(groups)
  else
    items = items[offset..max] if limit_entries?
    bibliography = render_items(items)
  end

  bibliography
end

#render_groups(groups) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/jekyll/scholar/tags/bibliography.rb', line 56

def render_groups(groups)
  def group_renderer(groupsOrItems,keys,order,tags)
    if keys.count == 0
      renderer(force = true)
      render_items(groupsOrItems)
    else
      groupsOrItems
        .sort do |e1,e2|
          if (order.first || group_order.last) =~ /^(desc|reverse)/i
            group_compare(keys.first,e2[0],e1[0])
          else
            group_compare(keys.first,e1[0],e2[0])
          end
        end
        .map do |e|
          bibhead = (tags.first || group_tags.last,
                                group_name(keys.first, e[0]),
                                :class => config['bibliography_class'])
          bibentries = group_renderer(e[1], keys.drop(1), order.drop(1), tags.drop(1))
          bibhead + "\n" + bibentries
        end
        .join("\n")
    end
  end
  group_renderer(groups,group_keys,group_order,group_tags)
end

#render_items(items) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/jekyll/scholar/tags/bibliography.rb', line 83

def render_items(items)
  bibliography = items.each_with_index.map { |entry, index|
    reference = bibliography_tag(entry, index + 1)

    if generate_details?
      reference << link_to(details_link_for(entry),
        config['details_link'], :class => config['details_link_class'])
    end

     config['bibliography_item_tag'], reference, config['bibliography_item_attributes']
  }.join("\n")

   config['bibliography_list_tag'], bibliography,
    { :class => config['bibliography_class'] }.merge(config['bibliography_list_attributes'])

end