To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / vendor / plugins / redmine_bibliography / app / controllers / bibtex_entries_controller.rb @ 405:8a105a53b8f4

History | View | Annotate | Download (1000 Bytes)

1 405:8a105a53b8f4 luis
class BibtexEntriesController < ApplicationController
2
3
  # parse string with bibtex authors
4
  # return an ordered array
5
  def parse_authors
6
7
  end
8
9
  # parses the bibtex file
10
  def parse_bibtex_file
11
12
  end
13
14
  def parse_bibtex_list(bibtex_list)
15
    bibliography = BibTeX.parse bibtex_list
16
17
    no_entries =  bibliography.data.length
18
19
    logger.error "Gonna parse " no_entries.to_s " Bibtex entries"
20
21
    # parses the bibtex entries
22
    bibliography.data.map do |d|
23
      create_bibtex_entry d
24
    end
25
26
    @publication.bibtex_entry = @bentry
27
28
    if @publication.save
29
      logger.error "SAVED"
30
    else
31
      logger.error "NOT SAVED"
32
    end
33
34
    logger.error @publication.bibtex_entry
35
  end
36
37
38
39
  def create_bibtex_entry(d)
40
    result = ''
41
    if d.class == BibTeX::Entry
42
      @bentry = BibtexEntry.new
43
44
      d.fields.keys.map do |k|
45
        if k == "title"
46
          @publication.title = d[k]
47
        else
48
          @bentry[k] = d[k]
49
        end
50
      end
51
      @bentry.save!
52
    end
53
  end
54
55
end