godmin-uploads 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +24 -0
- data/Gemfile +4 -0
- data/MIT-LICENSE +20 -0
- data/README.md +40 -0
- data/Rakefile +32 -0
- data/app/assets/javascripts/godmin-uploads/index.js +100 -0
- data/app/assets/stylesheets/godmin-uploads.css.scss +9 -0
- data/app/views/godmin/uploads/_uploader.html.erb +33 -0
- data/godmin-uploads.gemspec +28 -0
- data/lib/godmin/uploads/engine.rb +6 -0
- data/lib/godmin/uploads/helper.rb +15 -0
- data/lib/godmin/uploads/version.rb +5 -0
- data/lib/godmin/uploads.rb +11 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/images/.keep +0 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/controllers/concerns/.keep +0 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/mailers/.keep +0 -0
- data/test/dummy/app/models/.keep +0 -0
- data/test/dummy/app/models/concerns/.keep +0 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/config/application.rb +23 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +78 -0
- data/test/dummy/config/environments/test.rb +39 -0
- data/test/dummy/config/initializers/assets.rb +8 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +56 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/lib/assets/.keep +0 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/test_helper.rb +16 -0
- metadata +208 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 91b5c3c2adc026b7aa33854164913ddff4911887
|
4
|
+
data.tar.gz: b2e417524a219d249ffc2c9d10f413ad80cf7d00
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3d9e7f9736fb2a27ec9ae86a12549eaab740cc1532bc9a2680b710af645a0054722aa86f2836c8ec6f5df6f61b9c78486ea419b32b6d9534d7fb8f4f0caef0ee
|
7
|
+
data.tar.gz: bdb2455f3b5e40bb1fd6e8bf0f25b66c859d720003c206c5d6ccdc4a1496b7af8798b1d34f27429ef027895d072c45e6f36dec60b902fc8fdf3fed501267aa7a
|
data/.gitignore
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
*.rbc
|
2
|
+
*.sassc
|
3
|
+
.sass-cache
|
4
|
+
capybara-*.html
|
5
|
+
.rspec
|
6
|
+
.rvmrc
|
7
|
+
/.bundle
|
8
|
+
/vendor/bundle
|
9
|
+
/log/*
|
10
|
+
/tmp/*
|
11
|
+
/db/*.sqlite3
|
12
|
+
/public/system/*
|
13
|
+
/public/uploads/*
|
14
|
+
/coverage/
|
15
|
+
/spec/tmp/*
|
16
|
+
**.orig
|
17
|
+
rerun.txt
|
18
|
+
pickle-email-*.html
|
19
|
+
.project
|
20
|
+
config/initializers/secret_token.rb
|
21
|
+
.DS_Store
|
22
|
+
*.swp
|
23
|
+
/test/dummy/log/*
|
24
|
+
Gemfile.lock
|
data/Gemfile
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2014 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# Godmin Uploads
|
2
|
+
|
3
|
+
Godmin Uploads is a file upload component for [Godmin](https://github.com/varvet/godmin) that uses [refile](https://github.com/elabs/refile) for uploads.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add the gem to the application's `Gemfile`:
|
8
|
+
```ruby
|
9
|
+
gem "godmin-uploads"
|
10
|
+
```
|
11
|
+
|
12
|
+
Or to the admin engine's `gemspec`:
|
13
|
+
```ruby
|
14
|
+
s.add_dependency "godmin-uploads", "~> x.x.x"
|
15
|
+
```
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
See the [refile](https://github.com/elabs/refile) documentation for info on how to configure storage location, set up your model etc. Once that is done, require `godmin-uploads` in your application.js and application.css.
|
20
|
+
|
21
|
+
Then, simply use the `uploader` in your form like so:
|
22
|
+
|
23
|
+
```erb
|
24
|
+
<%= form_for(@resource) do |f| %>
|
25
|
+
<%= f.input_field :title %>
|
26
|
+
<%= f.text_field :body %>
|
27
|
+
|
28
|
+
<%= f.uploader :attachment, preview: true %>
|
29
|
+
<% end %>
|
30
|
+
```
|
31
|
+
|
32
|
+
The `preview` option should only be used for image attachments.
|
33
|
+
|
34
|
+
## Contributors
|
35
|
+
|
36
|
+
https://github.com/varvet/godmin-uploads/graphs/contributors
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
Licensed under the MIT license. See the separate MIT-LICENSE file.
|
data/Rakefile
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'GodminUploads'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
Bundler::GemHelper.install_tasks
|
21
|
+
|
22
|
+
require 'rake/testtask'
|
23
|
+
|
24
|
+
Rake::TestTask.new(:test) do |t|
|
25
|
+
t.libs << 'lib'
|
26
|
+
t.libs << 'test'
|
27
|
+
t.pattern = 'test/**/*_test.rb'
|
28
|
+
t.verbose = false
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
task default: :test
|
@@ -0,0 +1,100 @@
|
|
1
|
+
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
|
2
|
+
// about supported directives.
|
3
|
+
//
|
4
|
+
//= require refile
|
5
|
+
//= require_tree .
|
6
|
+
|
7
|
+
(function() {
|
8
|
+
|
9
|
+
var initialize = function() {
|
10
|
+
$(document).on("upload:start", ".godmin-upload", function(e) {
|
11
|
+
showProgressBar($(this));
|
12
|
+
});
|
13
|
+
|
14
|
+
$(document).on("upload:progress", ".godmin-upload", function(e) {
|
15
|
+
setProgressBarPercentage($(this), 50);
|
16
|
+
});
|
17
|
+
|
18
|
+
$(document).on("upload:complete", ".godmin-upload", function(e) {
|
19
|
+
setProgressBarPercentage($(this), 100);
|
20
|
+
});
|
21
|
+
|
22
|
+
$(document).on("upload:success", ".godmin-upload", function(e) {
|
23
|
+
setUploadPreview($(this));
|
24
|
+
setDownloadUrl($(this));
|
25
|
+
hideProgressBar($(this));
|
26
|
+
showButtons($(this));
|
27
|
+
});
|
28
|
+
|
29
|
+
$(document).on("upload:failure", ".godmin-upload", function(e) {
|
30
|
+
setProgressBarContext($(this), "danger");
|
31
|
+
});
|
32
|
+
|
33
|
+
$(document).on("click", ".godmin-upload-destroy-link", function(e) {
|
34
|
+
var $destroyField = $(this).parents(".godmin-upload").find(".godmin-upload-destroy-field");
|
35
|
+
|
36
|
+
if ($destroyField.val() === "") {
|
37
|
+
$(this).find("span").html("Undestroy file");
|
38
|
+
$destroyField.val("true");
|
39
|
+
} else {
|
40
|
+
$(this).find("span").html("Destroy file");
|
41
|
+
$destroyField.val("");
|
42
|
+
}
|
43
|
+
});
|
44
|
+
};
|
45
|
+
|
46
|
+
var showProgressBar = function($el) {
|
47
|
+
$el.find(".progress").show();
|
48
|
+
};
|
49
|
+
|
50
|
+
var hideProgressBar = function($el) {
|
51
|
+
setTimeout(function() {
|
52
|
+
$el.find(".progress").slideUp();
|
53
|
+
|
54
|
+
setTimeout(function() {
|
55
|
+
setProgressBarPercentage($el, 0);
|
56
|
+
}, 1000);
|
57
|
+
}, 2000);
|
58
|
+
};
|
59
|
+
|
60
|
+
var showButtons = function($el) {
|
61
|
+
$el.find(".godmin-upload-buttons").removeClass("hidden");
|
62
|
+
};
|
63
|
+
|
64
|
+
var setProgressBarPercentage = function($el, percentage) {
|
65
|
+
$el.find(".progress").find(".progress-bar").css("width", percentage + "%");
|
66
|
+
};
|
67
|
+
|
68
|
+
var setProgressBarContext = function($el, context) {
|
69
|
+
$el.find(".progress-bar").addClass("progress-bar-" + context);
|
70
|
+
};
|
71
|
+
|
72
|
+
var setUploadPreview = function($el) {
|
73
|
+
var $urlParts = getFileUrlParts($el);
|
74
|
+
|
75
|
+
$el.find(".godmin-upload-preview").attr(
|
76
|
+
"src", $urlParts[0] + "/fill/150/150/" + $urlParts[1] + "/foobar"
|
77
|
+
);
|
78
|
+
};
|
79
|
+
|
80
|
+
var setDownloadUrl = function($el) {
|
81
|
+
var $urlParts = getFileUrlParts($el);
|
82
|
+
|
83
|
+
$el.find(".godmin-upload-download-link").attr(
|
84
|
+
"href", $urlParts[0] + "/" + $urlParts[1] + "/foobar"
|
85
|
+
);
|
86
|
+
};
|
87
|
+
|
88
|
+
var getFileUrlParts = function($el) {
|
89
|
+
var $file = $el.find(".godmin-upload-file-field");
|
90
|
+
|
91
|
+
return [
|
92
|
+
$file.data("url"), $file.prev().val()
|
93
|
+
];
|
94
|
+
};
|
95
|
+
|
96
|
+
$(function() {
|
97
|
+
initialize();
|
98
|
+
});
|
99
|
+
|
100
|
+
})();
|
@@ -0,0 +1,33 @@
|
|
1
|
+
<div class="godmin-upload media">
|
2
|
+
<% if preview %>
|
3
|
+
<div class="media-left">
|
4
|
+
<%= attachment_image_tag(
|
5
|
+
@resource, attachment, :fill, 100, 100, fallback: "http://placehold.it/100/f5f5f5/cccccc", size: "100", class: "godmin-upload-preview"
|
6
|
+
) %>
|
7
|
+
</div>
|
8
|
+
<% end %>
|
9
|
+
<div class="media-body">
|
10
|
+
<%= f.label attachment do %>
|
11
|
+
<span class="btn btn-default godmin-upload-upload-link">
|
12
|
+
<i class="glyphicon glyphicon-arrow-up"></i>
|
13
|
+
<span>Upload file</span>
|
14
|
+
</span>
|
15
|
+
<% end %>
|
16
|
+
<%= f.attachment_field attachment, direct: true, class: "godmin-upload-file-field" %>
|
17
|
+
<%= f.hidden_field "remove_#{attachment}", class: "godmin-upload-destroy-field" %>
|
18
|
+
<span class="godmin-upload-buttons <%= "hidden" unless f.object.send(attachment) %>">
|
19
|
+
<%= link_to attachment_url(f.object, attachment), class: "btn btn-default godmin-upload-download-link" do %>
|
20
|
+
<i class="glyphicon glyphicon-arrow-down"></i>
|
21
|
+
<span>Download file</span>
|
22
|
+
<% end %>
|
23
|
+
<%= link_to "#", class: "btn btn-danger godmin-upload-destroy-link" do %>
|
24
|
+
<i class="glyphicon glyphicon-remove"></i>
|
25
|
+
<span>Destroy file</span>
|
26
|
+
<% end %>
|
27
|
+
</span>
|
28
|
+
<div class="godmin-upload-progress progress">
|
29
|
+
<div class="progress-bar progress-bar-striped active" style="width: 0%;">
|
30
|
+
</div>
|
31
|
+
</div>
|
32
|
+
</div>
|
33
|
+
</div>
|
@@ -0,0 +1,28 @@
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
|
3
|
+
# Maintain your gem's version:
|
4
|
+
require "godmin/uploads/version"
|
5
|
+
|
6
|
+
# Describe your gem and declare its dependencies:
|
7
|
+
Gem::Specification.new do |gem|
|
8
|
+
gem.name = "godmin-uploads"
|
9
|
+
gem.version = Godmin::Uploads::VERSION
|
10
|
+
gem.authors = ["Jens Ljungblad", "Varvet"]
|
11
|
+
gem.email = ["info@varvet.se"]
|
12
|
+
gem.homepage = "https://github.com/varvet/godmin-uploads"
|
13
|
+
gem.summary = "File uploads for the Godmin admin engine for Rails 4+"
|
14
|
+
gem.description = "File uploads for the Godmin admin engine for Rails 4+"
|
15
|
+
gem.license = "MIT"
|
16
|
+
|
17
|
+
gem.files = `git ls-files -z`.split("\x0")
|
18
|
+
gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
20
|
+
gem.require_paths = ["lib"]
|
21
|
+
|
22
|
+
gem.add_dependency "godmin", "~> 0.9.5"
|
23
|
+
gem.add_dependency "refile", "~> 0.3.0"
|
24
|
+
gem.add_dependency "mini_magick", "~> 4.0.1"
|
25
|
+
|
26
|
+
gem.add_development_dependency "bundler", "~> 1.7"
|
27
|
+
gem.add_development_dependency "rake", "~> 10.0"
|
28
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Godmin
|
2
|
+
module Uploads
|
3
|
+
module Helper
|
4
|
+
def uploader(attachment, preview: false)
|
5
|
+
@template.render partial: "godmin/uploads/uploader", locals: {
|
6
|
+
f: self, attachment: attachment, preview: preview
|
7
|
+
}
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
[FormBuilders::FormBuilder, FormBuilders::SimpleFormBuilder].each do |form_builder|
|
13
|
+
form_builder.send(:include, Uploads::Helper)
|
14
|
+
end
|
15
|
+
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/test/dummy/Rakefile
ADDED
File without changes
|
@@ -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,15 @@
|
|
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 bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any styles
|
10
|
+
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
11
|
+
* file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
File without changes
|