redactor_s3 0.0.1 → 1.0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e12f897ffc4c3a07d5d402817df954c4174f27cc
4
- data.tar.gz: ee4b26125ff17eeb3aa9d4927fdc1f29b8616966
3
+ metadata.gz: b728ee99cfe4c22b0819ef40e7f262d6970c89a1
4
+ data.tar.gz: 325900ea4a9afbb746c86f08daa8fbb5e290d9fc
5
5
  SHA512:
6
- metadata.gz: eca361228fc7b10f3fac57e72fc715197a6e6a614f5f0a858f9ef90499884357bd8401a6addde6f910e9c4ee29a36c20a7b0b048540e3cc97ff3f3d481983bb7
7
- data.tar.gz: 46cc3a4730abfadf02f3e332c32fcbad6d73807d685a7a9e1971ccd50d4b131843e404f7d5288d339fcaa869d9def906d0731232a643909e517ed15f472ba400
6
+ metadata.gz: d08e2fd3829fc465369d7f05abfb96a2fa493e726af738f0ad3db614ac78f8e1d221c51913c4371b4f75442e1c4ccfbe789460dad7d47e787268cbe2c3ef0718
7
+ data.tar.gz: 714c439f623ef954d0bc69f248d39659cdb1e292bbf713933fcf3c0c416bdd2721176b7cd8d8c2a7a7eb102dfab6762ef4fc32eec2920ef4e2443822a5bea169
@@ -1,3 +1,48 @@
1
1
  = RedactorS3
2
+ This gem provides easy integration between redactor.js and Amazon S3 for rails applications
2
3
 
4
+ == Getting started
5
+ 1. Add the gem:
6
+ gem 'redactor_s3'
7
+ 2. Mount it inside your routes:
8
+ mount RedactorS3::Engine => "/s3"
9
+ 3. Run the installer:
10
+ rails generate redactor_s3:install
11
+ Dont forget to edit the config file
12
+
13
+ == Usage
14
+ To use it you need to render some hidden fields in the views where you will be using redactor
15
+
16
+ Example:
17
+ # edit.html.rb
18
+ ...
19
+ ...
20
+ <textarea class="redactor"></textarea>
21
+ <%= render 'redactor_s3/config' %>
22
+
23
+ You then need to configure your redactor instance in jquery:
24
+ # edit.js
25
+ ...
26
+ ...
27
+ $("textarea.redactor").redactor({
28
+ ...
29
+ ...
30
+ imageUpload: $("#aws_endpoint").val(),
31
+ uploadCrossDomain: true,
32
+ uploadFields: {
33
+ 'key': '#aws_key',
34
+ 'AWSAccessKeyId': '#aws_access_key',
35
+ 'acl': '#aws_acl',
36
+ 'success_action_redirect': '#aws_success_path',
37
+ 'policy': '#aws_policy',
38
+ 'signature': '#aws_signature',
39
+ 'Content-Type': '#aws_content_type'
40
+ },
41
+ imageGetJson: $("#aws_files_path").val()
42
+ });
43
+
44
+
45
+ You should now be good to go
46
+
47
+ == License
3
48
  This project rocks and uses MIT-LICENSE.
@@ -5,15 +5,13 @@ require_dependency "jbuilder"
5
5
  module RedactorS3
6
6
  class FilesController < ApplicationController
7
7
  def success
8
- settings = Settings.new
9
- render json: { filelink: "http://#{settings.s3_host}/#{params[:key]}" }
8
+ render json: { filelink: "#{RedactorS3.config.s3_host_url}/#{params[:key]}" }
10
9
  end
11
10
 
12
11
  def index
13
- @settings = Settings.new
14
- s3 = AWS::S3.new access_key_id: @settings.access_key, secret_access_key: @settings.secret_key, s3_endpoint: @settings.endpoint
15
- bucket = s3.buckets[@settings.bucket]
16
- @files = bucket.objects.with_prefix(@settings.prefix)
12
+ s3 = AWS::S3.new access_key_id: RedactorS3.config.access_key, secret_access_key: RedactorS3.config.secret_key, s3_endpoint: RedactorS3.config.endpoint
13
+ bucket = s3.buckets[RedactorS3.config.bucket]
14
+ @files = bucket.objects.with_prefix(RedactorS3.config.prefix)
17
15
  end
18
16
  end
19
17
  end
@@ -1,10 +1,9 @@
1
- <% settings = RedactorS3::Settings.new %>
2
- <input type="hidden" id="aws_key" name="aws_key" value="<%= settings.prefix %>${filename}">
3
- <input type="hidden" id="aws_access_key" name="aws_access_key" value="<%= settings.access_key %>">
1
+ <input type="hidden" id="aws_key" name="aws_key" value="<%= RedactorS3.config.prefix %>${filename}">
2
+ <input type="hidden" id="aws_access_key" name="aws_access_key" value="<%= RedactorS3.config.access_key %>">
4
3
  <input type="hidden" id="aws_acl" name="aws_acl" value="public-read">
5
- <input type="hidden" id="aws_success_path" name="aws_success_path" value="<%= settings.success_url %>">
6
- <input type="hidden" id="aws_policy" name="aws_policy" value="<%= settings.policy %>">
7
- <input type="hidden" id="aws_signature" name="aws_signature" value="<%= settings.signature %>">
4
+ <input type="hidden" id="aws_success_path" name="aws_success_path" value="<%= RedactorS3.config.success_url %>">
5
+ <input type="hidden" id="aws_policy" name="aws_policy" value="<%= RedactorS3.config.policy %>">
6
+ <input type="hidden" id="aws_signature" name="aws_signature" value="<%= RedactorS3.config.signature %>">
8
7
  <input type="hidden" id="aws_content_type" name="aws_content_type" value="">
9
- <input type="hidden" id="aws_endpoint" name="aws_endpoint" value="<%= settings.bucket_url %>">
8
+ <input type="hidden" id="aws_endpoint" name="aws_endpoint" value="<%= RedactorS3.config.bucket_url %>">
10
9
  <input type="hidden" id="aws_files_path" name="aws_files_path" value="/s3/files">
@@ -1,4 +1,4 @@
1
1
  json.array! @files do |file|
2
- json.thumb "#{@settings.bucket_url}/#{file.key}"
3
- json.image "#{@settings.bucket_url}/#{file.key}"
2
+ json.thumb "#{RedactorS3.config.s3_host_url}/#{file.key}"
3
+ json.image "#{RedactorS3.config.s3_host_url}/#{file.key}"
4
4
  end
@@ -0,0 +1,15 @@
1
+ module RedactorS3
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ desc 'Creates an initializer at config/initializers/radactor_s3.rb'
5
+
6
+ def self.source_root
7
+ @source_root ||= File.expand_path("../templates", __FILE__)
8
+ end
9
+
10
+ def create_initializer_file
11
+ template 'initializer.rb', File.join('config', 'initializers', 'redactor_s3.rb')
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ RedactorS3.configure do |config|
2
+ config.application_host = 'my.domain.com'
3
+ config.bucket = 'mybucket'
4
+ config.access_key = 'AWS_ACCESS_KEY_ID'
5
+ config.secret_key = 'AWS_SECRET_ACCESS_KEY'
6
+
7
+ ## Optinal
8
+ # config.region = 'eu-west-1'
9
+ # config.s3_host = 'mybucket.example.com'
10
+ # config.prefix = 'files/'
11
+ end
@@ -1,5 +1,6 @@
1
+ require 'redactor_s3/redactor_s3'
2
+ require 'redactor_s3/config'
1
3
  require "redactor_s3/engine"
2
4
 
3
5
  module RedactorS3
4
- mattr_accessor :application_host, :access_key, :secret_key, :bucket, :s3_host, :endpoint, :prefix
5
6
  end
@@ -0,0 +1,46 @@
1
+ module RedactorS3
2
+ class Config
3
+ attr_accessor :application_host, :bucket, :access_key, :secret_key, :region, :prefix, :s3_alias
4
+
5
+ def initialize
6
+ self.prefix = 'files/'
7
+ end
8
+
9
+ def success_url
10
+ "http://#{application_host}/s3/success"
11
+ end
12
+
13
+ def bucket_url
14
+ "http://#{self.bucket}.#{self.endpoint}"
15
+ end
16
+
17
+ def s3_host_url
18
+ self.s3_alias ? "http://#{self.s3_alias}" : self.bucket_url
19
+ end
20
+
21
+ def endpoint
22
+ s3_prefix = 's3'
23
+ s3_prefix << "-#{self.region}" if region
24
+ "#{s3_prefix}.amazonaws.com"
25
+ end
26
+
27
+ def policy
28
+ policy_json="{'expiration': '2020-01-01T00:00:00Z',
29
+ 'conditions': [
30
+ {'bucket': '#{self.bucket}'},
31
+ ['starts-with', '$key', ''],
32
+ {'acl': 'public-read'},
33
+ {'success_action_redirect': '#{self.success_url}'},
34
+ ['starts-with', '$Content-Type', ''],
35
+ ['content-length-range', 0, 1048576]
36
+ ]
37
+ }"
38
+
39
+ Base64.encode64(policy_json).gsub("\n","")
40
+ end
41
+
42
+ def signature
43
+ Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new('sha1'), self.secret_key, policy)).gsub("\n","")
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,18 @@
1
+ module RedactorS3
2
+ class << self
3
+
4
+ def config=(data)
5
+ @config = data
6
+ end
7
+
8
+ def config
9
+ @config ||= Config.new
10
+ @config
11
+ end
12
+
13
+ def configure(&proc)
14
+ @config ||= Config.new
15
+ yield @config
16
+ end
17
+ end
18
+ end
@@ -1,3 +1,3 @@
1
1
  module RedactorS3
2
- VERSION = "0.0.1"
2
+ VERSION = "1.0.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redactor_s3
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aske Hansen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-11 00:00:00.000000000 Z
11
+ date: 2013-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -87,21 +87,18 @@ executables: []
87
87
  extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
- - app/assets/javascripts/redactor_s3/application.js
91
- - app/assets/javascripts/redactor_s3/files.js
92
- - app/assets/stylesheets/redactor_s3/application.css
93
- - app/assets/stylesheets/redactor_s3/files.css
94
90
  - app/controllers/redactor_s3/application_controller.rb
95
91
  - app/controllers/redactor_s3/files_controller.rb
96
92
  - app/helpers/redactor_s3/application_helper.rb
97
93
  - app/helpers/redactor_s3/files_helper.rb
98
- - app/models/redactor_s3/settings.rb
99
- - app/views/layouts/redactor_s3/application.html.erb
100
- - app/views/redactor_s3/files/_config.html.erb
94
+ - app/views/redactor_s3/_config.html.erb
101
95
  - app/views/redactor_s3/files/index.jbuilder
102
- - config/initializers/redactor_s3.rb
103
96
  - config/routes.rb
97
+ - lib/rails/generators/redactor_s3/install/install_generator.rb
98
+ - lib/rails/generators/redactor_s3/install/templates/initializer.rb
99
+ - lib/redactor_s3/config.rb
104
100
  - lib/redactor_s3/engine.rb
101
+ - lib/redactor_s3/redactor_s3.rb
105
102
  - lib/redactor_s3/version.rb
106
103
  - lib/redactor_s3.rb
107
104
  - lib/tasks/redactor_s3_tasks.rake
@@ -1,13 +0,0 @@
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
- // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
- // GO AFTER THE REQUIRES BELOW.
12
- //
13
- //= require_tree .
@@ -1,2 +0,0 @@
1
- // Place all the behaviors and hooks related to the matching controller here.
2
- // All this logic will automatically be available in application.js.
@@ -1,13 +0,0 @@
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 top of the
9
- * compiled file, but it's generally better to create a new file per style scope.
10
- *
11
- *= require_self
12
- *= require_tree .
13
- */
@@ -1,4 +0,0 @@
1
- /*
2
- Place all the styles related to the matching controller here.
3
- They will automatically be included in application.css.
4
- */
@@ -1,43 +0,0 @@
1
- module RedactorS3
2
- class Settings
3
- attr_accessor :application_host, :bucket, :access_key, :secret_key, :endpoint, :s3_host, :prefix
4
-
5
- def initialize
6
- @application_host = RedactorS3.application_host
7
- @bucket = RedactorS3.bucket
8
- @access_key = RedactorS3.access_key
9
- @secret_key = RedactorS3.secret_key
10
-
11
- @endpoint = RedactorS3.endpoint || 's3.amazonaws.com'
12
- @s3_host = RedactorS3.s3_host || "#{@bucket}.#{@endpoint}"
13
- @prefix = RedactorS3.prefix || 'files/'
14
- end
15
-
16
- def bucket_url
17
- "http://#{@bucket}.#{@endpoint}"
18
- end
19
-
20
- def success_url
21
- "http://#{@application_host}/s3/success"
22
- end
23
-
24
- def policy
25
- policy_json="{'expiration': '2020-01-01T00:00:00Z',
26
- 'conditions': [
27
- {'bucket': '#{@bucket}'},
28
- ['starts-with', '$key', ''],
29
- {'acl': 'public-read'},
30
- {'success_action_redirect': '#{success_url}'},
31
- ['starts-with', '$Content-Type', ''],
32
- ['content-length-range', 0, 1048576]
33
- ]
34
- }"
35
-
36
- Base64.encode64(policy_json).gsub("\n","")
37
- end
38
-
39
- def signature
40
- Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new('sha1'), @secret_key, policy)).gsub("\n","")
41
- end
42
- end
43
- end
@@ -1,14 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>RedactorS3</title>
5
- <%= stylesheet_link_tag "redactor_s3/application", media: "all" %>
6
- <%= javascript_include_tag "redactor_s3/application" %>
7
- <%= csrf_meta_tags %>
8
- </head>
9
- <body>
10
-
11
- <%= yield %>
12
-
13
- </body>
14
- </html>
@@ -1,11 +0,0 @@
1
- # # These are required options
2
- # RedactorS3.application_host = 'www.example.com' # your domain
3
- # RedactorS3.bucket = 'mybucket' # your s3 bucket name
4
- # RedactorS3.access_key = 'AWS_ACCESS_KEY_ID' # your aws access key id
5
- # RedactorS3.secret_key = 'AWS_SECRET_ACCESS_KEY' #your aws secret access key
6
-
7
-
8
- # # These are optinal options
9
- # RedactorS3.endpoint = 's3-eu-west-1.amazonaws.com' # use this for eu buckets
10
- # RedactorS3.s3_host = 'mybucket.example.com' # use this if you have a alias for your s3 bucket
11
- # RedactorS3.prefix = 'files' # all uploads goes the this folder