diff --git a/README.md b/README.md index f5ef182..edadaff 100644 --- a/README.md +++ b/README.md @@ -40,40 +40,19 @@ Use it as you would any other Paperclip processor. In your model: class Document < ActiveRecord::Base - has_attached_file :document, - - :styles => { - :original => { :params => "-z -j 100 -qq -G" } - }, - :processors => [:pdf_to_swf] + has_attached_file :pdf, + :styles => { + :swf => { + :params => "-z -j 100 -qq -G", + :format => "swf" } + }, + :processors => [:pdf_to_swf] end -which will convert your pdf document into swf. However, pdf extension will be retained. +which will convert your pdf document into swf , and keep both files (.swf and .pdf) on the server -In order to avoid this I have created a method to normalize file name and change it's extension. - - class Document < ActiveRecord::Base - - has_attached_file :document, - :styles => { - :original => { :params => "-z -j 100 -qq -G" } - }, - :processors => [:pdf_to_swf], - :path => ":rails_root/public/system/:attachment/:normalized_file_name", - :url => "/system/:attachment/:normalized_file_name" - - Paperclip.interpolates :normalized_file_name do |attachment, style| - attachment.instance.normalized_file_name - end - - def normalized_file_name - file = self.document_file_name.gsub( /[^a-zA-Z0-9_\-\.]/, '_') - file = "#{self.id}-#{File.basename(file, ".pdf")}".slice(0...32) - "#{file}.swf".downcase - end - end However, if you think you can do better, feel free to fork. diff --git a/lib/pdf_to_swf-paperclip-processor.rb b/lib/pdf_to_swf-paperclip-processor.rb index f50cc35..c03a597 100644 --- a/lib/pdf_to_swf-paperclip-processor.rb +++ b/lib/pdf_to_swf-paperclip-processor.rb @@ -2,7 +2,7 @@ module Paperclip class PdfToSwf < Processor - attr_accessor :params + attr_accessor :file, :params, :format def initialize file, options = {}, attachment = nil super @@ -10,11 +10,12 @@ def initialize file, options = {}, attachment = nil @params = options[:params] @current_format = File.extname(@file.path) @basename = File.basename(@file.path, @current_format) + @format = options[:format] end def make src = @file - dst = Tempfile.new([@basename.tableize]) + dst = Tempfile.new([@basename, @format ? ".#{@format}" : '']) begin parameters = [] parameters << @params diff --git a/lib/pdf_to_swf-paperclip-processor/version.rb b/lib/pdf_to_swf-paperclip-processor/version.rb index 1a4c8e1..9fb80d5 100644 --- a/lib/pdf_to_swf-paperclip-processor/version.rb +++ b/lib/pdf_to_swf-paperclip-processor/version.rb @@ -1,7 +1,7 @@ module Pdftoswf module Paperclip module Processor - VERSION = "0.0.2" + VERSION = "0.0.3" end end end diff --git a/pdf_to_swf-paperclip-processor.gemspec b/pdf_to_swf-paperclip-processor.gemspec index a2d3d3a..8efb2db 100644 --- a/pdf_to_swf-paperclip-processor.gemspec +++ b/pdf_to_swf-paperclip-processor.gemspec @@ -6,8 +6,8 @@ Gem::Specification.new do |s| s.name = "pdf_to_swf-paperclip-processor" s.version = Pdftoswf::Paperclip::Processor::VERSION s.platform = Gem::Platform::RUBY - s.authors = ["Armin Pašalić"] - s.email = ["apasalic@devlogic.eu"] + s.authors = ["Armin Pašalić", "Mojmir Novakovic-moonflash"] + s.email = ["apasalic@devlogic.eu","moonflash.as3@gmail.com"] s.homepage = "https://github.com/Krule/pdf_to_swf-paperclip-processor" s.summary = %q{Converts uploaded pdf to swf} s.description = %q{This gem is simple Paperclip processor which uses swftools to convert uploaded pdf files to swf}