def attach_array(rev_id=nil) c=if rev_id || self.new_card? || selected_revision_id==current_revision_id self.content else Card::Revision.find_by_id(selected_revision_id).content end !c || c =~ /^\s* e Rails.logger.info "attachment_format issue: #{e.message}" nil end # FIXME: test extension matches content type def attachment_link(rev_id) # create filesystem links to previous revision if styles = case type_code when 'File'; [''] when 'Image'; STYLES end save_rev_id = selected_revision_id links = {} self.selected_revision_id = rev_id styles.each { |style| links[style] = attach.path(style) } self.selected_revision_id = current_revision_id styles.each { |style| File.link links[style], attach.path(style) } self.selected_revision_id = save_rev_id end end def before_post_attach # Rails.logger.info "bpa called for #{name}" at=self.attach at.instance_write :file_name, at.original_filename Card::ImageID == (type_id || Card.fetch_id( @type_args[:type] ) ) # returning true enables thumnail creation end def self.included(base) base.class_eval do has_attached_file :attach, :preserve_files=>true, :default_url => "missing", :url => ":file_path/:basename-:size:revision_id.:extension", :path => ":local/:card_id/:size:revision_id.:extension", :styles => { :icon => '16x16#', :small => '75x75', :medium => '200x200>', :large => '500x500>' } before_post_process :before_post_attach validates_each :attach do |rec, attr, value| if [Card::FileID, Card::ImageID].member? rec.type_id max_size = (max = Card['*upload max']) ? max.content.to_i : 5 if value.size.to_i > max_size.megabytes rec.errors.add :file_size, "File cannot be larger than #{max_size} megabytes" end end end end end module Paperclip::Interpolations extend Wagn::Location def local at, style_name if mod = at.instance.attach_mod # generalize this to work with any mod (needs design) "#{Wagn.gem_root}/mods/#{mod}/files" else Wagn.paths['files'].existent.first end end def file_path at, style_name wagn_path Wagn.config.files_web_path end def card_id at, style_name at.instance.id end def basename at, style_name at.instance.name.to_name.url_key end def size(at, style_name) at.instance.type_id==Card::FileID || style_name.blank? ? '' : "#{style_name}-" end def revision_id(at, style_name) at.instance.selected_revision_id end end