Revision 405:8a105a53b8f4
| vendor/plugins/redmine_bibliography/app/controllers/bibtex_entries_controller.rb | ||
|---|---|---|
| 1 |
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 |
|
| vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb | ||
|---|---|---|
| 2 | 2 |
|
| 3 | 3 |
class PublicationsController < ApplicationController |
| 4 | 4 |
|
| 5 |
# parse string with bibtex authors |
|
| 6 |
# return an ordered array |
|
| 7 |
def parse_authors |
|
| 8 |
|
|
| 9 |
end |
|
| 10 |
|
|
| 11 |
def parse_bibtex_file |
|
| 12 |
|
|
| 13 |
end |
|
| 14 |
|
|
| 15 |
def parse_bibtex_text |
|
| 16 |
bib = BibTeX.parse bibtex_entry |
|
| 17 |
|
|
| 18 |
# parses the bibtex entries |
|
| 19 |
bib.data.map do |d| |
|
| 20 |
result = '' |
|
| 21 |
if d.class == BibTeX::Entry |
|
| 22 |
@bentry = BibtexEntry.new |
|
| 23 |
# d.replace!(bib.strings) |
|
| 24 |
|
|
| 25 |
d.fields.keys.map do |k| |
|
| 26 |
if k == "title" |
|
| 27 |
@publication.title = d[k] |
|
| 28 |
else |
|
| 29 |
@bentry[k] = d[k] |
|
| 30 |
end |
|
| 31 |
end |
|
| 32 |
end |
|
| 33 |
end |
|
| 34 |
|
|
| 35 |
@publication.bibtex_entry = @bentry |
|
| 36 |
|
|
| 37 |
if @publication.save |
|
| 38 |
logger.error "SAVED" |
|
| 39 |
else |
|
| 40 |
logger.error "NOT SAVED" |
|
| 41 |
end |
|
| 42 |
|
|
| 43 |
logger.error @publication.bibtex_entry |
|
| 44 |
end |
|
| 45 | 5 |
|
| 46 | 6 |
def new |
| 47 | 7 |
# we always try to create at least one publication |
| ... | ... | |
| 63 | 23 |
|
| 64 | 24 |
# method for creating "pasted" bibtex entries |
| 65 | 25 |
if bibtex_entry |
| 66 |
parse_bibtex_text |
|
| 26 |
parse_bibtex_text bibtex_entry
|
|
| 67 | 27 |
end |
| 68 | 28 |
|
| 69 | 29 |
# form's flow control |
| ... | ... | |
| 78 | 38 |
render "new" |
| 79 | 39 |
end |
| 80 | 40 |
|
| 41 |
|
|
| 81 | 42 |
def index |
| 82 | 43 |
@publications = Publication.find(:all) |
| 83 | 44 |
end |
| vendor/plugins/redmine_bibliography/app/helpers/bibtex_entries_helper.rb | ||
|---|---|---|
| 1 |
require 'bibtex' |
|
| 2 |
|
|
| 3 |
module BibtexEntriesHelper |
|
| 4 |
|
|
| 5 |
end |
|
| vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb | ||
|---|---|---|
| 1 |
# require 'rubygems' |
|
| 2 |
require 'bibtex' |
|
| 3 |
|
|
| 4 |
|
|
| 5 | 1 |
module PublicationsHelper |
| 6 | 2 |
|
| 7 | 3 |
end |
| vendor/plugins/redmine_bibliography/app/models/bibtex_entry.rb | ||
|---|---|---|
| 1 | 1 |
class BibtexEntry < ActiveRecord::Base |
| 2 | 2 |
belongs_to :publication |
| 3 |
|
|
| 3 |
|
|
| 4 | 4 |
end |
| vendor/plugins/redmine_bibliography/app/views/publications/_new_bibtex_step.html.erb | ||
|---|---|---|
| 1 | 1 |
<h3>New Bibtex</h3> |
| 2 | 2 |
|
| 3 |
<p> |
|
| 4 |
<%= f.label :title %> |
|
| 5 |
<%= f.text_field :title %> |
|
| 6 |
</p> |
|
| 7 |
|
|
| 3 |
<h4>Paste your bibtex entries here</h4> |
|
| 8 | 4 |
<p> |
| 9 | 5 |
<%=label_tag :bibtex_entry %> |
| 10 | 6 |
<%=text_area_tag :bibtex_entry%> |
| vendor/plugins/redmine_bibliography/app/views/publications/new.html.erb | ||
|---|---|---|
| 5 | 5 |
|
| 6 | 6 |
<%= render :partial => "#{@publication.current_step}_bibtex_step", :locals => { :f => f } %>
|
| 7 | 7 |
|
| 8 |
<%= f.submit "Continue" %>
|
|
| 9 |
<%= f.submit "Back", :name => "back_button" unless @publication.first_step? %> |
|
| 8 |
<%= f.submit "Submit" %>
|
|
| 9 |
|
|
| 10 | 10 |
|
| 11 | 11 |
<% end %> |
| 12 | 12 |
|
Also available in: Unified diff