# HG changeset patch # User luisf # Date 1302715005 -3600 # Node ID 8a105a53b8f4305cbe3127015b0a0d7daaca0274 # Parent 216a61338322a8b2da0d15a58bef46bb708e84c4 Refactoring. diff -r 216a61338322 -r 8a105a53b8f4 vendor/plugins/redmine_bibliography/app/controllers/bibtex_entries_controller.rb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vendor/plugins/redmine_bibliography/app/controllers/bibtex_entries_controller.rb Wed Apr 13 18:16:45 2011 +0100 @@ -0,0 +1,55 @@ +class BibtexEntriesController < ApplicationController + + # parse string with bibtex authors + # return an ordered array + def parse_authors + + end + + # parses the bibtex file + def parse_bibtex_file + + end + + def parse_bibtex_list(bibtex_list) + bibliography = BibTeX.parse bibtex_list + + no_entries = bibliography.data.length + + logger.error "Gonna parse " no_entries.to_s " Bibtex entries" + + # parses the bibtex entries + bibliography.data.map do |d| + create_bibtex_entry d + end + + @publication.bibtex_entry = @bentry + + if @publication.save + logger.error "SAVED" + else + logger.error "NOT SAVED" + end + + logger.error @publication.bibtex_entry + end + + + + def create_bibtex_entry(d) + result = '' + if d.class == BibTeX::Entry + @bentry = BibtexEntry.new + + d.fields.keys.map do |k| + if k == "title" + @publication.title = d[k] + else + @bentry[k] = d[k] + end + end + @bentry.save! + end + end + +end \ No newline at end of file diff -r 216a61338322 -r 8a105a53b8f4 vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb --- a/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb Wed Apr 13 14:29:12 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb Wed Apr 13 18:16:45 2011 +0100 @@ -2,46 +2,6 @@ class PublicationsController < ApplicationController - # parse string with bibtex authors - # return an ordered array - def parse_authors - - end - - def parse_bibtex_file - - end - - def parse_bibtex_text - bib = BibTeX.parse bibtex_entry - - # parses the bibtex entries - bib.data.map do |d| - result = '' - if d.class == BibTeX::Entry - @bentry = BibtexEntry.new - # d.replace!(bib.strings) - - d.fields.keys.map do |k| - if k == "title" - @publication.title = d[k] - else - @bentry[k] = d[k] - end - end - end - end - - @publication.bibtex_entry = @bentry - - if @publication.save - logger.error "SAVED" - else - logger.error "NOT SAVED" - end - - logger.error @publication.bibtex_entry - end def new # we always try to create at least one publication @@ -63,7 +23,7 @@ # method for creating "pasted" bibtex entries if bibtex_entry - parse_bibtex_text + parse_bibtex_text bibtex_entry end # form's flow control @@ -78,6 +38,7 @@ render "new" end + def index @publications = Publication.find(:all) end diff -r 216a61338322 -r 8a105a53b8f4 vendor/plugins/redmine_bibliography/app/helpers/bibtex_entries_helper.rb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vendor/plugins/redmine_bibliography/app/helpers/bibtex_entries_helper.rb Wed Apr 13 18:16:45 2011 +0100 @@ -0,0 +1,5 @@ +require 'bibtex' + +module BibtexEntriesHelper + +end \ No newline at end of file diff -r 216a61338322 -r 8a105a53b8f4 vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb --- a/vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb Wed Apr 13 14:29:12 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb Wed Apr 13 18:16:45 2011 +0100 @@ -1,7 +1,3 @@ -# require 'rubygems' -require 'bibtex' - - module PublicationsHelper end diff -r 216a61338322 -r 8a105a53b8f4 vendor/plugins/redmine_bibliography/app/models/bibtex_entry.rb --- a/vendor/plugins/redmine_bibliography/app/models/bibtex_entry.rb Wed Apr 13 14:29:12 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/models/bibtex_entry.rb Wed Apr 13 18:16:45 2011 +0100 @@ -1,4 +1,4 @@ class BibtexEntry < ActiveRecord::Base belongs_to :publication - + end diff -r 216a61338322 -r 8a105a53b8f4 vendor/plugins/redmine_bibliography/app/views/publications/_new_bibtex_step.html.erb --- a/vendor/plugins/redmine_bibliography/app/views/publications/_new_bibtex_step.html.erb Wed Apr 13 14:29:12 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/views/publications/_new_bibtex_step.html.erb Wed Apr 13 18:16:45 2011 +0100 @@ -1,10 +1,6 @@

New Bibtex

-

- <%= f.label :title %> - <%= f.text_field :title %> -

- +

Paste your bibtex entries here

<%=label_tag :bibtex_entry %> <%=text_area_tag :bibtex_entry%> diff -r 216a61338322 -r 8a105a53b8f4 vendor/plugins/redmine_bibliography/app/views/publications/new.html.erb --- a/vendor/plugins/redmine_bibliography/app/views/publications/new.html.erb Wed Apr 13 14:29:12 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/views/publications/new.html.erb Wed Apr 13 18:16:45 2011 +0100 @@ -5,8 +5,8 @@ <%= render :partial => "#{@publication.current_step}_bibtex_step", :locals => { :f => f } %> - <%= f.submit "Continue" %> - <%= f.submit "Back", :name => "back_button" unless @publication.first_step? %> + <%= f.submit "Submit" %> + <% end %>