uploadcare-rails 0.6.1 → 1.0.0.rc4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +1 -1
- data/Rakefile +13 -8
- data/app/assets/javascripts/uploadcare-0.17.0.js +8248 -0
- data/app/assets/javascripts/uploadcare-0.17.0.min.js +17 -0
- data/app/assets/javascripts/uploadcare.js +1 -1
- data/config/initializers/uploadcare.rb +27 -0
- data/config/uploadcare_defaults.yml +12 -0
- data/lib/generators/templates/uploadcare_config_template.yml +56 -0
- data/lib/generators/uploadcare_config_generator.rb +9 -0
- data/lib/tasks/uploadcare_rails_tasks.rake +4 -0
- data/lib/uploadcare-rails.rb +6 -2
- data/lib/uploadcare/rails/action_view_include_tags.rb +36 -0
- data/lib/uploadcare/rails/action_view_uploader_tags.rb +75 -0
- data/lib/uploadcare/rails/active_record_has_file.rb +46 -0
- data/lib/uploadcare/rails/active_record_has_group.rb +43 -0
- data/lib/uploadcare/rails/engine.rb +17 -11
- data/lib/uploadcare/rails/file.rb +17 -20
- data/lib/uploadcare/rails/group.rb +27 -0
- data/lib/uploadcare/rails/settings.rb +63 -50
- data/lib/uploadcare/rails/version.rb +1 -1
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/javascripts/post_with_collections.js +2 -0
- data/spec/dummy/app/assets/javascripts/posts.js +2 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/assets/stylesheets/post_with_collections.css +4 -0
- data/spec/dummy/app/assets/stylesheets/posts.css +4 -0
- data/spec/dummy/app/assets/stylesheets/scaffold.css +56 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/controllers/post_with_collections_controller.rb +58 -0
- data/spec/dummy/app/controllers/posts_controller.rb +58 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/helpers/post_with_collections_helper.rb +2 -0
- data/spec/dummy/app/helpers/posts_helper.rb +2 -0
- data/spec/dummy/app/models/post.rb +3 -0
- data/spec/dummy/app/models/post_with_collection.rb +3 -0
- data/spec/dummy/app/views/layouts/application.html.erb +16 -0
- data/spec/dummy/app/views/post_with_collections/_form.html.erb +25 -0
- data/spec/dummy/app/views/post_with_collections/edit.html.erb +6 -0
- data/spec/dummy/app/views/post_with_collections/index.html.erb +29 -0
- data/spec/dummy/app/views/post_with_collections/new.html.erb +5 -0
- data/spec/dummy/app/views/post_with_collections/show.html.erb +14 -0
- data/spec/dummy/app/views/posts/_form.html.erb +25 -0
- data/spec/dummy/app/views/posts/edit.html.erb +6 -0
- data/spec/dummy/app/views/posts/index.html.erb +37 -0
- data/spec/dummy/app/views/posts/new.html.erb +5 -0
- data/spec/dummy/app/views/posts/show.html.erb +15 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +23 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +29 -0
- data/spec/dummy/config/environments/production.rb +80 -0
- data/spec/dummy/config/environments/test.rb +36 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +12 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +61 -0
- data/spec/dummy/config/uploadcare.yml +56 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/20131119080328_create_posts.rb +10 -0
- data/spec/dummy/db/migrate/20131220083857_create_post_with_collections.rb +10 -0
- data/spec/dummy/db/schema.rb +30 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +9900 -0
- data/spec/dummy/log/test.log +1976 -0
- data/spec/dummy/public/404.html +58 -0
- data/spec/dummy/public/422.html +58 -0
- data/spec/dummy/public/500.html +57 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/tmp/cache/65C/2B0/uc.file.123213.store +1 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/1004cb216c6a15b26aa9c52095902ee6 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/1930f1dc4fdf14493b9e0803644ae54a +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/1e8f75a6b5b33970fb8e397347caa0a1 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/24204f742af588c8166d3160b500d20f +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/371bf96e99717688ed7313a0c53f4212 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/416150dc3ac35079c94273cc46e90aa6 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/510da110ae528e2d22533be39ff696c5 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/5384ad85f52d3272dbc64d46ef3876a4 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/6fc757c2c8329244ca95d6909865bbc2 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/883a8569a0105010b3a20e0b3dbdf927 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/95f1667ad97500a482296c32c98e0fa0 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/c5ee0ee454770d592be595422c5f89b8 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/c85016e7bbd4f3adbb7635d01f85d39b +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/d066c004d1fd26ae76a61303a7a18145 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/e41598315cab1b953e63b62bc36ee2f6 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/spec/dummy/tmp/restart.txt +0 -0
- data/spec/helpers/form_helpers_has_file_spec.rb +30 -0
- data/spec/helpers/form_helpers_has_group_spec.rb +30 -0
- data/spec/helpers/form_helpers_spec.rb +33 -0
- data/spec/helpers/include_tags_spec.rb +42 -0
- data/spec/helpers/uploader_tags_spec.rb +15 -0
- data/spec/models/file.rb +25 -0
- data/spec/models/group.rb +36 -0
- data/spec/models/has_file_spec.rb +31 -0
- data/spec/models/has_group_spec.rb +31 -0
- data/spec/spec_helper.rb +40 -0
- data/spec/uploadcare_rails_settings_spec.rb +50 -0
- metadata +290 -51
- data/README.md +0 -104
- data/app/assets/javascripts/uploadcare-0.8.js +0 -22865
- data/lib/uploadcare/rails/action_view.rb +0 -49
- data/lib/uploadcare/rails/active_record.rb +0 -61
- data/lib/uploadcare/rails/simple_form.rb +0 -9
@@ -1,49 +0,0 @@
|
|
1
|
-
module Uploadcare::Rails::ActionView
|
2
|
-
module Helpers
|
3
|
-
def uploadcare_include_tag(options = {})
|
4
|
-
s = Rails.application.config.uploadcare
|
5
|
-
|
6
|
-
src = ''
|
7
|
-
s.get_widget_settings.each do |k, v|
|
8
|
-
src << "UPLOADCARE_#{k.to_s.underscore.upcase} = \"#{j(v)}\";\n"
|
9
|
-
end
|
10
|
-
settings_code = javascript_tag(src)
|
11
|
-
|
12
|
-
version = options[:version] || s.widget_version
|
13
|
-
min = options[:min].nil? || options[:min]
|
14
|
-
url = "https://ucarecdn.com/widget/#{version}/uploadcare/uploadcare-#{version}#{'.min' if min}.js"
|
15
|
-
include_code = javascript_include_tag(url)
|
16
|
-
|
17
|
-
settings_code + include_code
|
18
|
-
end
|
19
|
-
|
20
|
-
def uploadcare_uploader_options(options)
|
21
|
-
options.symbolize_keys.deep_merge({
|
22
|
-
:role => "#{options[:role]} uploadcare-uploader",
|
23
|
-
:data => {:path_value => true}
|
24
|
-
})
|
25
|
-
end
|
26
|
-
|
27
|
-
def uploadcare_uploader_tag(name, options = {})
|
28
|
-
options = uploadcare_uploader_options(options)
|
29
|
-
hidden_field_tag(name, nil, options)
|
30
|
-
end
|
31
|
-
|
32
|
-
def uploadcare_uploader_field(object_name, method, options = {})
|
33
|
-
options = uploadcare_uploader_options(options)
|
34
|
-
hidden_field(object_name, method, options)
|
35
|
-
end
|
36
|
-
|
37
|
-
def self.included(arg)
|
38
|
-
ActionView::Helpers::FormBuilder.send(:include, Uploadcare::Rails::ActionView::FormBuilder)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
module FormBuilder
|
43
|
-
def uploadcare_uploader_field(method, options = {})
|
44
|
-
@template.uploadcare_uploader_field(@object_name, method, objectify_options(options))
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
ActionView::Base.send :include, Uploadcare::Rails::ActionView::Helpers
|
@@ -1,61 +0,0 @@
|
|
1
|
-
require 'uploadcare/rails/file'
|
2
|
-
|
3
|
-
module Uploadcare
|
4
|
-
module Rails
|
5
|
-
module ActiveRecord
|
6
|
-
def is_uploadcare_file attribute, options = {}
|
7
|
-
options.symbolize_keys!
|
8
|
-
opts = {
|
9
|
-
autostore: true,
|
10
|
-
force_autostore: false
|
11
|
-
}.update options
|
12
|
-
|
13
|
-
define_method "#{attribute}" do
|
14
|
-
cdn_url = attributes[attribute.to_s].to_s
|
15
|
-
return nil if cdn_url.empty?
|
16
|
-
|
17
|
-
if instance_variable_defined?("@#{attribute}_cached")
|
18
|
-
instance_variable_get("@#{attribute}_cached")
|
19
|
-
else
|
20
|
-
api = ::Rails.application.config.uploadcare.api
|
21
|
-
file_data = File.new(api, cdn_url)
|
22
|
-
instance_variable_set("@#{attribute}_cached", file_data)
|
23
|
-
file_data
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
if opts[:autostore]
|
28
|
-
after_save "store_#{attribute}"
|
29
|
-
|
30
|
-
define_method "store_#{attribute}" do
|
31
|
-
re = /[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}/i
|
32
|
-
m = re.match(attributes[attribute.to_s])
|
33
|
-
return unless m && m[0]
|
34
|
-
|
35
|
-
uuid = m[0]
|
36
|
-
stored = ::Rails.cache.exist?(
|
37
|
-
"uploadcare.file.#{uuid}.store",
|
38
|
-
force: opts[:force_autostore]
|
39
|
-
)
|
40
|
-
|
41
|
-
unless stored
|
42
|
-
begin
|
43
|
-
send(attribute).api.store
|
44
|
-
::Rails.cache.write("uploadcare.file.#{uuid}.store", true)
|
45
|
-
rescue ArgumentError => e
|
46
|
-
|
47
|
-
logger.error "\nError while saving a file: #{e.class} (#{e.message}):"
|
48
|
-
logger.error "#{::Rails.backtrace_cleaner.clean(e.backtrace).join("\n ")}"
|
49
|
-
|
50
|
-
raise e unless ::Rails.application.config.uploadcare.silence_save_errors
|
51
|
-
end
|
52
|
-
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
ActiveRecord::Base.extend Uploadcare::Rails::ActiveRecord
|
@@ -1,9 +0,0 @@
|
|
1
|
-
module Uploadcare::Rails::SimpleForm
|
2
|
-
class UploadcareUploaderInput < SimpleForm::Inputs::HiddenInput
|
3
|
-
def input_html_options
|
4
|
-
@input_html_options.merge role: "#{@input_html_options[:role]} uploadcare-uploader"
|
5
|
-
end
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
SimpleForm::Inputs.send :include, Uploadcare::Rails::SimpleForm
|