Created
October 22, 2011 19:12
-
-
Save zakwilson/1306373 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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