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
@@ -0,0 +1,27 @@
|
|
1
|
+
include ActionView::Helpers::AssetTagHelper
|
2
|
+
|
3
|
+
module Uploadcare
|
4
|
+
module Rails
|
5
|
+
class Group < Uploadcare::Api::Group
|
6
|
+
|
7
|
+
# override default to string method
|
8
|
+
# for group we just will return the uuid
|
9
|
+
def to_s
|
10
|
+
uuid
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
def map_files data
|
15
|
+
data["files"].map! do |file|
|
16
|
+
unless file.nil?
|
17
|
+
Uploadcare::Rails::File.new(@api, file["uuid"], file)
|
18
|
+
else
|
19
|
+
file
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
data
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -1,73 +1,86 @@
|
|
1
|
+
require "ostruct"
|
2
|
+
|
1
3
|
module Uploadcare
|
2
4
|
module Rails
|
3
5
|
class Settings < OpenStruct
|
4
|
-
|
5
|
-
super(*args)
|
6
|
-
settings = {
|
7
|
-
:public_key => 'demopublickey',
|
8
|
-
:private_key => 'demoprivatekey',
|
9
|
-
:widget_version => '0.8',
|
10
|
-
:silence_save_errors => false
|
11
|
-
}.update(settings)
|
12
|
-
settings.each do |k, v|
|
13
|
-
send "#{k}=", v
|
14
|
-
end
|
15
|
-
end
|
6
|
+
include ActiveModel::Validations
|
16
7
|
|
17
|
-
|
18
|
-
|
19
|
-
:api_url_base => false,
|
20
|
-
:api_version => false,
|
21
|
-
:private_key => false,
|
22
|
-
:widget_version => false,
|
23
|
-
:silence_save_errors => false,
|
24
|
-
|
25
|
-
# Renamed
|
26
|
-
:static_url_base => :cdn_base,
|
27
|
-
:upload_url_base => :url_base
|
28
|
-
}
|
29
|
-
|
30
|
-
def get_widget_settings
|
31
|
-
Hash[
|
32
|
-
marshal_dump
|
33
|
-
.reject{|k| @@widget_keys[k] == false }
|
34
|
-
.keys.map{|k| [@@widget_keys[k] || k, send(k)]}
|
35
|
-
]
|
36
|
-
end
|
8
|
+
# note that i did not include pub and private key even for demo
|
9
|
+
# point here to store them in one place and one place only
|
37
10
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
11
|
+
# settings validation (hey, why not? we already have all rails stack loaded :)
|
12
|
+
# so just use the godnes of rails magic and praise the lord!
|
13
|
+
validates :public_key, :presence => true
|
14
|
+
validates :private_key, :presence => true
|
15
|
+
|
16
|
+
# TODO: ALL the keys god damn it
|
17
|
+
PUBLIC_ALLOWED_KEYS = [:public_key,
|
18
|
+
:locale,
|
19
|
+
:images_only,
|
20
|
+
:multiple,
|
21
|
+
:multiple_min,
|
22
|
+
:multiple_max,
|
23
|
+
:preview_step,
|
24
|
+
:crop,
|
25
|
+
:clearable,
|
26
|
+
:tabs,
|
27
|
+
:autostore,
|
28
|
+
:live,
|
29
|
+
:manual_start,
|
30
|
+
:path_value
|
42
31
|
]
|
43
32
|
|
44
|
-
def
|
45
|
-
|
46
|
-
|
33
|
+
def initialize config
|
34
|
+
# extract envaroments settings
|
35
|
+
settings = config["#{::Rails.env}"]
|
36
|
+
raise ArgumentError.new "config is empty or not given at all" unless settings.present?
|
37
|
+
|
38
|
+
# build settings object (basicly openstruct)
|
39
|
+
# merge defaults with actual settings
|
40
|
+
|
41
|
+
# strip defaults suplied by uploadcare-ruby gem from private/pub key
|
42
|
+
uc_defaults = Uploadcare::DEFAULT_SETTINGS.except!(:public_key, :private_key)
|
43
|
+
defaults = Uploadcare::Rails::DEFAULT_SETTINGS.merge!(uc_defaults)
|
44
|
+
settings = defaults.merge!(settings)
|
45
|
+
super settings
|
47
46
|
|
48
|
-
|
49
|
-
|
47
|
+
# validates settings atributes.
|
48
|
+
unless valid?
|
49
|
+
raise ArgumentError.new "Private or public key options was not provaided"
|
50
|
+
end
|
50
51
|
end
|
51
52
|
|
52
53
|
|
54
|
+
def api_settings
|
55
|
+
@api_settings ||= build_api_settings
|
56
|
+
end
|
57
|
+
|
53
58
|
|
54
|
-
def
|
55
|
-
@
|
59
|
+
def widget_settings
|
60
|
+
@widget_settings ||= build_widget_settings
|
56
61
|
end
|
57
62
|
|
58
|
-
def
|
59
|
-
|
63
|
+
def build_widget_settings
|
64
|
+
settings = marshal_dump.slice(*PUBLIC_ALLOWED_KEYS)
|
60
65
|
end
|
66
|
+
private :build_widget_settings
|
61
67
|
|
62
68
|
|
69
|
+
def build_api_settings
|
70
|
+
marshal_dump
|
71
|
+
end
|
72
|
+
private :build_api_settings
|
73
|
+
|
63
74
|
|
64
|
-
def
|
65
|
-
@api
|
75
|
+
def api
|
76
|
+
@api ||= build_api
|
66
77
|
end
|
67
78
|
|
68
|
-
|
69
|
-
|
79
|
+
|
80
|
+
def build_api
|
81
|
+
Uploadcare::Api.new api_settings
|
70
82
|
end
|
83
|
+
private :build_api
|
71
84
|
end
|
72
85
|
end
|
73
|
-
end
|
86
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
== README
|
2
|
+
|
3
|
+
This README would normally document whatever steps are necessary to get the
|
4
|
+
application up and running.
|
5
|
+
|
6
|
+
Things you may want to cover:
|
7
|
+
|
8
|
+
* Ruby version
|
9
|
+
|
10
|
+
* System dependencies
|
11
|
+
|
12
|
+
* Configuration
|
13
|
+
|
14
|
+
* Database creation
|
15
|
+
|
16
|
+
* Database initialization
|
17
|
+
|
18
|
+
* How to run the test suite
|
19
|
+
|
20
|
+
* Services (job queues, cache servers, search engines, etc.)
|
21
|
+
|
22
|
+
* Deployment instructions
|
23
|
+
|
24
|
+
* ...
|
25
|
+
|
26
|
+
|
27
|
+
Please feel free to use a different markup language if you do not plan to run
|
28
|
+
<tt>rake doc:app</tt>.
|
data/spec/dummy/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require_tree .
|
@@ -0,0 +1,13 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the top of the
|
9
|
+
* compiled file, but it's generally better to create a new file per style scope.
|
10
|
+
*
|
11
|
+
*= require_self
|
12
|
+
*= require_tree .
|
13
|
+
*/
|
@@ -0,0 +1,56 @@
|
|
1
|
+
body { background-color: #fff; color: #333; }
|
2
|
+
|
3
|
+
body, p, ol, ul, td {
|
4
|
+
font-family: verdana, arial, helvetica, sans-serif;
|
5
|
+
font-size: 13px;
|
6
|
+
line-height: 18px;
|
7
|
+
}
|
8
|
+
|
9
|
+
pre {
|
10
|
+
background-color: #eee;
|
11
|
+
padding: 10px;
|
12
|
+
font-size: 11px;
|
13
|
+
}
|
14
|
+
|
15
|
+
a { color: #000; }
|
16
|
+
a:visited { color: #666; }
|
17
|
+
a:hover { color: #fff; background-color:#000; }
|
18
|
+
|
19
|
+
div.field, div.actions {
|
20
|
+
margin-bottom: 10px;
|
21
|
+
}
|
22
|
+
|
23
|
+
#notice {
|
24
|
+
color: green;
|
25
|
+
}
|
26
|
+
|
27
|
+
.field_with_errors {
|
28
|
+
padding: 2px;
|
29
|
+
background-color: red;
|
30
|
+
display: table;
|
31
|
+
}
|
32
|
+
|
33
|
+
#error_explanation {
|
34
|
+
width: 450px;
|
35
|
+
border: 2px solid red;
|
36
|
+
padding: 7px;
|
37
|
+
padding-bottom: 0;
|
38
|
+
margin-bottom: 20px;
|
39
|
+
background-color: #f0f0f0;
|
40
|
+
}
|
41
|
+
|
42
|
+
#error_explanation h2 {
|
43
|
+
text-align: left;
|
44
|
+
font-weight: bold;
|
45
|
+
padding: 5px 5px 5px 15px;
|
46
|
+
font-size: 12px;
|
47
|
+
margin: -7px;
|
48
|
+
margin-bottom: 0px;
|
49
|
+
background-color: #c00;
|
50
|
+
color: #fff;
|
51
|
+
}
|
52
|
+
|
53
|
+
#error_explanation ul li {
|
54
|
+
font-size: 12px;
|
55
|
+
list-style: square;
|
56
|
+
}
|
@@ -0,0 +1,58 @@
|
|
1
|
+
class PostWithCollectionsController < ApplicationController
|
2
|
+
before_action :set_post_with_collection, only: [:show, :edit, :update, :destroy]
|
3
|
+
|
4
|
+
# GET /post_with_collections
|
5
|
+
def index
|
6
|
+
@post_with_collections = PostWithCollection.all
|
7
|
+
end
|
8
|
+
|
9
|
+
# GET /post_with_collections/1
|
10
|
+
def show
|
11
|
+
end
|
12
|
+
|
13
|
+
# GET /post_with_collections/new
|
14
|
+
def new
|
15
|
+
@post_with_collection = PostWithCollection.new
|
16
|
+
end
|
17
|
+
|
18
|
+
# GET /post_with_collections/1/edit
|
19
|
+
def edit
|
20
|
+
end
|
21
|
+
|
22
|
+
# POST /post_with_collections
|
23
|
+
def create
|
24
|
+
@post_with_collection = PostWithCollection.new(post_with_collection_params)
|
25
|
+
|
26
|
+
if @post_with_collection.save
|
27
|
+
redirect_to @post_with_collection, notice: 'Post with collection was successfully created.'
|
28
|
+
else
|
29
|
+
render action: 'new'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# PATCH/PUT /post_with_collections/1
|
34
|
+
def update
|
35
|
+
if @post_with_collection.update(post_with_collection_params)
|
36
|
+
redirect_to @post_with_collection, notice: 'Post with collection was successfully updated.'
|
37
|
+
else
|
38
|
+
render action: 'edit'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# DELETE /post_with_collections/1
|
43
|
+
def destroy
|
44
|
+
@post_with_collection.destroy
|
45
|
+
redirect_to post_with_collections_url, notice: 'Post with collection was successfully destroyed.'
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
# Use callbacks to share common setup or constraints between actions.
|
50
|
+
def set_post_with_collection
|
51
|
+
@post_with_collection = PostWithCollection.find(params[:id])
|
52
|
+
end
|
53
|
+
|
54
|
+
# Only allow a trusted parameter "white list" through.
|
55
|
+
def post_with_collection_params
|
56
|
+
params.require(:post_with_collection).permit(:title, :file)
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
class PostsController < ApplicationController
|
2
|
+
before_action :set_post, only: [:show, :edit, :update, :destroy]
|
3
|
+
|
4
|
+
# GET /posts
|
5
|
+
def index
|
6
|
+
@posts = Post.all
|
7
|
+
end
|
8
|
+
|
9
|
+
# GET /posts/1
|
10
|
+
def show
|
11
|
+
end
|
12
|
+
|
13
|
+
# GET /posts/new
|
14
|
+
def new
|
15
|
+
@post = Post.new
|
16
|
+
end
|
17
|
+
|
18
|
+
# GET /posts/1/edit
|
19
|
+
def edit
|
20
|
+
end
|
21
|
+
|
22
|
+
# POST /posts
|
23
|
+
def create
|
24
|
+
@post = Post.new(post_params)
|
25
|
+
|
26
|
+
if @post.save
|
27
|
+
redirect_to @post, notice: 'Post was successfully created.'
|
28
|
+
else
|
29
|
+
render action: 'new'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# PATCH/PUT /posts/1
|
34
|
+
def update
|
35
|
+
if @post.update(post_params)
|
36
|
+
redirect_to @post, notice: 'Post was successfully updated.'
|
37
|
+
else
|
38
|
+
render action: 'edit'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# DELETE /posts/1
|
43
|
+
def destroy
|
44
|
+
@post.destroy
|
45
|
+
redirect_to posts_url, notice: 'Post was successfully destroyed.'
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
# Use callbacks to share common setup or constraints between actions.
|
50
|
+
def set_post
|
51
|
+
@post = Post.find(params[:id])
|
52
|
+
end
|
53
|
+
|
54
|
+
# Only allow a trusted parameter "white list" through.
|
55
|
+
def post_params
|
56
|
+
params.require(:post).permit(:title, :file)
|
57
|
+
end
|
58
|
+
end
|