list_cloud_files 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +11 -0
- data/MIT-LICENSE +20 -0
- data/README +111 -0
- data/Rakefile +46 -0
- data/VERSION +1 -0
- data/init.rb +1 -0
- data/lib/list_cloud_files.rb +44 -0
- data/list_cloud_files.gemspec +55 -0
- data/rails/init.rb +1 -0
- metadata +123 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "bundler", "~> 1.0.0"
|
10
|
+
gem "jeweler", "~> 1.5.2"
|
11
|
+
end
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 [name of plugin creator]
|
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
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
ListCloudFiles
|
2
|
+
==============
|
3
|
+
|
4
|
+
ListCloudFiles is a really simple gem to help you show the contents of an Amazon S3 bucket
|
5
|
+
in a view in your Rails app. It uses a simple _metadata.txt file inside your bucket (that you create)
|
6
|
+
to provide friendly descriptions for each of the files in your bucket.
|
7
|
+
|
8
|
+
Configuration and usage is pretty simple. See below for example usage and sample Haml/Sass code, too.
|
9
|
+
|
10
|
+
|
11
|
+
Example Usage
|
12
|
+
=============
|
13
|
+
|
14
|
+
Instructions for using ListCloudFiles:
|
15
|
+
|
16
|
+
0. Set up a bucket on Amazon S3 to hold your files. Make sure they're all publicly readable.
|
17
|
+
If you'd like to include description metadata for each of your files in the bucket,
|
18
|
+
create a new file in the bucket called _metadata.txt. Format _metadata.txt like this:
|
19
|
+
|
20
|
+
<code>
|
21
|
+
Some_file_name.txt|This is a description about some file.
|
22
|
+
Another_file.txt|Here's a description about another file.
|
23
|
+
</code>
|
24
|
+
|
25
|
+
Anything after the pipe character on this line counts as a description. Anything before the pipe character is the file name key we'll use to look up this description based on a matching filename in the bucket, so make sure it matches.
|
26
|
+
|
27
|
+
|
28
|
+
1. Create config/initializers/list_cloud_files.rb with:
|
29
|
+
ListCloudFiles.aws_access_key_id = 'your_amazon_aws_access_key'
|
30
|
+
ListCloudFiles.aws_secret_access_key = 'your_amazon_aws_secret_access_key'
|
31
|
+
|
32
|
+
# this controls how often the cache of the s3 bucket's file contents will be cleared
|
33
|
+
ListCloudFiles.cache_expires_in = 1.day
|
34
|
+
|
35
|
+
|
36
|
+
2. Call ListCloudFiles.get_files_for_bucket('your-bucket-name') in your controller.
|
37
|
+
You'd probably do something like:
|
38
|
+
|
39
|
+
<code>
|
40
|
+
@cloud_files = ListCloudFiles.get_files_for_bucket('my-bucket-name')
|
41
|
+
</code>
|
42
|
+
|
43
|
+
ListCloudFiles.get_files_for_bucket('your-bucket-name') returns a hash with:
|
44
|
+
:file_names # an array of strings for each file in your bucket
|
45
|
+
:file_metadata # a hash of metadata keyed on each file_name from the file_names key above
|
46
|
+
|
47
|
+
Each hash vlaue in the :file_metadata contains these keys:
|
48
|
+
:pretty_name # the name of the file without the extension
|
49
|
+
:extension # the file's extension
|
50
|
+
:description # a description taken from parsing the _metadata.txt file (see below)
|
51
|
+
:public_url # the public url for the file, assuming it has public read access
|
52
|
+
|
53
|
+
|
54
|
+
3. Use the result of ListCloudFiles.get_files_for_bucket in your view to show the data.
|
55
|
+
Assuming you set @cloud_files = ListCloudFiles.get_files_for_bucket('my-bucket-name'),
|
56
|
+
and assuming you're using Haml, you'd probably do something like the following.
|
57
|
+
|
58
|
+
Note: this example code assumes that you have file images to match each file extension
|
59
|
+
in public/images/list_cloud_files/filetypes/<extension>.png
|
60
|
+
|
61
|
+
<code>
|
62
|
+
- @file_metadata = @cloud_files[:file_metadata]
|
63
|
+
%ul.cloud_files
|
64
|
+
- @cloud_files[:file_names].each do |file_name|
|
65
|
+
- file_metadata = @file_metadata[file_name]
|
66
|
+
%li.file{ :class => file_metadata[:extension] }
|
67
|
+
%a{:href => file_metadata[:public_url]}
|
68
|
+
%img.file_icon{:src => "/images/list_cloud_files/filetypes/#{file_metadata[:extension]}.png", :alt => @file_metadata[file_name][:extension]}
|
69
|
+
%span.file_name
|
70
|
+
%a{:href => file_metadata[:public_url]}
|
71
|
+
= file_metadata[:pretty_name]
|
72
|
+
%span.file_description
|
73
|
+
%a{:href => file_metadata[:public_url]}
|
74
|
+
= file_metadata[:description]
|
75
|
+
</code>
|
76
|
+
|
77
|
+
|
78
|
+
4. Stlye the HTML output so it doesn't look like total crap. Here're some example Sass styles:
|
79
|
+
|
80
|
+
<code>
|
81
|
+
ul.cloud_files
|
82
|
+
:list-style-type none
|
83
|
+
:margin 0
|
84
|
+
:padding 0
|
85
|
+
li.file
|
86
|
+
:padding 0
|
87
|
+
:margin-bottom 20px
|
88
|
+
a
|
89
|
+
:color inherit
|
90
|
+
:text-decoration none
|
91
|
+
img.file_icon
|
92
|
+
:width 50px
|
93
|
+
:margin 0 10px 0 0
|
94
|
+
:float left
|
95
|
+
span.file_name
|
96
|
+
:font-weight bold
|
97
|
+
:font-size 24px
|
98
|
+
:display block
|
99
|
+
:padding-top 24px
|
100
|
+
:font-weight bold
|
101
|
+
a
|
102
|
+
:text-decoration underline
|
103
|
+
span.file_description
|
104
|
+
:display block
|
105
|
+
:clear both
|
106
|
+
:font-weight normal
|
107
|
+
</code>
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
Copyright (c) 2011 Gabe Hollombe, released under the MIT license
|
data/Rakefile
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
+
gem.name = "list_cloud_files"
|
16
|
+
gem.homepage = "http://github.com/gabehollombe/list_cloud_files"
|
17
|
+
gem.license = "MIT"
|
18
|
+
gem.summary = %Q{Easily share the contents of a public Amazon S3 bucket in your Rails app}
|
19
|
+
gem.description = %Q{Easily share the contents of a public Amazon S3 bucket in your Rails app}
|
20
|
+
gem.email = "gabe@avantbard.com"
|
21
|
+
gem.authors = ["Gabe Hollombe"]
|
22
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
23
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
24
|
+
gem.add_runtime_dependency 'fog', '>= 0.7.1'
|
25
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
26
|
+
end
|
27
|
+
Jeweler::RubygemsDotOrgTasks.new
|
28
|
+
|
29
|
+
require 'rake/testtask'
|
30
|
+
Rake::TestTask.new(:test) do |test|
|
31
|
+
test.libs << 'lib' << 'test'
|
32
|
+
test.pattern = 'test/**/test_*.rb'
|
33
|
+
test.verbose = true
|
34
|
+
end
|
35
|
+
|
36
|
+
task :default => :test
|
37
|
+
|
38
|
+
require 'rake/rdoctask'
|
39
|
+
Rake::RDocTask.new do |rdoc|
|
40
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
41
|
+
|
42
|
+
rdoc.rdoc_dir = 'rdoc'
|
43
|
+
rdoc.title = "list_cloud_files #{version}"
|
44
|
+
rdoc.rdoc_files.include('README*')
|
45
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
46
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Include hook code here
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# ListCloudFiles
|
2
|
+
class ListCloudFiles
|
3
|
+
#everything here is at the class level
|
4
|
+
class << self
|
5
|
+
attr_accessor :aws_access_key_id, :aws_secret_access_key, :cache_expires_in
|
6
|
+
|
7
|
+
def get_files_for_bucket(bucket_name)
|
8
|
+
Rails.cache.fetch(bucket_name, :expires_in => (@cache_expires_in || 1.day)) do
|
9
|
+
storage = Fog::Storage.new(:provider => 'AWS', :aws_access_key_id => @aws_access_key_id, :aws_secret_access_key => @aws_secret_access_key)
|
10
|
+
directory = storage.directories.get(bucket_name)
|
11
|
+
files = directory.files
|
12
|
+
|
13
|
+
#read the metadata file and build a hash of info for each file
|
14
|
+
file_metadata = {}
|
15
|
+
if directory.files.get('_metadata.txt')
|
16
|
+
directory.files.get('_metadata.txt').body.split("\n").each do |line|
|
17
|
+
file_name, description = line.split('|')
|
18
|
+
file_metadata[file_name] = { :description => description }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
file_names = []
|
23
|
+
files.reject{|f| f.key == '_metadata.txt'}.each do |file|
|
24
|
+
file_name = file.key
|
25
|
+
file_names << file_name
|
26
|
+
name, extension = file_name.rpartition('.')[0], file_name.rpartition('.')[2]
|
27
|
+
pretty_name = name.gsub('_', ' ')
|
28
|
+
file_metadata[file_name].merge!({
|
29
|
+
:pretty_name => pretty_name,
|
30
|
+
:extension => extension,
|
31
|
+
:public_url => file.public_url
|
32
|
+
})
|
33
|
+
end
|
34
|
+
|
35
|
+
#returning our hash of info
|
36
|
+
{:file_names => file_names, :file_metadata => file_metadata}
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def get_html_for_files(cloud_files)
|
41
|
+
#must be passed a hash with :file_names => array of filenames, :file_metadata => hash of metadata keyed on filename
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{list_cloud_files}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Gabe Hollombe"]
|
12
|
+
s.date = %q{2011-04-01}
|
13
|
+
s.description = %q{Easily share the contents of a public Amazon S3 bucket in your Rails app}
|
14
|
+
s.email = %q{gabe@avantbard.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
".document",
|
20
|
+
"Gemfile",
|
21
|
+
"MIT-LICENSE",
|
22
|
+
"README",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION",
|
25
|
+
"init.rb",
|
26
|
+
"lib/list_cloud_files.rb",
|
27
|
+
"list_cloud_files.gemspec",
|
28
|
+
"rails/init.rb"
|
29
|
+
]
|
30
|
+
s.homepage = %q{http://github.com/gabehollombe/list_cloud_files}
|
31
|
+
s.licenses = ["MIT"]
|
32
|
+
s.require_paths = ["lib"]
|
33
|
+
s.rubygems_version = %q{1.3.7}
|
34
|
+
s.summary = %q{Easily share the contents of a public Amazon S3 bucket in your Rails app}
|
35
|
+
|
36
|
+
if s.respond_to? :specification_version then
|
37
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
38
|
+
s.specification_version = 3
|
39
|
+
|
40
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
41
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
42
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
43
|
+
s.add_runtime_dependency(%q<fog>, [">= 0.7.1"])
|
44
|
+
else
|
45
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
46
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
47
|
+
s.add_dependency(%q<fog>, [">= 0.7.1"])
|
48
|
+
end
|
49
|
+
else
|
50
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
51
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
52
|
+
s.add_dependency(%q<fog>, [">= 0.7.1"])
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
data/rails/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'list_cloud_files'
|
metadata
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: list_cloud_files
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Gabe Hollombe
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-04-01 00:00:00 +11:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
name: bundler
|
25
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ~>
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
hash: 23
|
31
|
+
segments:
|
32
|
+
- 1
|
33
|
+
- 0
|
34
|
+
- 0
|
35
|
+
version: 1.0.0
|
36
|
+
requirement: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
name: jeweler
|
41
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ~>
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
hash: 7
|
47
|
+
segments:
|
48
|
+
- 1
|
49
|
+
- 5
|
50
|
+
- 2
|
51
|
+
version: 1.5.2
|
52
|
+
requirement: *id002
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
name: fog
|
57
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
hash: 1
|
63
|
+
segments:
|
64
|
+
- 0
|
65
|
+
- 7
|
66
|
+
- 1
|
67
|
+
version: 0.7.1
|
68
|
+
requirement: *id003
|
69
|
+
description: Easily share the contents of a public Amazon S3 bucket in your Rails app
|
70
|
+
email: gabe@avantbard.com
|
71
|
+
executables: []
|
72
|
+
|
73
|
+
extensions: []
|
74
|
+
|
75
|
+
extra_rdoc_files:
|
76
|
+
- README
|
77
|
+
files:
|
78
|
+
- .document
|
79
|
+
- Gemfile
|
80
|
+
- MIT-LICENSE
|
81
|
+
- README
|
82
|
+
- Rakefile
|
83
|
+
- VERSION
|
84
|
+
- init.rb
|
85
|
+
- lib/list_cloud_files.rb
|
86
|
+
- list_cloud_files.gemspec
|
87
|
+
- rails/init.rb
|
88
|
+
has_rdoc: true
|
89
|
+
homepage: http://github.com/gabehollombe/list_cloud_files
|
90
|
+
licenses:
|
91
|
+
- MIT
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
hash: 3
|
103
|
+
segments:
|
104
|
+
- 0
|
105
|
+
version: "0"
|
106
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
+
none: false
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
hash: 3
|
112
|
+
segments:
|
113
|
+
- 0
|
114
|
+
version: "0"
|
115
|
+
requirements: []
|
116
|
+
|
117
|
+
rubyforge_project:
|
118
|
+
rubygems_version: 1.3.7
|
119
|
+
signing_key:
|
120
|
+
specification_version: 3
|
121
|
+
summary: Easily share the contents of a public Amazon S3 bucket in your Rails app
|
122
|
+
test_files: []
|
123
|
+
|