Revision 406:40144aa9dfe7 vendor/plugins

View differences:

vendor/plugins/redmine_bibliography/app/controllers/authors_controller.rb
2 2
  
3 3
  def index
4 4
    @authors = Author.find(:all)
5
  end
5 6

  
6
  end
7 7
end
vendor/plugins/redmine_bibliography/app/controllers/bibtex_entries_controller.rb
1 1
class BibtexEntriesController < ApplicationController
2 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 3
end
vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb
60 60
    @authors = @publication.authors
61 61
  end
62 62

  
63

  
64

  
65

  
66

  
67
  
68
  
69
  
70
  
71
  
72
  
73
  
74
  # parse string with bibtex authors
75
  def parse_authors(authors_entry)
76
    # in bibtex the authors are always seperated by "and"
77
    authors = authors_entry.split(" and ")
78
    
79
    # need to save all authors
80
    
81
    
82
    return authors
83
  end
84

  
85
  # parses the bibtex file
86
  def parse_bibtex_file
87

  
88
  end
89

  
90
  # parses a list of bibtex 
91
  def parse_bibtex_list(bibtex_list)
92
    bibliography = BibTeX.parse bibtex_list
93

  
94
    no_entries = bibliography.data.length
95

  
96
    puts "Gonna parse " + no_entries.to_s + " Bibtex entries"
97

  
98
    # parses the bibtex entries
99
    bibliography.data.map do |d|
100
      create_bibtex_entry d
101
    end
102

  
103
    @publication.bibtex_entry = @bentry
104

  
105
    if @publication.save
106
      puts "SAVED"
107
    else
108
      puts "NOT SAVED"
109
    end
110

  
111
    Rails.logger.error @publication.bibtex_entry
112
  end 
113

  
114

  
115

  
116
  def create_bibtex_entry(d)
117

  
118
    if d.class == BibTeX::Entry
119
      # creates a new BibTex instance
120
      @bentry = BibtexEntry.new
121

  
122
      d.fields.keys.map do |field|
123
        
124
        case field.to_s
125
        when "author"
126
          authors = parse_authors d[field]
127
          puts "Number of authors: " + authors.length.to_s
128
        when "title"
129
          puts "The title " + d[field]
130
          @publication.title = d[field]
131
        when "The institution"
132
          puts "institution " + d[field]
133
        when "email"
134
          puts "The email " + d[field]
135
        else
136
          @bentry[field] = d[field]
137
          puts field.to_s + " " + d[field]
138
        end
139
      end
140

  
141
      @bentry.save!
142
    end 
143
  end
144

  
145

  
146

  
147

  
148

  
63 149
end
vendor/plugins/redmine_bibliography/db/migrate/001_create_authors.rb
2 2
  def self.up
3 3
    create_table :authors do |t|
4 4
      t.column :user_id, :integer
5
      t.column :name, :string
5 6
    end
6 7
  end
7 8

  

Also available in: Unified diff