public
Fork of AndrewO/page_attachments
Description: A clone of Radiant's page_attachments extension with a bugfix
Homepage: http://wiki.radiantcms.org/Installing_Extension_-_Page_Attachments
Clone URL: git://github.com/joelw/page_attachments.git
Joel Williams (author)
Sun Jun 01 02:18:20 -0700 2008
commit  454eb88bac9a3d31342f6f506091b71216f129ba
tree    9d86fa1ebbc7088e6e2d3faced65cb9ba800fd0e
parent  2bfd3ca5d44f39057bf796b65a1368a50ba76cd8
page_attachments / page_attachments_extension.rb
100644 41 lines (33 sloc) 1.319 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
require_dependency 'application'
require File.dirname(__FILE__)+'/lib/geometry'
require 'tempfile'
 
class PageAttachmentsExtension < Radiant::Extension
  version "0.2"
  description "Adds page-attachment-style asset management."
  url "http://seancribbs.com"
 
# define_routes do |map|
# map.connect 'admin/attachments/:action/:id', :controller => 'page_attachments'
# end
  
  def activate
    # Contents of attachment_fu/init.rb
    
    Tempfile.class_eval do
      # overwrite so tempfiles use the extension of the basename. important for rmagick and image science
      def make_tmpname(basename, n)
        ext = nil
        sprintf("%s%d-%d%s", basename.to_s.gsub(/\.\w+$/) { |s| ext = s; '' }, $$, n, ext)
      end
    end
    
    ActiveRecord::Base.send(:extend, Technoweenie::AttachmentFu::ActMethods)
    Technoweenie::AttachmentFu.tempfile_path = ATTACHMENT_FU_TEMPFILE_PATH if Object.const_defined?(:ATTACHMENT_FU_TEMPFILE_PATH)
    FileUtils.mkdir_p Technoweenie::AttachmentFu.tempfile_path
 
    # Regular page attachments stuff
    Page.class_eval {
      include PageAttachmentAssociations
      include PageAttachmentTags
    }
    UserActionObserver.send :include, ObservePageAttachments
    Admin::PageController.send :include, PageAttachmentsInterface
  end
  
  def deactivate
  end
    
end