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.
Files changed (121) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +1 -1
  3. data/Rakefile +13 -8
  4. data/app/assets/javascripts/uploadcare-0.17.0.js +8248 -0
  5. data/app/assets/javascripts/uploadcare-0.17.0.min.js +17 -0
  6. data/app/assets/javascripts/uploadcare.js +1 -1
  7. data/config/initializers/uploadcare.rb +27 -0
  8. data/config/uploadcare_defaults.yml +12 -0
  9. data/lib/generators/templates/uploadcare_config_template.yml +56 -0
  10. data/lib/generators/uploadcare_config_generator.rb +9 -0
  11. data/lib/tasks/uploadcare_rails_tasks.rake +4 -0
  12. data/lib/uploadcare-rails.rb +6 -2
  13. data/lib/uploadcare/rails/action_view_include_tags.rb +36 -0
  14. data/lib/uploadcare/rails/action_view_uploader_tags.rb +75 -0
  15. data/lib/uploadcare/rails/active_record_has_file.rb +46 -0
  16. data/lib/uploadcare/rails/active_record_has_group.rb +43 -0
  17. data/lib/uploadcare/rails/engine.rb +17 -11
  18. data/lib/uploadcare/rails/file.rb +17 -20
  19. data/lib/uploadcare/rails/group.rb +27 -0
  20. data/lib/uploadcare/rails/settings.rb +63 -50
  21. data/lib/uploadcare/rails/version.rb +1 -1
  22. data/spec/dummy/README.rdoc +28 -0
  23. data/spec/dummy/Rakefile +6 -0
  24. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  25. data/spec/dummy/app/assets/javascripts/post_with_collections.js +2 -0
  26. data/spec/dummy/app/assets/javascripts/posts.js +2 -0
  27. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  28. data/spec/dummy/app/assets/stylesheets/post_with_collections.css +4 -0
  29. data/spec/dummy/app/assets/stylesheets/posts.css +4 -0
  30. data/spec/dummy/app/assets/stylesheets/scaffold.css +56 -0
  31. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  32. data/spec/dummy/app/controllers/post_with_collections_controller.rb +58 -0
  33. data/spec/dummy/app/controllers/posts_controller.rb +58 -0
  34. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  35. data/spec/dummy/app/helpers/post_with_collections_helper.rb +2 -0
  36. data/spec/dummy/app/helpers/posts_helper.rb +2 -0
  37. data/spec/dummy/app/models/post.rb +3 -0
  38. data/spec/dummy/app/models/post_with_collection.rb +3 -0
  39. data/spec/dummy/app/views/layouts/application.html.erb +16 -0
  40. data/spec/dummy/app/views/post_with_collections/_form.html.erb +25 -0
  41. data/spec/dummy/app/views/post_with_collections/edit.html.erb +6 -0
  42. data/spec/dummy/app/views/post_with_collections/index.html.erb +29 -0
  43. data/spec/dummy/app/views/post_with_collections/new.html.erb +5 -0
  44. data/spec/dummy/app/views/post_with_collections/show.html.erb +14 -0
  45. data/spec/dummy/app/views/posts/_form.html.erb +25 -0
  46. data/spec/dummy/app/views/posts/edit.html.erb +6 -0
  47. data/spec/dummy/app/views/posts/index.html.erb +37 -0
  48. data/spec/dummy/app/views/posts/new.html.erb +5 -0
  49. data/spec/dummy/app/views/posts/show.html.erb +15 -0
  50. data/spec/dummy/bin/bundle +3 -0
  51. data/spec/dummy/bin/rails +4 -0
  52. data/spec/dummy/bin/rake +4 -0
  53. data/spec/dummy/config.ru +4 -0
  54. data/spec/dummy/config/application.rb +23 -0
  55. data/spec/dummy/config/boot.rb +5 -0
  56. data/spec/dummy/config/database.yml +25 -0
  57. data/spec/dummy/config/environment.rb +5 -0
  58. data/spec/dummy/config/environments/development.rb +29 -0
  59. data/spec/dummy/config/environments/production.rb +80 -0
  60. data/spec/dummy/config/environments/test.rb +36 -0
  61. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  62. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  63. data/spec/dummy/config/initializers/inflections.rb +16 -0
  64. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  65. data/spec/dummy/config/initializers/secret_token.rb +12 -0
  66. data/spec/dummy/config/initializers/session_store.rb +3 -0
  67. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  68. data/spec/dummy/config/locales/en.yml +23 -0
  69. data/spec/dummy/config/routes.rb +61 -0
  70. data/spec/dummy/config/uploadcare.yml +56 -0
  71. data/spec/dummy/db/development.sqlite3 +0 -0
  72. data/spec/dummy/db/migrate/20131119080328_create_posts.rb +10 -0
  73. data/spec/dummy/db/migrate/20131220083857_create_post_with_collections.rb +10 -0
  74. data/spec/dummy/db/schema.rb +30 -0
  75. data/spec/dummy/db/test.sqlite3 +0 -0
  76. data/spec/dummy/log/development.log +9900 -0
  77. data/spec/dummy/log/test.log +1976 -0
  78. data/spec/dummy/public/404.html +58 -0
  79. data/spec/dummy/public/422.html +58 -0
  80. data/spec/dummy/public/500.html +57 -0
  81. data/spec/dummy/public/favicon.ico +0 -0
  82. data/spec/dummy/tmp/cache/65C/2B0/uc.file.123213.store +1 -0
  83. data/spec/dummy/tmp/cache/assets/development/sprockets/1004cb216c6a15b26aa9c52095902ee6 +0 -0
  84. data/spec/dummy/tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
  85. data/spec/dummy/tmp/cache/assets/development/sprockets/1930f1dc4fdf14493b9e0803644ae54a +0 -0
  86. data/spec/dummy/tmp/cache/assets/development/sprockets/1e8f75a6b5b33970fb8e397347caa0a1 +0 -0
  87. data/spec/dummy/tmp/cache/assets/development/sprockets/24204f742af588c8166d3160b500d20f +0 -0
  88. data/spec/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
  89. data/spec/dummy/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
  90. data/spec/dummy/tmp/cache/assets/development/sprockets/371bf96e99717688ed7313a0c53f4212 +0 -0
  91. data/spec/dummy/tmp/cache/assets/development/sprockets/416150dc3ac35079c94273cc46e90aa6 +0 -0
  92. data/spec/dummy/tmp/cache/assets/development/sprockets/510da110ae528e2d22533be39ff696c5 +0 -0
  93. data/spec/dummy/tmp/cache/assets/development/sprockets/5384ad85f52d3272dbc64d46ef3876a4 +0 -0
  94. data/spec/dummy/tmp/cache/assets/development/sprockets/6fc757c2c8329244ca95d6909865bbc2 +0 -0
  95. data/spec/dummy/tmp/cache/assets/development/sprockets/883a8569a0105010b3a20e0b3dbdf927 +0 -0
  96. data/spec/dummy/tmp/cache/assets/development/sprockets/95f1667ad97500a482296c32c98e0fa0 +0 -0
  97. data/spec/dummy/tmp/cache/assets/development/sprockets/c5ee0ee454770d592be595422c5f89b8 +0 -0
  98. data/spec/dummy/tmp/cache/assets/development/sprockets/c85016e7bbd4f3adbb7635d01f85d39b +0 -0
  99. data/spec/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
  100. data/spec/dummy/tmp/cache/assets/development/sprockets/d066c004d1fd26ae76a61303a7a18145 +0 -0
  101. data/spec/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
  102. data/spec/dummy/tmp/cache/assets/development/sprockets/e41598315cab1b953e63b62bc36ee2f6 +0 -0
  103. data/spec/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
  104. data/spec/dummy/tmp/restart.txt +0 -0
  105. data/spec/helpers/form_helpers_has_file_spec.rb +30 -0
  106. data/spec/helpers/form_helpers_has_group_spec.rb +30 -0
  107. data/spec/helpers/form_helpers_spec.rb +33 -0
  108. data/spec/helpers/include_tags_spec.rb +42 -0
  109. data/spec/helpers/uploader_tags_spec.rb +15 -0
  110. data/spec/models/file.rb +25 -0
  111. data/spec/models/group.rb +36 -0
  112. data/spec/models/has_file_spec.rb +31 -0
  113. data/spec/models/has_group_spec.rb +31 -0
  114. data/spec/spec_helper.rb +40 -0
  115. data/spec/uploadcare_rails_settings_spec.rb +50 -0
  116. metadata +290 -51
  117. data/README.md +0 -104
  118. data/app/assets/javascripts/uploadcare-0.8.js +0 -22865
  119. data/lib/uploadcare/rails/action_view.rb +0 -49
  120. data/lib/uploadcare/rails/active_record.rb +0 -61
  121. 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