Class: BibSonomy::CSL
- Inherits:
-
Object
- Object
- BibSonomy::CSL
- Defined in:
- lib/bibsonomy/csl.rb
Instance Attribute Summary collapse
-
#bibsonomy_link ⇒ Object
publicly accessible attributes.
-
#bibtex_link ⇒ Object
publicly accessible attributes.
-
#css_class ⇒ Object
publicly accessible attributes.
-
#doi_link ⇒ Object
publicly accessible attributes.
-
#opt_sep ⇒ Object
publicly accessible attributes.
-
#pdf_dir ⇒ Object
publicly accessible attributes.
-
#public_doc_postfix ⇒ Object
publicly accessible attributes.
-
#style ⇒ Object
publicly accessible attributes.
-
#url_link ⇒ Object
publicly accessible attributes.
-
#year_headings ⇒ Object
publicly accessible attributes.
Instance Method Summary collapse
-
#initialize(user_name, api_key) ⇒ CSL
constructor
- Create a new BibSonomy instance Params:
user_name - BibSonomy user name
api_key -
API key of the given user (get at www.bibsonomy.org/settings?selTab=1).
- BibSonomy user name
- Create a new BibSonomy instance Params:
-
#render(user, tags, count) ⇒ Object
Download
countposts for the givenuserand tag(s) and render them with CSL.
Constructor Details
#initialize(user_name, api_key) ⇒ CSL
Create a new BibSonomy instance Params:
user_name-
BibSonomy user name
api_key-
API key of the given user (get at www.bibsonomy.org/settings?selTab=1)
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/bibsonomy/csl.rb', line 84 def initialize(user_name, api_key) super() @bibsonomy = BibSonomy::API.new(user_name, api_key, 'csl') # setting some defaults @style = 'apa.csl' @pdf_dir = nil @css_class = 'publications' @year_headings = true @public_doc_postfix = '_oa.pdf' # optional parts to be rendered (or not) @doi_link = true @url_link = true @bibtex_link = true @bibsonomy_link = true @opt_sep = ' | ' end |
Instance Attribute Details
#bibsonomy_link ⇒ Object
publicly accessible attributes
77 78 79 |
# File 'lib/bibsonomy/csl.rb', line 77 def bibsonomy_link @bibsonomy_link end |
#bibtex_link ⇒ Object
publicly accessible attributes
77 78 79 |
# File 'lib/bibsonomy/csl.rb', line 77 def bibtex_link @bibtex_link end |
#css_class ⇒ Object
publicly accessible attributes
77 78 79 |
# File 'lib/bibsonomy/csl.rb', line 77 def css_class @css_class end |
#doi_link ⇒ Object
publicly accessible attributes
77 78 79 |
# File 'lib/bibsonomy/csl.rb', line 77 def doi_link @doi_link end |
#opt_sep ⇒ Object
publicly accessible attributes
77 78 79 |
# File 'lib/bibsonomy/csl.rb', line 77 def opt_sep @opt_sep end |
#pdf_dir ⇒ Object
publicly accessible attributes
77 78 79 |
# File 'lib/bibsonomy/csl.rb', line 77 def pdf_dir @pdf_dir end |
#public_doc_postfix ⇒ Object
publicly accessible attributes
77 78 79 |
# File 'lib/bibsonomy/csl.rb', line 77 def public_doc_postfix @public_doc_postfix end |
#style ⇒ Object
publicly accessible attributes
77 78 79 |
# File 'lib/bibsonomy/csl.rb', line 77 def style @style end |
#url_link ⇒ Object
publicly accessible attributes
77 78 79 |
# File 'lib/bibsonomy/csl.rb', line 77 def url_link @url_link end |
#year_headings ⇒ Object
publicly accessible attributes
77 78 79 |
# File 'lib/bibsonomy/csl.rb', line 77 def year_headings @year_headings end |
Instance Method Details
#render(user, tags, count) ⇒ Object
Download count posts for the given user and tag(s) and render them with CSL. Params:
user-
user name
tags-
an array of tags
count-
number of posts to download
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/bibsonomy/csl.rb', line 108 def render(user, , count) # get posts from BibSonomy posts = JSON.parse(@bibsonomy.get_posts_for_user(user, 'publication', , 0, count)) # render them with citeproc cp = CiteProc::Processor.new style: @style, format: 'html' cp.import posts # to check for duplicate file names file_names = [] # sort posts by year sorted_keys = posts.keys.sort { |a,b| get_sort_posts(posts[b], posts[a]) } result = "" # print first heading last_year = 0 if @year_headings and sorted_keys.length > 0 last_year = get_year(posts[sorted_keys[0]]) result += "<h3>" + last_year + "</h3>" end result += "<ul class='#{@css_class}'>\n" for post_id in sorted_keys post = posts[post_id] # print heading if @year_headings year = get_year(post) if year != last_year last_year = year result += "</ul>\n<h3>" + last_year + "</h3>\n<ul class='#{@css_class}'>\n" end end # render metadata csl = cp.render(:bibliography, id: post_id) result += "<li class='" + post["type"] + "'>#{csl[0]}" # extract the post's id intra_hash, user_name = get_intra_hash(post_id) # optional parts = [] # attach documents if @pdf_dir for doc in get_public_docs(post["documents"]) # fileHash, fileName, md5hash, userName file_path = get_document(@bibsonomy, intra_hash, user_name, doc, @pdf_dir, file_names) << "<a href='#{file_path}'>PDF</a>" end end # attach DOI doi = post["DOI"] if @doi_link and doi != "" << "DOI:<a href='http://dx.doi.org/#{doi}'>#{doi}</a>" end # attach URL url = post["URL"] if @url_link and url != "" << "<a href='#{url}'>URL</a>" end # attach BibTeX if @bibtex_link << "<a href='http://www.bibsonomy.org/bib/publication/#{intra_hash}/#{user_name}'>BibTeX</a>" end # attach link to BibSonomy if @bibsonomy_link << "<a href='http://www.bibsonomy.org/publication/#{intra_hash}/#{user_name}'>BibSonomy</a>" end # attach options if .length > 0 result += " <span class='opt'>[" + .join(@opt_sep) + "]</span>" end result += "</li>\n" end result += "</ul>\n" return result end |