bcms_s3 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.markdown +18 -0
- data/lib/bcms_s3/s3_module.rb +29 -1
- metadata +2 -2
data/README.markdown
CHANGED
@@ -10,6 +10,24 @@ This should be in the following format
|
|
10
10
|
## Using this module with [Heroku](http://heroku.com)
|
11
11
|
If using this module in conjunction with deployment on heroku you should probably turning heroku caching on by setting Cms::S3.heroku_caching in config/initializers/browsercms.rb to true.
|
12
12
|
|
13
|
+
In order to avoid putting your secret AWS key in the s3.yml file, you can take advantage of [heroku's config vars](http://docs.heroku.com/config-vars). Use ERB to read the values from the environment. This way you can safely commit your s3.yml file to the repository without revealing your amazon credentials.
|
14
|
+
|
15
|
+
access_key_id: <%= ENV['s3_access_key_id'] %>
|
16
|
+
secret_access_key: <%= ENV['s3_secret_access_key'] %>
|
17
|
+
bucket: <%= ENV['s3_bucket'] %>
|
18
|
+
|
19
|
+
For developing on your local machine, export the s3 variables to your environment.
|
20
|
+
|
21
|
+
export s3_access_key_id='your AWS access key'
|
22
|
+
export s3_secret_access_key='your AWS secret access key'
|
23
|
+
export s3_bucket='your unique bucket name'
|
24
|
+
|
25
|
+
Set the config vars on heroku to get it working there as well.
|
26
|
+
|
27
|
+
heroku config:add s3_access_key_id='your AWS access key'
|
28
|
+
heroku config:add s3_secret_access_key='your AWS secret access key'
|
29
|
+
heroku config:add s3_bucket='your unique bucket name'
|
30
|
+
|
13
31
|
## www prefix for non cms urls
|
14
32
|
If your non cms domain is www.myapp.com rather than app.com this can be enabled by setting Cms::S3.www_domain_prefix in config/initializers/browsercms.rb to true.
|
15
33
|
|
data/lib/bcms_s3/s3_module.rb
CHANGED
@@ -7,6 +7,32 @@ module Cms
|
|
7
7
|
attr_accessor :www_domain_prefix
|
8
8
|
attr_accessor :options
|
9
9
|
end
|
10
|
+
module AttachmentsController
|
11
|
+
def self.included(controller_class)
|
12
|
+
controller_class.alias_method_chain :show, :s3
|
13
|
+
end
|
14
|
+
|
15
|
+
def show_with_s3
|
16
|
+
@attachment = ::Attachment.find(params[:id])
|
17
|
+
@attachment = @attachment.as_of_version(params[:version]) if params[:version]
|
18
|
+
if Cms::S3.enabled
|
19
|
+
#get the file off S3
|
20
|
+
redirect_to("http://#{Cms::S3.options[:bucket]}.s3.amazonaws.com/#{@attachment.file_location}")
|
21
|
+
else
|
22
|
+
#Construct a path to where this file would be if it were cached
|
23
|
+
@file = @attachment.full_file_location
|
24
|
+
|
25
|
+
#Stream the file if it exists
|
26
|
+
if @path != "/" && File.exists?(@file)
|
27
|
+
send_file(@file,
|
28
|
+
:filename => @attachment.file_name,
|
29
|
+
:type => @attachment.file_type,
|
30
|
+
:disposition => "inline"
|
31
|
+
)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
10
36
|
module ContentController
|
11
37
|
def self.included(controller_class)
|
12
38
|
controller_class.alias_method_chain :render_page_with_caching, :s3
|
@@ -103,6 +129,7 @@ module Cms
|
|
103
129
|
end
|
104
130
|
end
|
105
131
|
|
132
|
+
Cms::AttachmentsController.send(:include, Cms::S3::AttachmentsController)
|
106
133
|
Cms::ContentController.send(:include, Cms::S3::ContentController)
|
107
134
|
Attachment.send(:include, Cms::S3::Attachment)
|
108
135
|
Cms::ApplicationController.send(:include, Cms::S3::ApplicationController)
|
@@ -114,6 +141,7 @@ Cms::S3.heroku_caching = false if Cms::S3.heroku_caching.nil?
|
|
114
141
|
Cms::S3.www_domain_prefix = false if Cms::S3.www_domain_prefix.nil?
|
115
142
|
# load s3 options if s3.yml exists
|
116
143
|
if File.exists?("#{RAILS_ROOT}/config/s3.yml")
|
117
|
-
|
144
|
+
yaml_string = IO.read("#{RAILS_ROOT}/config/s3.yml")
|
145
|
+
Cms::S3.options = YAML::load(ERB.new(yaml_string).result)
|
118
146
|
Cms::S3.options.symbolize_keys!
|
119
147
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bcms_s3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anthony Underwood
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2010-06-17 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|