anaconda 0.0.3 → 0.1.2
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 +4 -4
- data/README.markdown +86 -8
- data/app/assets/javascripts/anaconda_uploader.js.coffee +55 -39
- data/app/views/anaconda/_uploader_form_for.html.haml +3 -4
- data/lib/anaconda.rb +16 -0
- data/lib/anaconda/anaconda_for.rb +13 -11
- data/lib/anaconda/form_builder_helpers.rb +147 -0
- data/lib/anaconda/railtie.rb +3 -0
- data/lib/anaconda/upload_helper.rb +5 -5
- data/lib/anaconda/version.rb +1 -1
- data/lib/generators/anaconda/USAGE +3 -0
- data/lib/generators/anaconda/install_generator.rb +12 -0
- data/lib/generators/anaconda/migration_generator.rb +25 -0
- data/lib/generators/anaconda/templates/config/initializers/anaconda.rb +8 -0
- metadata +6 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7fdbbf12ffefec5c116f99be38fc11d908ba60a9
|
4
|
+
data.tar.gz: 9320e3c6cdef34e2e968c668b357dba366d37914
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36c1eb4ac4d6597b285edcee1a5502af3f95b4bb24dbc00c8a2143afe6f20547641c4798246a238e6fcf9afece4f4c37f5a26e99258039eb49d1b85a3e85e7b0
|
7
|
+
data.tar.gz: 12ace30c835230a065e6ea66fee390d79f37e8533bba47c2bf2817e48f8f3b49619ea8c57c62bad1aa568965325ce90a673d63e43698477480c28ccea49c55ae
|
data/README.markdown
CHANGED
@@ -10,20 +10,98 @@ If you require stability before that time, you are strongly encouraged to specif
|
|
10
10
|
|
11
11
|
## Installation
|
12
12
|
|
13
|
-
Add to your `Gemfile`
|
13
|
+
1. Add to your `Gemfile`
|
14
14
|
|
15
|
-
|
15
|
+
gem 'anaconda'
|
16
16
|
|
17
|
-
|
17
|
+
2. `bundle install`
|
18
18
|
|
19
|
-
|
20
|
-
|
19
|
+
3. Add the following to your `application.js`
|
20
|
+
|
21
|
+
//= require anaconda
|
22
|
+
|
23
|
+
4. Finally, run the installer to install the configuration initializer into `config/initializers/anaconda.rb`
|
24
|
+
|
25
|
+
$ rails g anaconda:install
|
26
|
+
|
27
|
+
## Configuration
|
28
|
+
|
29
|
+
### AWS S3 Setup
|
30
|
+
|
31
|
+
### AWS S3 Setup
|
32
|
+
|
33
|
+
#### IAM
|
34
|
+
|
35
|
+
Sample IAM Policy (be sure to replace 'your.bucketname'):
|
36
|
+
|
37
|
+
{
|
38
|
+
"Statement": [
|
39
|
+
{
|
40
|
+
"Effect": "Allow",
|
41
|
+
"Action": "s3:*",
|
42
|
+
"Resource": [
|
43
|
+
"arn:aws:s3:::[your.bucketname]",
|
44
|
+
"arn:aws:s3:::[your.bucketname]/*"
|
45
|
+
]
|
46
|
+
}
|
47
|
+
]
|
48
|
+
}
|
49
|
+
|
50
|
+
#### CORS
|
51
|
+
|
52
|
+
Sample CORS configuration:
|
53
|
+
|
54
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
55
|
+
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
|
56
|
+
<CORSRule>
|
57
|
+
<AllowedOrigin>*</AllowedOrigin>
|
58
|
+
<AllowedMethod>GET</AllowedMethod>
|
59
|
+
<AllowedMethod>POST</AllowedMethod>
|
60
|
+
<AllowedMethod>PUT</AllowedMethod>
|
61
|
+
<MaxAgeSeconds>3000</MaxAgeSeconds>
|
62
|
+
<AllowedHeader>*</AllowedHeader>
|
63
|
+
</CORSRule>
|
64
|
+
</CORSConfiguration>
|
65
|
+
|
66
|
+
|
67
|
+
### Initializer
|
68
|
+
|
69
|
+
The initializer installed into `config/initializers/anaconda.rb` contains the settings you need to get anaconda working.
|
70
|
+
|
71
|
+
**You must set these to your S3 credentials/settings in order for anaconda to work.**
|
72
|
+
|
73
|
+
We highly recommend the `figaro` gem [https://github.com/laserlemon/figaro](https://github.com/laserlemon/figaro) to manage your environment variables in development and production.
|
21
74
|
|
22
75
|
## Usage
|
23
76
|
|
24
|
-
*
|
25
|
-
|
26
|
-
*
|
77
|
+
* Controller changes (if any)
|
78
|
+
|
79
|
+
* Migrations
|
80
|
+
|
81
|
+
$ rails g migration anaconda:migration PostMedia asset
|
82
|
+
|
83
|
+
* Model setup
|
84
|
+
|
85
|
+
class PostMedia < ActiveRecord::Base
|
86
|
+
belongs_to :post
|
87
|
+
|
88
|
+
anaconda_for :asset, base_key: :asset_key
|
89
|
+
|
90
|
+
def asset_key
|
91
|
+
o = [('a'..'z'), ('A'..'Z')].map { |i| i.to_a }.flatten
|
92
|
+
s = (0...24).map { o[rand(o.length)] }.join
|
93
|
+
"post_media/#{s}"
|
94
|
+
end
|
95
|
+
|
96
|
+
|
97
|
+
|
98
|
+
* Form setup
|
99
|
+
|
100
|
+
#anaconda_upload_form_wrapper
|
101
|
+
= anaconda_uploader_form_for post_media, :asset, form_el: '#new_post_media', limits: { images: 9999 }, auto_upload: true
|
102
|
+
|
103
|
+
|
104
|
+
* Options
|
27
105
|
|
28
106
|
## Contributing to anaconda
|
29
107
|
|
@@ -8,6 +8,7 @@ class @AnacondaUploader
|
|
8
8
|
|
9
9
|
|
10
10
|
constructor: (options = {}) ->
|
11
|
+
@element_id = options.element_id ? ""
|
11
12
|
@limits = options.limits ? {}
|
12
13
|
@allowed_types = options.allowed_types ? []
|
13
14
|
@upload_details_container = $("##{options.upload_details_container}") ? $("#files")
|
@@ -19,13 +20,12 @@ class @AnacondaUploader
|
|
19
20
|
@attribute = options.attribute ? null
|
20
21
|
|
21
22
|
@files_for_upload = []
|
22
|
-
@base_key =
|
23
|
+
@base_key = options.base_key ? ""
|
23
24
|
@setup_fileupload()
|
24
|
-
@setup_upload_button_handler()
|
25
25
|
|
26
26
|
setup_fileupload: ->
|
27
27
|
self = this
|
28
|
-
$(
|
28
|
+
$( @element_id ).fileupload
|
29
29
|
dropZone: $("#dropzone")
|
30
30
|
add: (e, data) ->
|
31
31
|
self.add_file data
|
@@ -41,20 +41,34 @@ class @AnacondaUploader
|
|
41
41
|
fail: (e, data) ->
|
42
42
|
alert("#{data.files[0].name} failed to upload.")
|
43
43
|
DLog("Upload failed:")
|
44
|
+
DLog("Error:")
|
44
45
|
DLog(e)
|
46
|
+
DLog("data:")
|
45
47
|
DLog(data)
|
48
|
+
DLog("data.errorThrown:")
|
46
49
|
DLog(data.errorThrown )
|
50
|
+
DLog("data.textStatus:")
|
47
51
|
DLog(data.textStatus )
|
52
|
+
DLog("data.jqXHR:")
|
48
53
|
DLog(data.jqXHR )
|
49
54
|
|
50
55
|
$(document).bind 'drop dragover', (e) ->
|
51
56
|
e.preventDefault()
|
52
57
|
|
53
58
|
setup_upload_button_handler: ->
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
59
|
+
#alert( "setup_upload_button_handler for #{@element_id}" )
|
60
|
+
unless ( @upload_automatically == true )
|
61
|
+
DLog( "Setting up submit handler for element #{@element_id}")
|
62
|
+
$(@element_id).closest( 'form' ).on( 'submit', { self: this }, this.form_submit_handler )
|
63
|
+
|
64
|
+
form_submit_handler: (e) ->
|
65
|
+
# alert( 'form_submit_handler' )
|
66
|
+
e.preventDefault()
|
67
|
+
self = e.data.self
|
68
|
+
$(this).off( 'submit', self.form_submit_handler )
|
69
|
+
|
70
|
+
self.files_for_upload[0].submit()
|
71
|
+
false
|
58
72
|
|
59
73
|
files_by_type: (type) ->
|
60
74
|
matches = []
|
@@ -91,9 +105,11 @@ class @AnacondaUploader
|
|
91
105
|
DLog(upload_file)
|
92
106
|
@upload_details_container.append "<div id='upload_file_#{upload_file.id}' class='upload-file #{upload_file.media_type}'><span class='file-name'>#{upload_file.file.name}</span><span class='size'>#{upload_file.file.size}</span><span class='progress-percent'></span><div class='progress'><span class='progress-bar'></span></div></div>"
|
93
107
|
|
94
|
-
if @upload_automatically
|
108
|
+
if @upload_automatically == true
|
109
|
+
DLog( "Upload Automatically: #{@upload_automatically}")
|
95
110
|
upload_file.submit()
|
96
|
-
|
111
|
+
else
|
112
|
+
@setup_upload_button_handler()
|
97
113
|
else
|
98
114
|
alert "Only #{@limits[upload_file.media_type]} #{upload_file.media_type} files are allowed"
|
99
115
|
else
|
@@ -103,36 +119,36 @@ class @AnacondaUploader
|
|
103
119
|
DLog "#{upload_file.file.name} completed uploading"
|
104
120
|
DLog upload_file
|
105
121
|
|
106
|
-
if @upload_complete_post_url? && @upload_complete_post_url != ""
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
122
|
+
# if @upload_complete_post_url? && @upload_complete_post_url != ""
|
123
|
+
# DLog "will now post to #{@upload_complete_post_url}"
|
124
|
+
#
|
125
|
+
# file_data = {}
|
126
|
+
# file_data[@resource] = {}
|
127
|
+
# file_data[@resource]["#{@attribute}_file_path"] = "#{@base_key}/#{upload_file.file.name}"
|
128
|
+
# file_data[@resource]["#{@attribute}_filename"] = upload_file.file.name
|
129
|
+
# file_data[@resource]["#{@attribute}_size"] = upload_file.file.size
|
130
|
+
# file_data[@resource]["#{@attribute}_type"] = upload_file.file.media_type
|
131
|
+
# upload_file = this
|
132
|
+
# $.ajax({
|
133
|
+
# type: 'PATCH',
|
134
|
+
# url: @upload_complete_post_url,
|
135
|
+
# data: $.param(file_data)
|
136
|
+
# success: (data, textStatus, jqXHR) ->
|
137
|
+
# DLog "file completed handler complete"
|
138
|
+
# DLog data
|
139
|
+
# #TODO: handle a failure on this POST
|
140
|
+
# })
|
141
|
+
|
142
|
+
DLog "will now fill form #{@upload_complete_form_to_fill}"
|
143
|
+
|
144
|
+
DLog "#{@resource}_#{@attribute}_file_path"
|
145
|
+
|
146
|
+
$( @element_id ).siblings( '#' + "#{@resource}_#{@attribute}_file_path" ).val( "#{@base_key}/#{upload_file.file.name}" )
|
147
|
+
$( @element_id ).siblings( '#' + "#{@resource}_#{@attribute}_filename" ).val( upload_file.file.name )
|
148
|
+
$( @element_id ).siblings( '#' + "#{@resource}_#{@attribute}_size" ).val( upload_file.file.size )
|
149
|
+
$( @element_id ).siblings( '#' + "#{@resource}_#{@attribute}_type" ).val( upload_file.file.type )
|
150
|
+
|
151
|
+
$( @element_id ).closest( 'form' ).submit() unless ( @upload_automatically == true )
|
136
152
|
|
137
153
|
class @AnacondaUploadFile
|
138
154
|
|
@@ -1,6 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
%button#upload Upload
|
1
|
+
/ Moved to form_builder_helpers.rb
|
4
2
|
|
5
3
|
%strong Files:
|
6
4
|
#files
|
@@ -15,7 +13,8 @@
|
|
15
13
|
resource: 1,
|
16
14
|
image: 1
|
17
15
|
},
|
18
|
-
|
16
|
+
element_id: "#{option[:element_id]}"
|
17
|
+
allowed_types: [],
|
19
18
|
upload_details_container: "files",
|
20
19
|
upload_button_id: "upload",
|
21
20
|
upload_complete_post_url: "#{options[:form_options][:post_url]}",
|
data/lib/anaconda.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'rails'
|
1
2
|
require 'anaconda/anaconda'
|
2
3
|
require 'anaconda/anaconda_for'
|
3
4
|
require 'anaconda/railtie'
|
@@ -7,3 +8,18 @@ require 'anaconda/version'
|
|
7
8
|
ActiveSupport.on_load(:active_record) do
|
8
9
|
include Anaconda::Model
|
9
10
|
end
|
11
|
+
|
12
|
+
module Anaconda
|
13
|
+
mattr_accessor :aws
|
14
|
+
@@aws = {
|
15
|
+
aws_access_key: "",
|
16
|
+
aws_secret_key: "",
|
17
|
+
aws_bucket: ""
|
18
|
+
}
|
19
|
+
|
20
|
+
# Default way to setup Anaconda. Run rails generate anaconda:install
|
21
|
+
# to create a fresh initializer with all configuration values.
|
22
|
+
def self.config
|
23
|
+
yield self
|
24
|
+
end
|
25
|
+
end
|
@@ -6,20 +6,20 @@ module Anaconda
|
|
6
6
|
end
|
7
7
|
|
8
8
|
module ClassMethods
|
9
|
-
|
9
|
+
|
10
10
|
def anaconda_for( anaconda_columns, options = {})
|
11
11
|
send :include, InstanceMethods
|
12
|
-
|
12
|
+
|
13
13
|
anaconda_columns = [anaconda_columns] if anaconda_columns.kind_of?(Symbol) || anaconda_columns.kind_of?(String)
|
14
14
|
class_attribute :anaconda_columns
|
15
15
|
self.anaconda_columns = anaconda_columns.collect{ |c| c.to_sym }
|
16
16
|
# Class.anaconda_columns is now an array of symbols
|
17
|
-
|
17
|
+
|
18
18
|
class_attribute :anaconda_options
|
19
19
|
self.anaconda_options = options.reverse_merge(
|
20
|
-
aws_access_key_id:
|
21
|
-
aws_secret_access_key:
|
22
|
-
bucket:
|
20
|
+
aws_access_key_id: Anaconda.aws[:aws_access_key],
|
21
|
+
aws_secret_access_key: Anaconda.aws[:aws_secret_key],
|
22
|
+
bucket: Anaconda.aws[:aws_bucket],
|
23
23
|
acl: "public-read",
|
24
24
|
max_file_size: 500.megabytes,
|
25
25
|
base_key: "#{self.to_s.pluralize.downcase}/#{anaconda_columns.first.to_s.pluralize}/#{(0...32).map{(65+rand(26)).chr}.join.downcase}"
|
@@ -27,7 +27,7 @@ module Anaconda
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
module InstanceMethods
|
30
|
-
def method_missing(method, *args, &block)
|
30
|
+
def method_missing(method, *args, &block)
|
31
31
|
checking_column = checking_method = nil
|
32
32
|
if self.class.anaconda_columns.present? && self.class.anaconda_columns.any? do |column|
|
33
33
|
checking_column = column
|
@@ -46,14 +46,16 @@ module Anaconda
|
|
46
46
|
super
|
47
47
|
end
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
private
|
51
51
|
def magic_url(column_name)
|
52
|
+
nil unless send("#{column_name}_file_path").present?
|
53
|
+
|
52
54
|
if send("#{column_name}_stored_privately")
|
53
|
-
aws = Fog::Storage.new({:provider => 'AWS', :aws_access_key_id =>
|
54
|
-
aws.get_object_https_url(
|
55
|
+
aws = Fog::Storage.new({:provider => 'AWS', :aws_access_key_id => Anaconda.aws[:aws_access_key], :aws_secret_access_key => Anaconda.aws[:aws_secret_key]})
|
56
|
+
aws.get_object_https_url(Anaconda.aws[:aws_bucket], send("#{column_name}_file_path"), 1.hour.from_now)
|
55
57
|
else
|
56
|
-
"https://s3.amazonaws.com/#{
|
58
|
+
"https://s3.amazonaws.com/#{Anaconda.aws[:aws_bucket]}/#{send("#{column_name}_file_path")}"
|
57
59
|
end
|
58
60
|
end
|
59
61
|
end
|
@@ -0,0 +1,147 @@
|
|
1
|
+
module Anaconda
|
2
|
+
module FormBuilderHelpers
|
3
|
+
|
4
|
+
def anaconda( anaconda_field_name, form_options = {} )
|
5
|
+
output = ""
|
6
|
+
instance = nil
|
7
|
+
options = {}
|
8
|
+
|
9
|
+
element_id = "anaconda_file_#{anaconda_field_name}"
|
10
|
+
|
11
|
+
if self.class == SimpleForm::FormBuilder
|
12
|
+
instance = self.object
|
13
|
+
a_class = self.object.class unless self.object.kind_of? Class
|
14
|
+
|
15
|
+
options = a_class.anaconda_options.dup
|
16
|
+
options[:base_key] = instance.send(options[:base_key].to_s) if options[:base_key].kind_of? Symbol
|
17
|
+
|
18
|
+
uploader = S3Uploader.new(options)
|
19
|
+
|
20
|
+
output += self.input_field "file", name: "file", id: element_id, as: :file, "data-url" => uploader.url, "data-form-data" => uploader.fields.to_json
|
21
|
+
end
|
22
|
+
|
23
|
+
output += self.hidden_field "#{anaconda_field_name}_filename".to_sym
|
24
|
+
output += self.hidden_field "#{anaconda_field_name}_file_path".to_sym
|
25
|
+
output += self.hidden_field "#{anaconda_field_name}_size".to_sym
|
26
|
+
output += self.hidden_field "#{anaconda_field_name}_original_filename".to_sym
|
27
|
+
output += self.hidden_field "#{anaconda_field_name}_stored_privately".to_sym
|
28
|
+
output += self.hidden_field "#{anaconda_field_name}_type".to_sym
|
29
|
+
|
30
|
+
# output += render(:template =>"anaconda/_uploader_form_for.html.haml", :locals => {resource: instance, options: options.merge(as: anaconda_field_name, form_options: form_options, element_id: element_id )}, layout: false).to_s
|
31
|
+
|
32
|
+
options = options.merge(as: anaconda_field_name, form_options: form_options, element_id: element_id )
|
33
|
+
|
34
|
+
output += <<-END
|
35
|
+
<strong>Files:</strong>
|
36
|
+
|
37
|
+
<div id="files"></div>
|
38
|
+
|
39
|
+
<script>
|
40
|
+
(function() {
|
41
|
+
jQuery(function() {
|
42
|
+
return window.uploader = new AnacondaUploader({
|
43
|
+
limits: {
|
44
|
+
audio: 1,
|
45
|
+
video: 1,
|
46
|
+
resource: 1,
|
47
|
+
image: 1
|
48
|
+
},
|
49
|
+
element_id: "##{options[:element_id]}",
|
50
|
+
base_key: "#{options[:base_key]}",
|
51
|
+
allowed_types: [],
|
52
|
+
upload_details_container: "files",
|
53
|
+
upload_button_id: "upload",
|
54
|
+
upload_complete_post_url: "#{options[:form_options][:post_url]}",
|
55
|
+
upload_complete_form_to_fill: "#{options[:form_options][:form_el]}",
|
56
|
+
upload_automatically: "#{options[:form_options][:auto_upload]}",
|
57
|
+
resource: "#{instance.class.to_s.underscore}",
|
58
|
+
attribute: "#{options[:as]}"
|
59
|
+
});
|
60
|
+
});
|
61
|
+
|
62
|
+
}).call(this);
|
63
|
+
</script>
|
64
|
+
|
65
|
+
END
|
66
|
+
|
67
|
+
output.html_safe
|
68
|
+
end
|
69
|
+
|
70
|
+
class S3Uploader
|
71
|
+
def initialize(options)
|
72
|
+
@options = options.reverse_merge(
|
73
|
+
id: "fileupload",
|
74
|
+
aws_access_key_id: Anaconda.aws[:aws_access_key],
|
75
|
+
aws_secret_access_key: Anaconda.aws[:aws_secret_key],
|
76
|
+
bucket: Anaconda.aws[:aws_bucket],
|
77
|
+
acl: "public-read",
|
78
|
+
expiration: 10.hours.from_now,
|
79
|
+
max_file_size: 500.megabytes,
|
80
|
+
as: "file"
|
81
|
+
)
|
82
|
+
end
|
83
|
+
|
84
|
+
def form_options
|
85
|
+
{
|
86
|
+
id: @options[:id],
|
87
|
+
method: "post",
|
88
|
+
authenticity_token: false,
|
89
|
+
multipart: true,
|
90
|
+
data: {
|
91
|
+
post: @options[:post],
|
92
|
+
as: @options[:as],
|
93
|
+
base_key: base_key
|
94
|
+
}
|
95
|
+
}
|
96
|
+
end
|
97
|
+
|
98
|
+
def fields
|
99
|
+
{
|
100
|
+
:key => key,
|
101
|
+
:acl => @options[:acl],
|
102
|
+
:policy => policy,
|
103
|
+
:signature => signature,
|
104
|
+
"AWSAccessKeyId" => @options[:aws_access_key_id],
|
105
|
+
}
|
106
|
+
end
|
107
|
+
|
108
|
+
def key
|
109
|
+
@key ||= "#{base_key}/${filename}"
|
110
|
+
end
|
111
|
+
|
112
|
+
def base_key
|
113
|
+
@options[:base_key]
|
114
|
+
end
|
115
|
+
|
116
|
+
def url
|
117
|
+
"https://s3.amazonaws.com/#{@options[:bucket]}/"
|
118
|
+
end
|
119
|
+
|
120
|
+
def policy
|
121
|
+
Base64.encode64(policy_data.to_json).gsub("\n", "")
|
122
|
+
end
|
123
|
+
|
124
|
+
def policy_data
|
125
|
+
{
|
126
|
+
expiration: @options[:expiration],
|
127
|
+
conditions: [
|
128
|
+
#["starts-with", "$utf8", ""],
|
129
|
+
["starts-with", "$key", base_key],
|
130
|
+
["content-length-range", 1, @options[:max_file_size]],
|
131
|
+
{bucket: @options[:bucket]},
|
132
|
+
{acl: @options[:acl]}
|
133
|
+
]
|
134
|
+
}
|
135
|
+
end
|
136
|
+
|
137
|
+
def signature
|
138
|
+
Base64.encode64(
|
139
|
+
OpenSSL::HMAC.digest(
|
140
|
+
OpenSSL::Digest::Digest.new('sha1'),
|
141
|
+
@options[:aws_secret_access_key], policy
|
142
|
+
)
|
143
|
+
).gsub("\n", "")
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
data/lib/anaconda/railtie.rb
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
require 'rails/railtie'
|
2
2
|
require 'anaconda/upload_helper'
|
3
|
+
require 'anaconda/form_builder_helpers'
|
3
4
|
|
4
5
|
module Anaconda
|
5
6
|
class Railtie < ::Rails::Railtie
|
6
7
|
initializer "anaconda.upload_helper" do
|
7
8
|
ActionView::Base.send :include, UploadHelper
|
9
|
+
ActionView::Helpers::FormBuilder.send :include, FormBuilderHelpers
|
10
|
+
SimpleForm::FormBuilder.send :include, FormBuilderHelpers if SimpleForm::FormBuilder
|
8
11
|
end
|
9
12
|
end
|
10
13
|
end
|
@@ -20,9 +20,9 @@ module Anaconda
|
|
20
20
|
def initialize(options)
|
21
21
|
@options = options.reverse_merge(
|
22
22
|
id: "fileupload",
|
23
|
-
aws_access_key_id:
|
24
|
-
aws_secret_access_key:
|
25
|
-
bucket:
|
23
|
+
aws_access_key_id: Anaconda.aws[:aws_access_key],
|
24
|
+
aws_secret_access_key: Anaconda.aws[:aws_secret_key],
|
25
|
+
bucket: Anaconda.aws[:aws_bucket],
|
26
26
|
acl: "public-read",
|
27
27
|
expiration: 10.hours.from_now,
|
28
28
|
max_file_size: 500.megabytes,
|
@@ -57,11 +57,11 @@ module Anaconda
|
|
57
57
|
def key
|
58
58
|
@key ||= "#{base_key}/${filename}"
|
59
59
|
end
|
60
|
-
|
60
|
+
|
61
61
|
def base_key
|
62
62
|
@options[:base_key]
|
63
63
|
end
|
64
|
-
|
64
|
+
|
65
65
|
def url
|
66
66
|
"https://s3.amazonaws.com/#{@options[:bucket]}/"
|
67
67
|
end
|
data/lib/anaconda/version.rb
CHANGED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
module Anaconda
|
4
|
+
class InstallGenerator < ::Rails::Generators::Base
|
5
|
+
desc "Copy Anaconda default files"
|
6
|
+
source_root File.expand_path('../templates', __FILE__)
|
7
|
+
|
8
|
+
def copy_config
|
9
|
+
template "config/initializers/anaconda.rb"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
module Anaconda
|
4
|
+
class MigrationGenerator < ::Rails::Generators::NamedBase
|
5
|
+
desc "Create a migration for the given class name"
|
6
|
+
source_root File.expand_path('../templates', __FILE__)
|
7
|
+
|
8
|
+
argument :field_name, :type => :string, :default => "asset"
|
9
|
+
|
10
|
+
def create_migration_file
|
11
|
+
create_file "db/migrate/#{Time.now.strftime('%Y%m%d%H%M%S')}_anaconda_migration_for_#{file_name}.rb", <<-FILE
|
12
|
+
class AnacondaMigrationFor#{file_name.titlecase} < ActiveRecord::Migration
|
13
|
+
def change
|
14
|
+
add_column :#{plural_name}, :#{field_name}_filename, :string
|
15
|
+
add_column :#{plural_name}, :#{field_name}_file_path, :text
|
16
|
+
add_column :#{plural_name}, :#{field_name}_size, :integer
|
17
|
+
add_column :#{plural_name}, :#{field_name}_original_filename, :text
|
18
|
+
add_column :#{plural_name}, :#{field_name}_stored_privately, :boolean
|
19
|
+
add_column :#{plural_name}, :#{field_name}_type, :string
|
20
|
+
end
|
21
|
+
end
|
22
|
+
FILE
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: anaconda
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben McFadden
|
@@ -60,9 +60,14 @@ files:
|
|
60
60
|
- lib/anaconda/anaconda.rb
|
61
61
|
- lib/anaconda/anaconda_for.rb
|
62
62
|
- lib/anaconda/engine.rb
|
63
|
+
- lib/anaconda/form_builder_helpers.rb
|
63
64
|
- lib/anaconda/railtie.rb
|
64
65
|
- lib/anaconda/upload_helper.rb
|
65
66
|
- lib/anaconda/version.rb
|
67
|
+
- lib/generators/anaconda/USAGE
|
68
|
+
- lib/generators/anaconda/install_generator.rb
|
69
|
+
- lib/generators/anaconda/migration_generator.rb
|
70
|
+
- lib/generators/anaconda/templates/config/initializers/anaconda.rb
|
66
71
|
- test/helper.rb
|
67
72
|
- test/test_anaconda.rb
|
68
73
|
- vendor/assets/javascripts/.gitkeep
|