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 @@
<%= link_to('New contact', new_contact_path) %>
+ <% @contacts.rows.each do |contact| -%>