diff --git a/.gitmodules b/.gitmodules index fd4584e..cb58993 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "vendor/plugins/basic_model"] path = vendor/plugins/basic_model url = git://github.com/topfunky/basic_model.git +[submodule "vendor/plugins/pdf_label_maker"] + path = vendor/plugins/pdf_label_maker + url = git://github.com/sermoa/pdf_label_maker.git diff --git a/app/controllers/contacts_controller.rb b/app/controllers/contacts_controller.rb index d54a340..82159e1 100644 --- a/app/controllers/contacts_controller.rb +++ b/app/controllers/contacts_controller.rb @@ -2,6 +2,13 @@ class ContactsController < ApplicationController def index @contacts = Contact.view(database_name, 'contacts/by_last_name-map') + respond_to do |format| + format.pdf do + pdf = PdfLabelMaker.avery_labels(@contacts.rows) + send_data pdf.render, :filename => 'labels.pdf', :type => 'application/pdf' + end + format.html + end end def edit diff --git a/app/models/contact.rb b/app/models/contact.rb index 682450e..39ccd5c 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -1,7 +1,14 @@ - class Contact < BasicModel +class Contact < BasicModel def full_name "#{first_name} #{last_name}" end + + def label_lines + returning Array.new do |arr| + arr << full_name + address.split("\r\n").each{|line| arr << line} + end + end end diff --git a/app/views/contacts/index.html.erb b/app/views/contacts/index.html.erb index ce4f2e5..9fdc649 100644 --- a/app/views/contacts/index.html.erb +++ b/app/views/contacts/index.html.erb @@ -1,5 +1,7 @@

Contacts

+

<%= link_to('New contact', new_contact_path) %>

+ <% @contacts.rows.each do |contact| -%>

<%= contact.full_name %>

diff --git a/config/environment.rb b/config/environment.rb index c06a101..508d4a4 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -65,3 +65,7 @@ # Activate observers that should always be running # config.active_record.observers = :cacher, :garbage_collector end + + +Mime::Type.register 'application/pdf', :pdf + diff --git a/vendor/plugins/pdf_label_maker b/vendor/plugins/pdf_label_maker new file mode 160000 index 0000000..446b2c3 --- /dev/null +++ b/vendor/plugins/pdf_label_maker @@ -0,0 +1 @@ +Subproject commit 446b2c3ddd8135190bd3061730858e5691cf4bd3