uploadify-rails 3.1.1 → 3.1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile CHANGED
@@ -1,2 +1,2 @@
1
1
  source :rubygems
2
- gemspe
2
+ gemspec
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Uploadify::Rails
2
2
 
3
- TODO: Write a gem description
3
+ Uploadify plugin for Ruby on Rails asset pipeline.
4
4
 
5
5
  ## Installation
6
6
 
@@ -18,7 +18,45 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- TODO: Write usage instructions here
21
+ Add to your JavaScript pipeline:
22
+
23
+ //= require uploadify
24
+
25
+ Add to you CSS pipeline:
26
+
27
+ /*
28
+ *= require uploadify
29
+ */
30
+
31
+ You can configure options in an initializer. For example:
32
+
33
+ Uploadify::Rails.configure do |config|
34
+ config.uploader = 'uploads/create'
35
+ config.buttonText = lambda { I18n.t('uploader.upload_file') }
36
+ config.queueID = 'uploadify_queue_div'
37
+ config.onUploadSuccess = true
38
+ end
39
+
40
+ When you define any callbacks as true, you should define a function 'window.UploadifyRails.#{callback}' in your javascript asset files with the appropriate arguments. For convenience, you can run `rake uploadify_rails:coffee` to generate a coffeescript file with those functions already outlined. You can delete or leave as-is any functions in that file whose configuration values are not set to true.
41
+
42
+ For convenient access to your configuration, add to you ApplicationHelper:
43
+
44
+ include UploadifyRailsHelper
45
+
46
+ You can then access the uploadifier options using `uploadify_rails_options` in a view. For example:
47
+
48
+ <script type='text/javascript'>
49
+ $(document).ready(function() {
50
+ $('input#uploadify').uploadify(<%= uploadify_rails_options %>);
51
+ });
52
+ </script>
53
+
54
+ ## Using flash_cookie_session
55
+ If uploadify will be sending data back to your Rails application, just put 'gem "flash_cookie_session"' in your Gemfile, BEFORE 'gem "uploadify-rails"'.
56
+
57
+ (If you are designing a plugin, remember to put 'require "flash_cookie_session"' at the top of your engine file. Make sure it's included before 'require "uploadify-rails"'.)
58
+
59
+ In most cases, 'flash_cookie_session' should be in your Gemfile. However, if uploadify is configured to send data to a different web application, such as, for instance, if you're uploading files directly to Amazon S3, omit flash_cookie_session. (If you require it for other parts of your application, list it in the Gemfile AFTER "uploadify-rails".)
22
60
 
23
61
  ## Contributing
24
62
 
@@ -0,0 +1,8 @@
1
+ require 'uploadify-rails/callback_generator'
2
+
3
+ namespace :uploadify_rails do
4
+ desc "create uploadify.js.coffee in app/assets/javascripts with a skeleton of all Uploadify callbacks"
5
+ task :coffee do
6
+ Uploadify::Rails::CallbackGenerator.new.create_coffeescript_file
7
+ end
8
+ end
@@ -0,0 +1,55 @@
1
+ window.UploadifyRails = {}
2
+
3
+ window.UploadifyRails.onCancel = (file) ->
4
+ true
5
+
6
+ window.UploadifyRails.onClearQueue = (queueItemCount) ->
7
+ true
8
+
9
+ window.UploadifyRails.onDestroy = ->
10
+ true
11
+
12
+ window.UploadifyRails.onDialogClose = (queueData) ->
13
+ true
14
+
15
+ window.UploadifyRails.onDialogOpen = ->
16
+ true
17
+
18
+ window.UploadifyRails.onDisable = ->
19
+ true
20
+
21
+ window.UploadifyRails.onEnable = ->
22
+ true
23
+
24
+ window.UploadifyRails.onFallback = ->
25
+ true
26
+
27
+ window.UploadifyRails.onInit = (instance) ->
28
+ true
29
+
30
+ window.UploadifyRails.onQueueComplete = (queueData) ->
31
+ true
32
+
33
+ window.UploadifyRails.onSelect = (file) ->
34
+ true
35
+
36
+ window.UploadifyRails.onSelectError = (file, errorCode, errorMsg) ->
37
+ true
38
+
39
+ window.UploadifyRails.onSWFReady = ->
40
+ true
41
+
42
+ window.UploadifyRails.onUploadComplete = (file) ->
43
+ true
44
+
45
+ window.UploadifyRails.onUploadError = (file, errorCode, errorMsg, errorString) ->
46
+ true
47
+
48
+ window.UploadifyRails.onUploadProgress = (file, bytesUploaded, bytesTotal, totalBytesUploaded, totalBytesTotal) ->
49
+ true
50
+
51
+ window.UploadifyRails.onUploadStart = (file) ->
52
+ true
53
+
54
+ window.UploadifyRails.onUploadSuccess = (file, data, response) ->
55
+ true
@@ -1,2 +1,4 @@
1
+ require "uploadify-rails/helpers/uploadify_rails_helper"
2
+ require "uploadify-rails/configuration"
1
3
  require "uploadify-rails/version"
2
- require "uploadify-rails/engine"
4
+ require "uploadify-rails/engine"
@@ -0,0 +1,17 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/base'
3
+
4
+ module Uploadify
5
+ module Rails
6
+ class CallbackGenerator < ::Rails::Generators::Base
7
+ COFFEESCRIPT_FILE = 'uploadify-rails.js.coffee'
8
+ source_root File.expand_path("../../templates", __FILE__)
9
+
10
+ def create_coffeescript_file
11
+ puts "Creating coffeescript file..."
12
+ copy_file COFFEESCRIPT_FILE, ::Rails.application.config.root + 'app' + 'assets' + 'javascripts' + COFFEESCRIPT_FILE
13
+ puts "Done!"
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,134 @@
1
+ module Uploadify
2
+ module Rails
3
+ def self.configuration
4
+ @configuration ||= Configuration.new
5
+ end
6
+
7
+ def self.configure
8
+ yield self.configuration
9
+ end
10
+
11
+ class ConfigurationError < StandardError; end
12
+
13
+ class Configuration
14
+ private
15
+ def self.callbacks
16
+ [:onCancel, :onClearQueue, :onDestroy, :onDialogClose, :onDialogOpen, :onDisable, :onEnable, :onFallback, :onInit, :onQueueComplete, :onSelectError, :onSelect, :onSWFReady, :onUploadComplete, :onUploadError, :onUploadSuccess, :onUploadProgress, :onUploadStart]
17
+ end
18
+ def self.value_options
19
+ [:uploader, :buttonClass, :buttonCursor, :buttonImage, :buttonText, :checkExisting, :fileObjName, :fileSizeLimit, :fileTypeDesc, :fileTypeExts, :height, :method, :progressData, :queueID, :queueSizeLimit, :removeTimeout, :successTimeout, :uploadLimit, :width, :overrideEvents]
20
+ end
21
+ def self.bool_options
22
+ [:auto, :debug, :multi, :preventCaching, :removeCompleted, :requeueErrors]
23
+ end
24
+ def self.callback_args
25
+ @@callback_definitions ||= {
26
+ :onCancel => [:file],
27
+ :onClearQueue => [:queueItemCount],
28
+ :onDialogClose => [:queueData],
29
+ :onInit => [:instance],
30
+ :onQueueComplete => [:queueData],
31
+ :onSelect => [:file],
32
+ :onSelectError => [:file, :errorCode, :errorMsg],
33
+ :onUploadComplete => [:file],
34
+ :onUploadError => [:file, :errorCode, :errorMsg, :errorString],
35
+ :onUploadProgress => [:file, :bytesUploaded, :bytesTotal, :totalBytesUploaded, :totalBytesTotal],
36
+ :onUploadStart => [:file],
37
+ :onUploadSuccess => [:file, :data, :response]
38
+ }
39
+ end
40
+ public
41
+ self.callbacks.each { |option|
42
+ attr_accessor option
43
+ }
44
+ self.value_options.each { |option|
45
+ attr_accessor option
46
+ }
47
+ self.bool_options.each { |option|
48
+ attr_accessor option
49
+ }
50
+ attr_accessor :formData
51
+
52
+ if defined?(FlashCookieSession)
53
+ def uploadify_options protection_token, cookies, auth_token
54
+ generate_option_hash do |option_hash|
55
+ option_hash[:formData] = required_form_data(protection_token, cookies, auth_token).merge(@formData || {})
56
+ end
57
+ end
58
+ else
59
+ def uploadify_options
60
+ generate_option_hash do |option_hash|
61
+ option_hash[:formData] = @formData unless @formData.nil?
62
+ end
63
+ end
64
+ end
65
+
66
+ private
67
+ def generate_option_hash &block
68
+ validate_options
69
+ @option_hash = {}
70
+ insert_options self.class.value_options
71
+ insert_options self.class.bool_options
72
+ insert_options self.class.callbacks.each do |k,v|
73
+ @option_hash[k] = "_____#{k}____" if v
74
+ end
75
+ yield @option_hash
76
+ @json = @option_hash.to_json
77
+ set_callbacks_without_quotes
78
+ @json.html_safe
79
+ end
80
+
81
+ def validate_options
82
+ raise ConfigurationError, "UploadifyRails.Configuration.formData must be a hash" unless @formData.is_a?(Hash) || @formData.nil?
83
+ raise ConfigurationError, "UploadifyRails.Configuration.overrideEvents must be a Array" unless @overrideEvents.is_a?(Array) || @overrideEvents.nil?
84
+ raise ConfigurationError, "UploadifyRails.Configuration.progressData must be either :percentage or :speed" unless @progressData.nil? || [:percentage, :speed].include?(@progressData.to_sym)
85
+ raise ConfigurationError, "UploadifyRails.Configuration.buttonCursor must be either :arrow or :hand" unless @buttonCursor.nil? || [:arrow, :hand].include?(@buttonCursor.to_sym)
86
+ raise ConfigurationError, 'Please set UploadifyRails.Configuration.uploader to the route of the uploading action. Run `rake routes` to find the correct value' if @uploader.nil?
87
+ self.class.bool_options.each { |bool_option|
88
+ raise ConfigurationError, "UploadifyRails.Configuration.#{bool_option} must be either 'true' or 'false'" unless [true, false, nil].include?(get_value(bool_option))
89
+ }
90
+ self.class.callbacks.each { |callback|
91
+ raise ConfigurationError, "UploadifyRails.Configuration.#{callback} must be either 'true' or 'false'\nRun 'rake uploadify_rails:coffee' to generate a coffeescript file and define callbacks there" unless [true, false, nil].include?(get_value(callback))
92
+ }
93
+ end
94
+ def args_for callback
95
+ args = self.class.callback_args
96
+ args.key?(callback) ? args[callback].join(',') : ''
97
+ end
98
+ def set_callbacks_without_quotes
99
+ insert_options self.class.callbacks.each do |k,v|
100
+ if v
101
+ args = args_for k
102
+ @json.gsub!("\"#{@option_hash[k]}\"", "function(#{args}) { window.UploadifyRails.#{k}(#{args}); return true;}")
103
+ end
104
+ end
105
+ end
106
+ def get_value option
107
+ self.instance_variable_get("@#{option}")
108
+ end
109
+ def required_form_data protection_token, cookies, auth_token
110
+ @session_key ||= ::Rails.application.config.session_options[:key]
111
+ @forgery_token = protection_token
112
+ {
113
+ :_http_accept => 'application/javascript',
114
+ :_method => 'post',
115
+ @session_key => cookies[@session_key],
116
+ @forgery_token => auth_token
117
+ }
118
+ end
119
+ def insert_options keys
120
+ keys.each do |option|
121
+ value = get_value(option)
122
+ value = value.call if value.is_a?(Proc)
123
+ unless value.nil?
124
+ if block_given?
125
+ yield option, value
126
+ else
127
+ @option_hash[option] = value
128
+ end
129
+ end
130
+ end
131
+ end
132
+ end
133
+ end
134
+ end
@@ -0,0 +1,10 @@
1
+ module UploadifyRailsHelper
2
+ def uploadify_rails_options
3
+ config = Uploadify::Rails.configuration
4
+ if defined?(FlashCookieSession)
5
+ config.uploadify_options(request_forgery_protection_token, cookies, form_authenticity_token)
6
+ else
7
+ config.uploadify_options
8
+ end
9
+ end
10
+ end
@@ -1,5 +1,5 @@
1
1
  module Uploadify
2
2
  module Rails
3
- VERSION = "3.1.1"
3
+ VERSION = "3.1.1.1"
4
4
  end
5
5
  end
@@ -10,7 +10,7 @@ Gem::Specification.new do |gem|
10
10
  gem.email = ["filip@tepper.pl"]
11
11
  gem.description = %q{Uploadify plugin for Ruby on Rails asset pipeline}
12
12
  gem.summary = %q{Uploadify plugin for Ruby on Rails asset pipeline}
13
- gem.homepage = ""
13
+ gem.homepage = "https://github.com/filiptepper/uploadify-rails/"
14
14
 
15
15
  gem.files = `git ls-files`.split($/)
16
16
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uploadify-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.1
4
+ version: 3.1.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-05 00:00:00.000000000 Z
12
+ date: 2012-12-05 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Uploadify plugin for Ruby on Rails asset pipeline
15
15
  email:
@@ -23,8 +23,13 @@ files:
23
23
  - LICENSE.txt
24
24
  - README.md
25
25
  - Rakefile
26
+ - lib/tasks/install.rake
27
+ - lib/templates/uploadify-rails.js.coffee
26
28
  - lib/uploadify-rails.rb
29
+ - lib/uploadify-rails/callback_generator.rb
30
+ - lib/uploadify-rails/configuration.rb
27
31
  - lib/uploadify-rails/engine.rb
32
+ - lib/uploadify-rails/helpers/uploadify_rails_helper.rb
28
33
  - lib/uploadify-rails/version.rb
29
34
  - uploadify-rails.gemspec
30
35
  - vendor/assets/images/uploadify/uploadify-cancel.png
@@ -32,7 +37,7 @@ files:
32
37
  - vendor/assets/javascripts/uploadify.js
33
38
  - vendor/assets/javascripts/uploadify/jquery.uploadify.js.erb
34
39
  - vendor/assets/stylesheets/uploadify.css.erb
35
- homepage: ''
40
+ homepage: https://github.com/filiptepper/uploadify-rails/
36
41
  licenses: []
37
42
  post_install_message:
38
43
  rdoc_options: []