s3_cors_fileupload 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.1.5
2
+
3
+ - Added option to select 'haml' as the language template for the view files on the install generator.
4
+ - Fixed `S3CorsFileupload::Config` YAML initializer so that it properly reads in ERB statements.
5
+
1
6
  ## 0.1.4
2
7
 
3
8
  - Added a `data-confirmation` option to the delete buttons and functionality to the jQuery-File-Upload UI's destroy callback that picks up the contents of that attribute to use as a confirmation dialog. (Fixed the implementation from v0.1.3) [See the README notes for more details](https://github.com/fullbridge-batkins/s3_cors_fileupload#notes).
data/Gemfile CHANGED
@@ -1,14 +1,19 @@
1
1
  source :rubygems
2
2
 
3
+ # Bundler will treat runtime dependencies like base dependencies, and
4
+ # development dependencies will be added by default to the :development group.
5
+ gemspec
6
+
3
7
  # Add dependencies to develop your gem here.
4
8
  # Include everything needed to run rake, tests, features, etc.
5
9
  group :development do
6
- gem 'bundler'
7
10
  gem 'rdoc', '~> 3.12'
8
11
  gem 'gem-release', '~> 0.4'
9
12
  end
10
13
 
11
14
  group :test do
12
- gem 'rspec', '~> 2.11'
15
+ gem 'rails'
16
+ gem 'sqlite3' # the database driver for rails
17
+ gem 'rspec-rails', '~> 2.11'
13
18
  gem 'shoulda-matchers'
14
19
  end
data/Gemfile.lock CHANGED
@@ -1,14 +1,87 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ s3_cors_fileupload (0.1.4)
5
+ aws-s3 (~> 0.6)
6
+ jquery-rails (>= 2.0)
7
+ rails (~> 3.1)
8
+
1
9
  GEM
2
10
  remote: http://rubygems.org/
3
11
  specs:
12
+ actionmailer (3.2.8)
13
+ actionpack (= 3.2.8)
14
+ mail (~> 2.4.4)
15
+ actionpack (3.2.8)
16
+ activemodel (= 3.2.8)
17
+ activesupport (= 3.2.8)
18
+ builder (~> 3.0.0)
19
+ erubis (~> 2.7.0)
20
+ journey (~> 1.0.4)
21
+ rack (~> 1.4.0)
22
+ rack-cache (~> 1.2)
23
+ rack-test (~> 0.6.1)
24
+ sprockets (~> 2.1.3)
25
+ activemodel (3.2.8)
26
+ activesupport (= 3.2.8)
27
+ builder (~> 3.0.0)
28
+ activerecord (3.2.8)
29
+ activemodel (= 3.2.8)
30
+ activesupport (= 3.2.8)
31
+ arel (~> 3.0.2)
32
+ tzinfo (~> 0.3.29)
33
+ activeresource (3.2.8)
34
+ activemodel (= 3.2.8)
35
+ activesupport (= 3.2.8)
4
36
  activesupport (3.2.8)
5
37
  i18n (~> 0.6)
6
38
  multi_json (~> 1.0)
39
+ arel (3.0.2)
40
+ aws-s3 (0.6.3)
41
+ builder
42
+ mime-types
43
+ xml-simple
44
+ builder (3.0.4)
7
45
  diff-lcs (1.1.3)
46
+ erubis (2.7.0)
8
47
  gem-release (0.4.1)
48
+ hike (1.2.1)
9
49
  i18n (0.6.1)
50
+ journey (1.0.4)
51
+ jquery-rails (2.1.3)
52
+ railties (>= 3.1.0, < 5.0)
53
+ thor (~> 0.14)
10
54
  json (1.7.5)
55
+ mail (2.4.4)
56
+ i18n (>= 0.4.0)
57
+ mime-types (~> 1.16)
58
+ treetop (~> 1.4.8)
59
+ mime-types (1.19)
11
60
  multi_json (1.3.6)
61
+ polyglot (0.3.3)
62
+ rack (1.4.1)
63
+ rack-cache (1.2)
64
+ rack (>= 0.4)
65
+ rack-ssl (1.3.2)
66
+ rack
67
+ rack-test (0.6.2)
68
+ rack (>= 1.0)
69
+ rails (3.2.8)
70
+ actionmailer (= 3.2.8)
71
+ actionpack (= 3.2.8)
72
+ activerecord (= 3.2.8)
73
+ activeresource (= 3.2.8)
74
+ activesupport (= 3.2.8)
75
+ bundler (~> 1.0)
76
+ railties (= 3.2.8)
77
+ railties (3.2.8)
78
+ actionpack (= 3.2.8)
79
+ activesupport (= 3.2.8)
80
+ rack-ssl (~> 1.3.2)
81
+ rake (>= 0.8.7)
82
+ rdoc (~> 3.4)
83
+ thor (>= 0.14.6, < 2.0)
84
+ rake (0.9.2.2)
12
85
  rdoc (3.12)
13
86
  json (~> 1.4)
14
87
  rspec (2.11.0)
@@ -19,8 +92,25 @@ GEM
19
92
  rspec-expectations (2.11.3)
20
93
  diff-lcs (~> 1.1.3)
21
94
  rspec-mocks (2.11.3)
95
+ rspec-rails (2.11.4)
96
+ actionpack (>= 3.0)
97
+ activesupport (>= 3.0)
98
+ railties (>= 3.0)
99
+ rspec (~> 2.11.0)
22
100
  shoulda-matchers (1.4.1)
23
101
  activesupport (>= 3.0.0)
102
+ sprockets (2.1.3)
103
+ hike (~> 1.2)
104
+ rack (~> 1.0)
105
+ tilt (~> 1.1, != 1.3.0)
106
+ sqlite3 (1.3.6)
107
+ thor (0.16.0)
108
+ tilt (1.3.3)
109
+ treetop (1.4.12)
110
+ polyglot
111
+ polyglot (>= 0.3.1)
112
+ tzinfo (0.3.34)
113
+ xml-simple (1.1.2)
24
114
 
25
115
  PLATFORMS
26
116
  ruby
@@ -28,6 +118,10 @@ PLATFORMS
28
118
  DEPENDENCIES
29
119
  bundler
30
120
  gem-release (~> 0.4)
121
+ rails
122
+ rake (>= 0.8.7)
31
123
  rdoc (~> 3.12)
32
- rspec (~> 2.11)
124
+ rspec-rails (~> 2.11)
125
+ s3_cors_fileupload!
33
126
  shoulda-matchers
127
+ sqlite3
data/README.md CHANGED
@@ -16,10 +16,14 @@ and views for the file uploading.
16
16
 
17
17
  bundle exec rails generate s3_cors_fileupload:install
18
18
 
19
+ If you are using HAML as the template language for your app, you can make the install generator produce HAML view files:
20
+
21
+ bundle exec rails g s3_cors_fileupload:install --template-language=haml
22
+
19
23
  If you don't want to generate a migration (for instance if you've already run the install generator in the past),
20
- you can pass in an options `--skip-migration` like so:
24
+ you can pass in `--skip-migration` like so:
21
25
 
22
- bundle exec rails generate s3_cors_fileupload:install --skip-migration
26
+ bundle exec rails g s3_cors_fileupload:install --skip-migration
23
27
 
24
28
  If you chose to generate a migration, run it now:
25
29
 
@@ -27,7 +31,7 @@ If you chose to generate a migration, run it now:
27
31
 
28
32
  Also, as you may have noticed, a config file was generated at `config/amazon_s3.yml`. Edit this file and fill in
29
33
  the fields with your AWS S3 credentials. If you don't want to commit your S3 account credentials to your
30
- repository, you can make the config load from environment variables like so:
34
+ repository, you can make the config file load from environment variables like so (this functionality is fixed as of version `0.1.5`):
31
35
 
32
36
  secret_access_key: <%= ENV['S3_SECRET_ACCESS_KEY'] %>
33
37
 
data/Rakefile CHANGED
@@ -1,7 +1,11 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  require 'rubygems'
4
- require 'bundler'
4
+ # begin
5
+ # require 'bundler/setup'
6
+ # rescue LoadError
7
+ # puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
8
+ # end
5
9
  Bundler::GemHelper.install_tasks
6
10
 
7
11
  require 'rspec/core/rake_task'
@@ -26,12 +30,14 @@ Rake::RDocTask.new do |rdoc|
26
30
  version = S3CorsFileupload::VERSION
27
31
 
28
32
  rdoc.rdoc_dir = 'rdoc'
29
- rdoc.title = "s3_cors_fileupload #{version}"
33
+ rdoc.title = "S3CorsFileupload #{version}"
34
+ rdoc.rdoc_files.include('LICENSE*')
30
35
  rdoc.rdoc_files.include('README*')
36
+ rdoc.rdoc_files.include('CHANGELOG*')
31
37
  rdoc.rdoc_files.include('lib/**/*.rb')
32
38
  end
33
39
 
34
- desc "Open an irb session preloaded with this library"
40
+ desc 'Open an irb session preloaded with this library'
35
41
  task :console do
36
- sh "irb -I lib -r s3_cors_fileupload.rb"
42
+ sh 'irb -I lib -r s3_cors_fileupload.rb'
37
43
  end
@@ -8,8 +8,11 @@ module S3CorsFileupload
8
8
  include ::Rails::Generators::Migration
9
9
  extend ActiveRecord::Generators::Migration
10
10
 
11
+ VALID_TEMPLATE_LANGS = [:erb, :haml]
12
+
11
13
  source_root File.expand_path('../templates', __FILE__)
12
14
  class_option :migration, :type => :boolean, :default => true, :desc => "Generate a migration for the SourceFile model."
15
+ class_option :template_language, :type => :string, :default => 'erb', :desc => "Specify a template language to use for view files, must be one of: [erb, haml]"
13
16
 
14
17
  desc('Creates a config file, then generates (but does not run) a migration to add a source_files table and ' +
15
18
  'a corresponding model, as well as a controller, routes, and views for the file uploading.')
@@ -32,8 +35,10 @@ module S3CorsFileupload
32
35
  end
33
36
 
34
37
  def create_views
35
- Dir.foreach(File.expand_path('../templates/views', __FILE__)).reject { |file_name| %w(. ..).include?(file_name) }.each do |file_name|
36
- copy_file "views/#{file_name}", "app/views/s3_uploads/#{file_name}"
38
+ template_language = options.template_language if VALID_TEMPLATE_LANGS.include?(options.template_language.to_sym)
39
+ template_language ||= 'erb'
40
+ Dir.foreach(File.expand_path("../templates/views/#{template_language}", __FILE__)).reject { |file_name| %w(. ..).include?(file_name) }.each do |file_name|
41
+ copy_file "views/#{template_language}/#{file_name}", "app/views/s3_uploads/#{file_name}"
37
42
  end
38
43
  end
39
44
 
@@ -0,0 +1,32 @@
1
+ / To be used with Javascript-Templates (see: https://github.com/blueimp/JavaScript-Templates)
2
+ / The template to display files available for download (the stock one from the jquery-fileupload script)
3
+ %script#template-download{:type => "text/x-tmpl"}
4
+ {% for (var i=0, file; file=o.files[i]; i++) { %}
5
+ %tr.template-download.fade
6
+ {% if (file.error) { %}
7
+ %td
8
+ %td.name
9
+ %span {%=file.name%}
10
+ %td.size
11
+ %span {%=o.formatFileSize(file.size)%}
12
+ %td.error{:colspan => "2"}
13
+ %span.label.label-important {%=locale.fileupload.error%}
14
+ {%=locale.fileupload.errors[file.error] || file.error%}
15
+ {% } else { %}
16
+ %td.preview
17
+ {% if (file.thumbnail_url) { %}
18
+ %a{:download => "{%=file.name%}", :href => "{%=file.url%}", :rel => "gallery", :title => "{%=file.name%}"}
19
+ %img{:src => "{%=file.thumbnail_url%}"}/
20
+ {% } %}
21
+ %td.name
22
+ %a{:download => "{%=file.name%}", :href => "{%=file.url%}", :rel => "{%=file.thumbnail_url&&'gallery'%}", :title => "{%=file.name%}"} {%=file.name%}
23
+ %td.size
24
+ %span {%=$('#fileupload').formatFileSize(file.size)%}
25
+ %td{:colspan => "2"}
26
+ {% } %}
27
+ %td.delete
28
+ %button.btn.btn-danger{"data-type" => "{%=file.delete_type%}", "data-url" => "{%=file.delete_url%}", "data-confirmation" => "Are you sure?"}
29
+ %i.icon-trash.icon-white
30
+ %span Delete
31
+ %input{:name => "delete", :type => "checkbox", :value => "1"}
32
+ {% } %}
@@ -0,0 +1,35 @@
1
+ / To be used with Javascript-Templates (see: https://github.com/blueimp/JavaScript-Templates)
2
+ / The template to display files available for upload
3
+ %script#template-upload{:type => "text/x-tmpl"}
4
+ {% for (var i=0, file; file=o.files[i]; i++) { %}
5
+ %tr.template-upload.fade
6
+ %td.preview
7
+ %span.fade
8
+ %td.name
9
+ %span {%=file.name%}
10
+ %td.size
11
+ %span {%=o.formatFileSize(file.size)%}
12
+ {% if (file.error) { %}
13
+ %td.error{:colspan => "2"}
14
+ %span.label.label-important Error
15
+ {%=file.error%}
16
+ {% } else if (o.files.valid && !i) { %}
17
+ %td
18
+ .progress.progress-success.progress-striped.active
19
+ .bar{:style => "width:0%;"}
20
+ %td.start
21
+ {% if (!o.options.autoUpload) { %}
22
+ %button.btn.btn-primary
23
+ %i.icon-upload.icon-white
24
+ %span Start
25
+ {% } %}
26
+ {% } else { %}
27
+ %td{:colspan => "2"}
28
+ {% } %}
29
+ %td.cancel
30
+ {% if (!i) { %}
31
+ %button.btn.btn-warning
32
+ %i.icon-ban-circle.icon-white
33
+ %span Cancel
34
+ {% } %}
35
+ {% } %}
@@ -0,0 +1,21 @@
1
+ / To be used with Javascript-Templates (see: https://github.com/blueimp/JavaScript-Templates)
2
+ / The template to display files that have been uploaded to S3 already
3
+ %script#template-uploaded{:type => "text/x-tmpl"}
4
+ %tr.template-uploaded{:id => "source_file_{%=o.id%}"}
5
+ {% if (o.image == true) { %}
6
+ %td.preview
7
+ %a{:download => "{%=o.name%}", :href => "{%=o.url%}", :rel => "gallery", :title => "{%=o.name%}"}
8
+ %img{:src => "{%=o.url%}", :style => 'width:80px; height:56px;'}
9
+ {% } else { %}
10
+ %td
11
+ {% } %}
12
+ %td.name
13
+ %a{:download => "{%=o.name%}", :href => "{%=o.url%}", :rel => "{%=o.thumbnail_url&&'gallery'%}".html_safe, :title => "{%=o.name%}"} {%=o.name%}
14
+ %td.size
15
+ %span {%=formatFileSize(o.size)%}
16
+ %td{:colspan => "2"}
17
+ %td.delete
18
+ %button.btn.btn-danger{"data-type" => "DELETE", "data-url" => "{%=o.delete_url%}", "data-confirmation" => "Are you sure?"}
19
+ %i.icon-trash.icon-white
20
+ %span Delete
21
+ %input{:name => "delete", :type => "checkbox", :value => "1"}
@@ -0,0 +1,38 @@
1
+ = stylesheet_link_tag '//netdna.bootstrapcdn.com/twitter-bootstrap/2.1.1/css/bootstrap-combined.min.css'
2
+
3
+ %div{:style => 'padding: 10px;'}
4
+ %h2 Upload file
5
+ = s3_cors_fileupload_form_tag :id => 'fileupload'
6
+
7
+ .javascript-templates
8
+ = render 'template_upload'
9
+ = render 'template_uploaded'
10
+ =# render 'template_download'
11
+
12
+ :javascript
13
+ $(function () {
14
+ // Initialize the jQuery File Upload widget:
15
+ $('#fileupload').fileupload({
16
+ dataType: 'xml',
17
+ sequentialUploads: true,
18
+ downloadTemplateId: null,
19
+ downloadTemplate: null
20
+ });
21
+
22
+ // Load existing files:
23
+ $.getJSON('/source_files', function (files) {
24
+ $.each(files, function(index, value) {
25
+ $('#upload_files tbody').append(tmpl('template-uploaded', value));
26
+ });
27
+ });
28
+ });
29
+
30
+ // used by the jQuery File Upload
31
+ var fileUploadErrors = {
32
+ maxFileSize: 'File is too big',
33
+ minFileSize: 'File is too small',
34
+ acceptFileTypes: 'Filetype not allowed',
35
+ maxNumberOfFiles: 'Max number of files exceeded',
36
+ uploadedBytes: 'Uploaded bytes exceed file size',
37
+ emptyResult: 'Empty file upload result'
38
+ };
@@ -17,7 +17,7 @@ module S3CorsFileupload
17
17
  private
18
18
 
19
19
  def config
20
- @config ||= YAML.load_file(File.join(::Rails.root, 'config', 'amazon_s3.yml'))[::Rails.env]
20
+ @config ||= YAML.load(ERB.new(File.read(File.join(::Rails.root, 'config', 'amazon_s3.yml'))).result)[::Rails.env]
21
21
  rescue
22
22
  warn('WARNING: s3_cors_fileupload gem was unable to locate a configuration file in config/amazon_s3.yml and may not ' +
23
23
  'be able to function properly. Please run `rails generate s3_cors_upload:install` before proceeding.')
@@ -1,5 +1,5 @@
1
1
  module S3CorsFileupload
2
- VERSION = '0.1.4'
2
+ VERSION = '0.1.5'
3
3
  JQUERY_FILEUPLOAD_VERSION = '5.19'
4
4
  JQUERY_FILEUPLOAD_UI_VERSION = '6.10'
5
5
  end
@@ -22,12 +22,14 @@ Gem::Specification.new do |s|
22
22
  s.add_development_dependency('rake', [">= 0.8.7"])
23
23
  s.add_development_dependency('bundler', [">= 0"])
24
24
 
25
+
25
26
  s.files = `git ls-files`.split("\n")
26
27
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
27
28
  s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
28
29
  s.require_paths = ['lib']
29
30
  s.extra_rdoc_files = [
30
31
  "LICENSE.txt",
31
- "README.md"
32
+ "README.md",
33
+ "CHANGELOG.md"
32
34
  ]
33
35
  end
data/spec/spec_helper.rb CHANGED
@@ -1,12 +1,36 @@
1
- require 'rubygems'
2
- require 'bundler/setup'
3
-
4
- require File.expand_path('../../lib/s3_cors_fileupload', __FILE__)
1
+ ENV["RAILS_ENV"] ||= 'test'
2
+ require File.expand_path('../dummy/config/environment', __FILE__)
3
+ require 'rspec/rails'
4
+ require 'rspec/autorun'
5
5
 
6
+ # Requires supporting ruby files with custom matchers and macros, etc,
7
+ # in spec/support/ and its subdirectories.
8
+ Dir[::Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
6
9
 
7
10
  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
8
11
  RSpec.configure do |config|
9
12
  config.treat_symbols_as_metadata_keys_with_true_values = true
13
+
14
+ # ## Mock Framework
15
+ #
16
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
17
+ #
18
+ # config.mock_with :mocha
19
+ # config.mock_with :flexmock
20
+ # config.mock_with :rr
21
+
22
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
23
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
24
+
25
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
26
+ # examples within a transaction, remove the following line or assign false
27
+ # instead of true.
28
+ config.use_transactional_fixtures = true
29
+
30
+ # If true, the base class of anonymous controllers will be inferred
31
+ # automatically. This will be the default behavior in future versions of
32
+ # rspec-rails.
33
+ config.infer_base_class_for_anonymous_controllers = false
10
34
 
11
35
  # Run specs in random order to surface order dependencies. If you find an
12
36
  # order dependency and want to debug it, you can fix the order by providing
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: s3_cors_fileupload
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
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-10-31 00:00:00.000000000 Z
12
+ date: 2012-11-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -100,6 +100,7 @@ extensions: []
100
100
  extra_rdoc_files:
101
101
  - LICENSE.txt
102
102
  - README.md
103
+ - CHANGELOG.md
103
104
  files:
104
105
  - .document
105
106
  - .gitignore
@@ -117,10 +118,14 @@ files:
117
118
  - lib/generators/s3_cors_fileupload/install/templates/s3_uploads.js
118
119
  - lib/generators/s3_cors_fileupload/install/templates/s3_uploads_controller.rb
119
120
  - lib/generators/s3_cors_fileupload/install/templates/source_file.rb
120
- - lib/generators/s3_cors_fileupload/install/templates/views/_template_download.html.erb
121
- - lib/generators/s3_cors_fileupload/install/templates/views/_template_upload.html.erb
122
- - lib/generators/s3_cors_fileupload/install/templates/views/_template_uploaded.html.erb
123
- - lib/generators/s3_cors_fileupload/install/templates/views/index.html.erb
121
+ - lib/generators/s3_cors_fileupload/install/templates/views/erb/_template_download.html.erb
122
+ - lib/generators/s3_cors_fileupload/install/templates/views/erb/_template_upload.html.erb
123
+ - lib/generators/s3_cors_fileupload/install/templates/views/erb/_template_uploaded.html.erb
124
+ - lib/generators/s3_cors_fileupload/install/templates/views/erb/index.html.erb
125
+ - lib/generators/s3_cors_fileupload/install/templates/views/haml/_template_download.html.haml
126
+ - lib/generators/s3_cors_fileupload/install/templates/views/haml/_template_upload.html.haml
127
+ - lib/generators/s3_cors_fileupload/install/templates/views/haml/_template_uploaded.html.haml
128
+ - lib/generators/s3_cors_fileupload/install/templates/views/haml/index.html.haml
124
129
  - lib/s3_cors_fileupload.rb
125
130
  - lib/s3_cors_fileupload/rails.rb
126
131
  - lib/s3_cors_fileupload/rails/config.rb