Revision 393:9595ab4cac6b vendor
| vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb | ||
|---|---|---|
| 5 | 5 |
# parse string with bibtex authors |
| 6 | 6 |
# return an ordered array |
| 7 | 7 |
def parse_authors |
| 8 |
|
|
| 8 |
|
|
| 9 | 9 |
end |
| 10 | 10 |
|
| 11 | 11 |
def parse_bibtex_file |
| 12 |
|
|
| 12 |
|
|
| 13 | 13 |
end |
| 14 | 14 |
|
| 15 | 15 |
def parse_bibtex_text |
| ... | ... | |
| 17 | 17 |
|
| 18 | 18 |
if bibtex_entry |
| 19 | 19 |
bib = BibTeX.parse bibtex_entry |
| 20 |
|
|
| 20 |
|
|
| 21 | 21 |
# parses the bibtex entries |
| 22 | 22 |
bib.data.map do |d| |
| 23 | 23 |
result = '' |
| 24 | 24 |
if d.class == BibTeX::Entry |
| 25 |
@bentry = BibtexEntry.new |
|
| 25 | 26 |
# d.replace!(bib.strings) |
| 26 |
|
|
| 27 |
result = [author, '. ', d.title].join |
|
| 28 |
end |
|
| 27 |
|
|
| 28 |
d.fields.keys.map do |k| |
|
| 29 |
@bentry[k] = d[k] |
|
| 30 |
end |
|
| 31 |
end |
|
| 29 | 32 |
end |
| 30 | 33 |
|
| 31 |
end |
|
| 32 |
end |
|
| 34 |
@publication.bibtex_entry = @bentry |
|
| 35 |
|
|
| 36 |
logger.error @publication.bibtex_entry |
|
| 37 |
|
|
| 38 |
end |
|
| 39 |
end |
|
| 33 | 40 |
|
| 34 | 41 |
def new |
| 35 | 42 |
@publication = Publication.new |
| 36 | 43 |
@publication.current_step = session[:publication_step] |
| 37 |
|
|
| 44 |
|
|
| 38 | 45 |
end |
| 39 | 46 |
|
| 40 | 47 |
def create |
| ... | ... | |
| 43 | 50 |
|
| 44 | 51 |
parse_bibtex_text |
| 45 | 52 |
|
| 53 |
if @publication.save |
|
| 54 |
logger.error "SAVED" |
|
| 55 |
else |
|
| 56 |
logger.error "NOT SAVED" |
|
| 57 |
end |
|
| 58 |
|
|
| 46 | 59 |
if params[:back_button] |
| 47 | 60 |
@publication.previous_step |
| 48 | 61 |
else |
| 49 | 62 |
@publication.next_step |
| 50 | 63 |
end |
| 51 |
|
|
| 64 |
|
|
| 52 | 65 |
session[:publication_step] = @publication.current_step |
| 53 |
|
|
| 66 |
|
|
| 54 | 67 |
render "new" |
| 55 | 68 |
end |
| 56 | 69 |
|
| ... | ... | |
| 75 | 88 |
@authors = @publication.authors |
| 76 | 89 |
end |
| 77 | 90 |
|
| 78 |
|
|
| 79 | 91 |
end |
| vendor/plugins/redmine_bibliography/app/models/authorship.rb | ||
|---|---|---|
| 1 | 1 |
class Authorship < ActiveRecord::Base |
| 2 | 2 |
belongs_to :author |
| 3 | 3 |
belongs_to :publication |
| 4 |
|
|
| 4 | 5 |
end |
| vendor/plugins/redmine_bibliography/app/models/bibtex_entry.rb | ||
|---|---|---|
| 1 |
class BibtexEntry < ActiveRecord::Base |
|
| 2 |
belongs_to :publication |
|
| 3 |
|
|
| 4 |
end |
|
| vendor/plugins/redmine_bibliography/app/models/publication.rb | ||
|---|---|---|
| 3 | 3 |
class Publication < ActiveRecord::Base |
| 4 | 4 |
has_many :authorships |
| 5 | 5 |
has_many :authors, :through => :authorships |
| 6 |
has_one :bibtex_entry |
|
| 6 | 7 |
|
| 7 | 8 |
validates_presence_of :title |
| 8 | 9 |
|
| vendor/plugins/redmine_bibliography/test/fixtures/bibtex_entries.yml | ||
|---|---|---|
| 1 |
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html |
|
| 2 |
one: |
|
| 3 |
id: 1 |
|
| 4 |
entry_type: |
|
| 5 |
address: |
|
| 6 |
annote: |
|
| 7 |
booktitle: |
|
| 8 |
chapter: |
|
| 9 |
crossref: |
|
| 10 |
edition: |
|
| 11 |
editor: |
|
| 12 |
eprint: |
|
| 13 |
howpublished: |
|
| 14 |
journal: |
|
| 15 |
key: |
|
| 16 |
month: |
|
| 17 |
note: |
|
| 18 |
number: |
|
| 19 |
organization: |
|
| 20 |
pages: |
|
| 21 |
publisher: |
|
| 22 |
school: |
|
| 23 |
series: |
|
| 24 |
type: |
|
| 25 |
url: |
|
| 26 |
volume: |
|
| 27 |
year: 1 |
|
| 28 |
two: |
|
| 29 |
id: 2 |
|
| 30 |
entry_type: |
|
| 31 |
address: |
|
| 32 |
annote: |
|
| 33 |
booktitle: |
|
| 34 |
chapter: |
|
| 35 |
crossref: |
|
| 36 |
edition: |
|
| 37 |
editor: |
|
| 38 |
eprint: |
|
| 39 |
howpublished: |
|
| 40 |
journal: |
|
| 41 |
key: |
|
| 42 |
month: |
|
| 43 |
note: |
|
| 44 |
number: |
|
| 45 |
organization: |
|
| 46 |
pages: |
|
| 47 |
publisher: |
|
| 48 |
school: |
|
| 49 |
series: |
|
| 50 |
type: |
|
| 51 |
url: |
|
| 52 |
volume: |
|
| 53 |
year: 1 |
|
| vendor/plugins/redmine_bibliography/test/unit/bibtex_entry_test.rb | ||
|---|---|---|
| 1 |
require File.dirname(__FILE__) + '/../test_helper' |
|
| 2 |
|
|
| 3 |
class BibtexEntryTest < ActiveSupport::TestCase |
|
| 4 |
fixtures :bibtex_entries |
|
| 5 |
|
|
| 6 |
# Replace this with your real tests. |
|
| 7 |
def test_truth |
|
| 8 |
assert true |
|
| 9 |
end |
|
| 10 |
end |
|
Also available in: Unified diff