browse-everything 0.10.5 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +16 -0
- data/.rubocop_todo.yml +149 -0
- data/.travis.yml +5 -6
- data/Rakefile +2 -2
- data/app/controllers/browse_everything_controller.rb +19 -22
- data/app/helpers/bootstrap_version_helper.rb +9 -11
- data/app/helpers/browse_everything_helper.rb +11 -22
- data/app/views/browse_everything/_file.html.erb +7 -11
- data/app/views/browse_everything/_files.html.erb +4 -7
- data/app/views/browse_everything/index.html.erb +1 -1
- data/browse-everything.gemspec +37 -34
- data/config/routes.rb +3 -3
- data/lib/browse-everything.rb +1 -1
- data/lib/browse_everything.rb +9 -8
- data/lib/browse_everything/browser.rb +4 -4
- data/lib/browse_everything/driver/base.rb +14 -14
- data/lib/browse_everything/driver/box.rb +48 -59
- data/lib/browse_everything/driver/dropbox.rb +10 -11
- data/lib/browse_everything/driver/file_system.rb +19 -24
- data/lib/browse_everything/driver/google_drive.rb +58 -82
- data/lib/browse_everything/driver/s3.rb +87 -0
- data/lib/browse_everything/driver/sky_drive.rb +41 -47
- data/lib/browse_everything/engine.rb +2 -2
- data/lib/browse_everything/file_entry.rb +3 -3
- data/lib/browse_everything/retriever.rb +19 -20
- data/lib/browse_everything/version.rb +1 -1
- data/lib/generators/browse_everything/assets_generator.rb +2 -4
- data/lib/generators/browse_everything/config_generator.rb +12 -12
- data/lib/generators/browse_everything/install_generator.rb +2 -4
- data/lib/generators/browse_everything/templates/browse_everything_providers.yml.example +6 -0
- data/spec/features/select_files_spec.rb +12 -12
- data/spec/features/test_compiling_stylesheets_spec.rb +2 -2
- data/spec/helper/browse_everything_controller_helper_spec.rb +8 -8
- data/spec/javascripts/jasmine_spec.rb +5 -5
- data/spec/javascripts/support/jasmine_helper.rb +9 -9
- data/spec/spec_helper.rb +26 -23
- data/spec/support/app/controllers/file_handler_controller.rb +3 -3
- data/spec/support/rake.rb +1 -1
- data/spec/test_app_templates/lib/generators/test_app_generator.rb +21 -22
- data/spec/unit/base_spec.rb +6 -6
- data/spec/unit/browse_everything_helper_spec.rb +9 -9
- data/spec/unit/browser_spec.rb +19 -19
- data/spec/unit/dropbox_spec.rb +44 -43
- data/spec/unit/file_entry_spec.rb +31 -31
- data/spec/unit/file_system_spec.rb +26 -26
- data/spec/unit/retriever_spec.rb +42 -43
- data/spec/unit/s3_spec.rb +77 -0
- data/spec/unit/sky_drive_spec.rb +31 -31
- data/spec/views/browse_everything/_file.html.erb_spec.rb +37 -37
- data/tasks/ci.rake +3 -3
- metadata +52 -7
- data/app/.DS_Store +0 -0
- data/app/views/.DS_Store +0 -0
@@ -2,7 +2,7 @@ module BrowseEverything
|
|
2
2
|
class Engine < ::Rails::Engine
|
3
3
|
config.assets.paths << config.root.join('vendor', 'assets', 'javascripts')
|
4
4
|
config.assets.paths << config.root.join('vendor', 'assets', 'stylesheets')
|
5
|
-
config.assets.precompile += %w
|
6
|
-
config.assets.precompile += %w
|
5
|
+
config.assets.precompile += %w(browse_everything.js)
|
6
|
+
config.assets.precompile += %w(browse_everything.css)
|
7
7
|
end
|
8
8
|
end
|
@@ -2,20 +2,20 @@ module BrowseEverything
|
|
2
2
|
class FileEntry
|
3
3
|
attr_reader :id, :location, :name, :size, :mtime, :type
|
4
4
|
|
5
|
-
def initialize(id, location, name, size, mtime, container, type=nil)
|
5
|
+
def initialize(id, location, name, size, mtime, container, type = nil)
|
6
6
|
@id = id
|
7
7
|
@location = location
|
8
8
|
@name = name
|
9
9
|
@size = size
|
10
10
|
@mtime = mtime
|
11
11
|
@container = container
|
12
|
-
@type = type || @container ? 'application/x-directory' : Rack::Mime.mime_type(File.extname(name))
|
12
|
+
@type = type || (@container ? 'application/x-directory' : Rack::Mime.mime_type(File.extname(name)))
|
13
13
|
end
|
14
14
|
|
15
15
|
def relative_parent_path?
|
16
16
|
name =~ /^\.\.?$/ ? true : false
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
def container?
|
20
20
|
@container
|
21
21
|
end
|
@@ -4,38 +4,38 @@ require 'tempfile'
|
|
4
4
|
module BrowseEverything
|
5
5
|
class Retriever
|
6
6
|
attr_accessor :chunk_size
|
7
|
-
|
7
|
+
|
8
8
|
def initialize
|
9
9
|
@chunk_size = 16384
|
10
10
|
end
|
11
|
-
|
12
|
-
def download(spec, target=nil)
|
11
|
+
|
12
|
+
def download(spec, target = nil)
|
13
13
|
if target.nil?
|
14
14
|
ext = File.extname(spec['file_name'])
|
15
|
-
base = File.basename(spec['file_name'],ext)
|
16
|
-
target = Dir::Tmpname.create([base,ext]) {}
|
15
|
+
base = File.basename(spec['file_name'], ext)
|
16
|
+
target = Dir::Tmpname.create([base, ext]) {}
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
File.open(target, 'wb') do |output|
|
20
|
-
|
21
|
-
output.write(chunk)
|
20
|
+
retrieve(spec) do |chunk, retrieved, total|
|
21
|
+
output.write(chunk)
|
22
22
|
yield(target, retrieved, total) if block_given?
|
23
23
|
end
|
24
24
|
end
|
25
|
-
|
25
|
+
target
|
26
26
|
end
|
27
|
-
|
28
|
-
def retrieve(spec
|
29
|
-
if spec.
|
27
|
+
|
28
|
+
def retrieve(spec)
|
29
|
+
if spec.key?('expires') && Time.parse(spec['expires']) < Time.now
|
30
30
|
raise ArgumentError, "Download spec expired at #{spec['expires']}"
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
url = Addressable::URI.parse(spec['url'])
|
34
34
|
retrieved = 0
|
35
35
|
case url.scheme
|
36
36
|
when 'file'
|
37
|
-
File.open(url.path,'rb') do |f|
|
38
|
-
|
37
|
+
File.open(url.path, 'rb') do |f|
|
38
|
+
until f.eof?
|
39
39
|
chunk = f.read(chunk_size)
|
40
40
|
retrieved += chunk.length
|
41
41
|
yield(chunk, retrieved, spec['file_size'].to_i)
|
@@ -43,11 +43,11 @@ module BrowseEverything
|
|
43
43
|
end
|
44
44
|
when /https?/
|
45
45
|
headers = spec['auth_header'] || {}
|
46
|
-
headers.each_pair do |k,v|
|
47
|
-
headers[k] = v.
|
46
|
+
headers.each_pair do |k, v|
|
47
|
+
headers[k] = v.tr('+', ' ')
|
48
48
|
end
|
49
|
-
|
50
|
-
HTTParty.get(url.to_s, headers: headers) do |chunk|
|
49
|
+
|
50
|
+
HTTParty.get(url.to_s, headers: headers) do |chunk|
|
51
51
|
retrieved += chunk.length
|
52
52
|
yield(chunk, retrieved, spec['file_size'].to_i)
|
53
53
|
end
|
@@ -55,6 +55,5 @@ module BrowseEverything
|
|
55
55
|
raise URI::BadURIError, "Unknown URI scheme: #{uri.scheme}"
|
56
56
|
end
|
57
57
|
end
|
58
|
-
|
59
58
|
end
|
60
59
|
end
|
@@ -2,13 +2,11 @@
|
|
2
2
|
require 'rails/generators'
|
3
3
|
|
4
4
|
class BrowseEverything::AssetsGenerator < Rails::Generators::Base
|
5
|
-
desc
|
6
|
-
This generator installs the browse_everything CSS assets into your application
|
7
|
-
"""
|
5
|
+
desc 'This generator installs the browse_everything CSS assets into your application'
|
8
6
|
|
9
7
|
source_root File.expand_path('../templates', __FILE__)
|
10
8
|
|
11
9
|
def inject_css
|
12
|
-
copy_file
|
10
|
+
copy_file 'browse_everything.scss', 'app/assets/stylesheets/browse_everything.scss'
|
13
11
|
end
|
14
12
|
end
|
@@ -2,27 +2,27 @@
|
|
2
2
|
require 'rails/generators'
|
3
3
|
|
4
4
|
class BrowseEverything::ConfigGenerator < Rails::Generators::Base
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
desc <<-END_OF_DESC
|
6
|
+
This generator makes the following changes to your application:
|
7
|
+
1. Creates config/browse_everything_providers.yml with a placeholder value
|
8
|
+
2. Modifies your app's routes.rb to mount BrowseEverything at /browse
|
9
|
+
END_OF_DESC
|
10
10
|
source_root File.expand_path('../templates', __FILE__)
|
11
11
|
|
12
12
|
def inject_routes
|
13
|
-
|
14
|
-
%
|
15
|
-
|
16
|
-
|
13
|
+
insert_into_file 'config/routes.rb', after: '.draw do' do
|
14
|
+
%(
|
15
|
+
mount BrowseEverything::Engine => '/browse')
|
16
|
+
end
|
17
17
|
end
|
18
18
|
|
19
19
|
def copy_example_config
|
20
|
-
copy_file
|
20
|
+
copy_file 'browse_everything_providers.yml.example', 'config/browse_everything_providers.yml'
|
21
21
|
end
|
22
22
|
|
23
23
|
def insert_file_system_path
|
24
|
-
insert_into_file
|
25
|
-
YAML.dump(
|
24
|
+
insert_into_file 'config/browse_everything_providers.yml', before: '# dropbox:' do
|
25
|
+
YAML.dump('file_system' => { home: Rails.root.to_s })
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
@@ -2,11 +2,9 @@
|
|
2
2
|
require 'rails/generators'
|
3
3
|
|
4
4
|
class BrowseEverything::InstallGenerator < Rails::Generators::Base
|
5
|
-
class_option :'skip-assets', type: :boolean, default: false, desc:
|
5
|
+
class_option :'skip-assets', type: :boolean, default: false, desc: 'Skip generating javascript and css assets into the application'
|
6
6
|
|
7
|
-
desc
|
8
|
-
This generator installs the browse everything configuration and assets into your application
|
9
|
-
"""
|
7
|
+
desc 'This generator installs the browse everything configuration and assets into your application'
|
10
8
|
|
11
9
|
source_root File.expand_path('../templates', __FILE__)
|
12
10
|
|
@@ -11,6 +11,12 @@
|
|
11
11
|
# google_drive:
|
12
12
|
# :client_id: YOUR_GOOGLE_API_CLIENT_ID
|
13
13
|
# :client_secret: YOUR_GOOGLE_API_CLIENT_SECRET
|
14
|
+
# s3:
|
15
|
+
# :app_key: YOUR_AWS_S3_KEY
|
16
|
+
# :app_secret: YOUR_AWS_S3_SECRET
|
17
|
+
# :bucket: YOUR_AWS_S3_BUCKET
|
18
|
+
# :region: YOUR_AWS_S3_REGION # default: us-east-1
|
19
|
+
# :signed_url: true # set to false for public urls
|
14
20
|
# sky_drive:
|
15
21
|
# :client_id: YOUR_MS_LIVE_CONNECT_CLIENT_ID
|
16
22
|
# :client_secret: YOUR_MS_LIVE_CONNECT_CLIENT_SECRET
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'capybara/poltergeist'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe 'Choosing files', type: :feature do
|
4
4
|
before do
|
5
5
|
Capybara.register_driver :poltergeist do |app|
|
6
6
|
Capybara::Poltergeist::Driver.new(app, js_errors: true, timeout: 90)
|
@@ -9,27 +9,27 @@ describe "Choosing files", :type => :feature do
|
|
9
9
|
visit '/'
|
10
10
|
end
|
11
11
|
|
12
|
-
shared_examples
|
13
|
-
it
|
12
|
+
shared_examples 'browseable files' do
|
13
|
+
it 'selects files from the filesystem' do
|
14
14
|
click_button('Browse')
|
15
15
|
sleep(5)
|
16
|
-
click_link(
|
17
|
-
within(
|
18
|
-
expect(page).to have_selector(
|
19
|
-
click_button(
|
16
|
+
click_link('Gemfile.lock')
|
17
|
+
within('.modal-footer') do
|
18
|
+
expect(page).to have_selector('span', text: '1 file selected')
|
19
|
+
click_button('Submit')
|
20
20
|
end
|
21
21
|
sleep(5)
|
22
|
-
expect(page).to have_selector(
|
22
|
+
expect(page).to have_selector('#status', text: '1 items selected')
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
context
|
26
|
+
context 'when Turbolinks are enabled' do
|
27
27
|
before { click_link('Enter Test App (Turbolinks)') }
|
28
|
-
it_behaves_like
|
28
|
+
it_behaves_like 'browseable files'
|
29
29
|
end
|
30
30
|
|
31
|
-
context
|
31
|
+
context 'when Turbolinks are disabled' do
|
32
32
|
before { click_link('Enter Test App (No Turbolinks)') }
|
33
|
-
it_behaves_like
|
33
|
+
it_behaves_like 'browseable files'
|
34
34
|
end
|
35
35
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.expand_path('../../spec_helper',__FILE__)
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
2
|
|
3
3
|
include BrowserConfigHelper
|
4
4
|
|
@@ -6,7 +6,7 @@ describe BrowseEverythingController, type: :controller do
|
|
6
6
|
before(:all) { stub_configuration }
|
7
7
|
after(:all) { unstub_configuration }
|
8
8
|
|
9
|
-
let(:helper_context) {controller.view_context}
|
9
|
+
let(:helper_context) { controller.view_context }
|
10
10
|
let(:browser) { BrowseEverything::Browser.new(url_options) }
|
11
11
|
|
12
12
|
before do
|
@@ -16,9 +16,9 @@ describe BrowseEverythingController, type: :controller do
|
|
16
16
|
context 'dropbox' do
|
17
17
|
let(:provider) { browser.providers['dropbox'] }
|
18
18
|
|
19
|
-
describe
|
20
|
-
subject {helper_context.auth_link}
|
21
|
-
it
|
19
|
+
describe 'auth_link' do
|
20
|
+
subject { helper_context.auth_link }
|
21
|
+
it 'has a single state' do
|
22
22
|
expect(subject.scan(/state/).length).to eq 1
|
23
23
|
end
|
24
24
|
end
|
@@ -27,9 +27,9 @@ describe BrowseEverythingController, type: :controller do
|
|
27
27
|
context 'box' do
|
28
28
|
let(:provider) { browser.providers['box'] }
|
29
29
|
|
30
|
-
describe
|
31
|
-
subject {helper_context.auth_link}
|
32
|
-
it
|
30
|
+
describe 'auth_link' do
|
31
|
+
subject { helper_context.auth_link }
|
32
|
+
it 'has a single state' do
|
33
33
|
expect(subject.scan(/state/).length).to eq 1
|
34
34
|
end
|
35
35
|
end
|
@@ -2,15 +2,15 @@ require 'rake'
|
|
2
2
|
|
3
3
|
# Run the jasmine tests by running the jasmine:ci rake command and parses the output for failures.
|
4
4
|
# The spec will fail if any jasmine tests fails.
|
5
|
-
describe
|
6
|
-
it
|
5
|
+
describe 'Jasmine' do
|
6
|
+
it 'expects all jasmine tests to pass' do
|
7
7
|
load_rake_environment ["#{jasmine_path}/lib/jasmine/tasks/jasmine.rake"]
|
8
8
|
jasmine_out = run_task 'jasmine:ci'
|
9
|
-
unless jasmine_out.include?
|
10
|
-
puts
|
9
|
+
unless jasmine_out.include? '0 failures'
|
10
|
+
puts 'Some of the Jasmine tests failed'
|
11
11
|
puts jasmine_out
|
12
12
|
end
|
13
|
-
expect(jasmine_out).to include
|
13
|
+
expect(jasmine_out).to include '0 failures'
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
@@ -1,15 +1,15 @@
|
|
1
|
-
#Use this file to set/override Jasmine configuration options
|
2
|
-
#You can remove it if you don't need it.
|
3
|
-
#This file is loaded *after* jasmine.yml is interpreted.
|
1
|
+
# Use this file to set/override Jasmine configuration options
|
2
|
+
# You can remove it if you don't need it.
|
3
|
+
# This file is loaded *after* jasmine.yml is interpreted.
|
4
4
|
#
|
5
|
-
#Example: using a different boot file.
|
6
|
-
#Jasmine.configure do |config|
|
5
|
+
# Example: using a different boot file.
|
6
|
+
# Jasmine.configure do |config|
|
7
7
|
# config.boot_dir = '/absolute/path/to/boot_dir'
|
8
8
|
# config.boot_files = lambda { ['/absolute/path/to/boot_dir/file.js'] }
|
9
|
-
#end
|
9
|
+
# end
|
10
10
|
#
|
11
|
-
#Example: prevent PhantomJS auto install, uses PhantomJS already on your path.
|
12
|
-
#Jasmine.configure do |config|
|
11
|
+
# Example: prevent PhantomJS auto install, uses PhantomJS already on your path.
|
12
|
+
# Jasmine.configure do |config|
|
13
13
|
# config.prevent_phantom_js_auto_install = true
|
14
|
-
#end
|
14
|
+
# end
|
15
15
|
#
|
data/spec/spec_helper.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'engine_cart'
|
2
|
-
require File.expand_path(
|
2
|
+
require File.expand_path('config/environment', EngineCart.destination)
|
3
3
|
require 'rspec'
|
4
4
|
require 'rspec/rails'
|
5
5
|
require 'rspec/its'
|
@@ -15,7 +15,7 @@ Coveralls.wear!
|
|
15
15
|
EngineCart.load_application!
|
16
16
|
|
17
17
|
SimpleCov.start do
|
18
|
-
add_filter
|
18
|
+
add_filter '/spec/'
|
19
19
|
end
|
20
20
|
|
21
21
|
VCR.configure do |c|
|
@@ -45,27 +45,30 @@ module BrowserConfigHelper
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def stub_configuration
|
48
|
-
BrowseEverything.configure({
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
48
|
+
BrowseEverything.configure('file_system' => {
|
49
|
+
home: File.expand_path('../fixtures/file_system', __FILE__)
|
50
|
+
},
|
51
|
+
'box' => {
|
52
|
+
client_id: 'BoxClientId',
|
53
|
+
client_secret: 'BoxClientSecret'
|
54
|
+
},
|
55
|
+
'dropbox' => {
|
56
|
+
app_key: 'DropboxAppKey',
|
57
|
+
app_secret: 'DropboxAppSecret'
|
58
|
+
},
|
59
|
+
'google_drive' => {
|
60
|
+
client_id: 'GoogleClientId',
|
61
|
+
client_secret: 'GoogleClientSecret'
|
62
|
+
},
|
63
|
+
'sky_drive' => {
|
64
|
+
client_id: 'SkyDriveClientId',
|
65
|
+
client_secret: 'SkyDriveClientSecret'
|
66
|
+
},
|
67
|
+
's3' => {
|
68
|
+
app_key: 'S3AppKey',
|
69
|
+
app_secret: 'S3AppSecret',
|
70
|
+
bucket: 's3.bucket'
|
71
|
+
})
|
69
72
|
end
|
70
73
|
|
71
74
|
def unstub_configuration
|
data/spec/support/rake.rb
CHANGED
@@ -1,47 +1,46 @@
|
|
1
1
|
require 'rails/generators'
|
2
2
|
|
3
3
|
class TestAppGenerator < Rails::Generators::Base
|
4
|
-
source_root File.expand_path(
|
5
|
-
|
4
|
+
source_root File.expand_path('../../../../spec/support', __FILE__)
|
5
|
+
|
6
6
|
def run_config_generator
|
7
|
-
generate
|
7
|
+
generate 'browse_everything:config'
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
def inject_css
|
11
|
-
copy_file File.expand_path(
|
12
|
-
remove_file
|
13
|
-
insert_into_file
|
14
|
-
%
|
11
|
+
copy_file File.expand_path('app/assets/stylesheets/application.css', ENV['RAILS_ROOT']), 'app/assets/stylesheets/application.css.scss'
|
12
|
+
remove_file 'app/assets/stylesheets/application.css'
|
13
|
+
insert_into_file 'app/assets/stylesheets/application.css.scss', after: '*/' do
|
14
|
+
%(\n\n@import "browse_everything")
|
15
15
|
end
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
def inject_javascript
|
19
|
-
insert_into_file
|
19
|
+
insert_into_file 'app/assets/javascripts/application.js', after: '//= require_tree .' do
|
20
20
|
"\n//= require browse_everything"
|
21
21
|
end
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
def inject_application
|
25
|
-
insert_into_file
|
25
|
+
insert_into_file 'config/application.rb', after: 'Rails::Application' do
|
26
26
|
"\nconfig.autoload_paths+=[File.join(Rails.root,'../../lib')]"
|
27
27
|
end
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
def inject_routes
|
31
|
-
insert_into_file
|
32
|
-
%
|
33
|
-
|
31
|
+
insert_into_file 'config/routes.rb', after: '.draw do' do
|
32
|
+
%(
|
33
|
+
|
34
34
|
root :to => "file_handler#index"
|
35
35
|
get '/main', :to => "file_handler#main"
|
36
36
|
post '/file', :to => "file_handler#update"
|
37
|
-
|
37
|
+
)
|
38
38
|
end
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
def create_test_route
|
42
|
-
copy_file
|
43
|
-
copy_file
|
44
|
-
copy_file
|
42
|
+
copy_file 'app/controllers/file_handler_controller.rb', 'app/controllers/file_handler_controller.rb'
|
43
|
+
copy_file 'app/views/file_handler/main.html.erb', 'app/views/file_handler/main.html.erb'
|
44
|
+
copy_file 'app/views/file_handler/index.html.erb', 'app/views/file_handler/index.html.erb'
|
45
45
|
end
|
46
|
-
|
47
46
|
end
|