File description patch for page_attachments

Hi all,
I sent this to the author directly but didn’t hear back, so in case
anyone’s
interested, here is is a patch for the page_attachment plugin that adds
a
‘description’ field. It’s not currently possible to edit the description
without removing the file and adding it again, but that’s good enough
for
me!

Joel

As far as I can tell, the attachment was stripped, so here’s the patch
inline:

Index: app/models/page_attachment_tags.rb

— app/models/page_attachment_tags.rb (revision 58)
+++ app/models/page_attachment_tags.rb (working copy)
@@ -35,7 +35,7 @@
attachment.public_filename(size)
end

  • [:content_type, :size, :width, :height].each do |key|
  • [:content_type, :size, :width, :height, :description].each do |key|
    desc %{
    Renders the `#{key}’ attribute of the attachment.
    The ‘name’ attribute is required on this tag or the parent tag.
    The optional ‘size’
    Index: app/models/page_attachment_associations.rb
    ===================================================================
    — app/models/page_attachment_associations.rb (revision 58)
    +++ app/models/page_attachment_associations.rb (working copy)
    @@ -4,6 +4,7 @@
    has_many :attachments, :class_name => “PageAttachment”,
    :dependent => :destroy

    attr_accessor :add_attachments
    
  •  attr_accessor :describe_attachments
     attr_accessor :delete_attachments
     after_save :save_attachments
     after_save :destroy_attachments
    

@@ -29,11 +30,11 @@

 def save_attachments
   if @add_attachments
  •    @add_attachments.each do |attachment|
    
  •      attachments << PageAttachment.new(:uploaded_data => 
    

attachment)

  •    @add_attachments.zip(@describe_attachments).each do 
    

|attachment, description|

  •      attachments << PageAttachment.new(:uploaded_data => 
    

attachment, :description => description)
end
end
@add_attachments = nil
end
end
-end
\ No newline at end of file
+end
Index: app/views/admin/page/_attachment.rhtml

— app/views/admin/page/_attachment.rhtml (revision 58)
+++ app/views/admin/page/_attachment.rhtml (working copy)
@@ -4,6 +4,7 @@
image_tag(attachment.thumbnails.first.public_filename,
:class => “thumbnail”)%>

<%= File.basename(attachment.public_filename) %>
  • <%= attachment.description %> <%= link_to_function image("minus", :title => "Remove

    attachment"), “remove_attachment(#{attachment.id})” %>


    -
    \ No newline at end of file
    +
    Index: db/migrate/001_create_page_attachments_extension_schema.rb

    — db/migrate/001_create_page_attachments_extension_schema.rb
    (revision 58)
    +++ db/migrate/001_create_page_attachments_extension_schema.rb (working
    copy)
    @@ -13,10 +13,11 @@
    t.column “updated_at”, :datetime
    t.column “updated_by”, :integer
    t.column “page_id”, :integer

    •  t.column "description",  :string
      

      end
      end

      def self.down
      drop_table “page_attachments”
      end
      -end
      \ No newline at end of file
      +end
      Index: public/javascripts/page_attachments.js
      ===================================================================
      — public/javascripts/page_attachments.js (revision 58)
      +++ public/javascripts/page_attachments.js (working copy)
      @@ -1,6 +1,6 @@
      function add_attachment() {
      var attachments_box = $(‘attachments’);

    • var template = new Template(‘

      Upload file: Cancel

      ’);
    • var template = new Template(‘

      Upload file: Description:Cancel

      ’);
      new Insertion.Bottom(attachments_box, template.evaluate({id:
      Math.round(Math.random() * 100000)}));
      }
      function remove_attachment(id){
      @@ -15,4 +15,4 @@
      }
      new Effect.Highlight(‘attachments-deleted’);
      }
      -}
      \ No newline at end of file
      +}