Skip to content

Instantly share code, notes, and snippets.

@zakwilson
Created October 22, 2011 19:12
Show Gist options
  • Save zakwilson/1306373 to your computer and use it in GitHub Desktop.
Save zakwilson/1306373 to your computer and use it in GitHub Desktop.
#app/models/document.rb
class Document < ActiveRecord::Base
has_attached_file :attachment, styles: {html: {}}, :processors => [:htmlprocessor]
attr_accessor :attachment_file_name
end
#lib/paperclip_processors/htmlprocessor.rb
module Paperclip
class Htmlprocessor < Processor
class InstanceNotGiven < ArgumentError; end
def initialize(file, options = {})
super
@file = file
@instance = options[:instance]
@current_format = File.extname(@file.path)
@basename = File.basename(@file.path, @current_format)
end
def make
@file.pos = 0 # Reset the file position incase it is coming out of a another processor
dst = Tempfile.new([@basename, "html"].compact.join("."))
Paperclip.run("#{RAILS_ROOT}/DocumentConverter.py", "#{File.expand_path(@file.path)} #{File.expand_path(dst.path)}")
dst
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment