activeadmin_images 0.0.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,116 @@
1
+ /* Have ideas for improving this CSS for the general community? Submit your changes at: https://github.com/Valums-File-Uploader/file-uploader */
2
+ .qq-uploader {
3
+ position: relative;
4
+ width: 100%;
5
+ }
6
+ .qq-upload-button {
7
+ display: block;
8
+ /*or inline-block*/
9
+ width: 105px;
10
+ padding: 7px 0;
11
+ text-align: center;
12
+ background: #880000;
13
+ border-bottom: 1px solid #DDD;
14
+ color: #FFF;
15
+ }
16
+ .qq-upload-button-hover {
17
+ background: #CC0000;
18
+ }
19
+ .qq-upload-button-focus {
20
+ outline: 1px dotted #000000;
21
+ }
22
+ .qq-upload-drop-area, .qq-upload-extra-drop-area {
23
+ position: absolute;
24
+ top: 0;
25
+ left: 0;
26
+ width: 100%;
27
+ height: 100%;
28
+ min-height: 30px;
29
+ z-index: 2;
30
+ background: #FF9797;
31
+ text-align: center;
32
+ }
33
+ .qq-upload-drop-area span {
34
+ display: block;
35
+ position: absolute;
36
+ top: 50%;
37
+ width: 100%;
38
+ margin-top: -8px;
39
+ font-size: 16px;
40
+ }
41
+ .qq-upload-extra-drop-area {
42
+ position: relative;
43
+ margin-top: 50px;
44
+ font-size: 16px;
45
+ padding-top: 30px;
46
+ height: 20px;
47
+ min-height: 40px;
48
+ }
49
+ .qq-upload-drop-area-active {
50
+ background: #FF7171;
51
+ }
52
+ .qq-upload-list {
53
+ margin: 0;
54
+ padding: 0;
55
+ list-style: none;
56
+ }
57
+ .qq-upload-list li {
58
+ margin: 0;
59
+ padding: 9px;
60
+ line-height: 15px;
61
+ font-size: 16px;
62
+ background-color: #FFF0BD;
63
+ }
64
+ .qq-upload-file, .qq-upload-spinner, .qq-upload-size, .qq-upload-cancel, .qq-upload-failed-text {
65
+ margin-right: 12px;
66
+ }
67
+ .qq-upload-file {
68
+ }
69
+ .qq-upload-spinner {
70
+ display: inline-block;
71
+ background: url("loading.gif");
72
+ width: 15px;
73
+ height: 15px;
74
+ vertical-align: text-bottom;
75
+ }
76
+ .qq-upload-size, .qq-upload-cancel {
77
+ font-size: 12px;
78
+ font-weight: normal;
79
+ }
80
+ .qq-upload-failed-text {
81
+ display: none;
82
+ }
83
+ .qq-upload-fail .qq-upload-failed-text {
84
+ display: inline;
85
+ }
86
+ .qq-upload-list li.qq-upload-success {
87
+ background-color: #5DA30C;
88
+ color: #FFFFFF;
89
+ /*vertical-align: middle;*/
90
+ }
91
+
92
+ .qq-upload-list li.qq-upload-success img{
93
+ vertical-align: middle;
94
+ }
95
+
96
+
97
+ .qq-image-name, .qq-save-name{
98
+ display: inline;
99
+ }
100
+
101
+ .qq-id, .qq-params{
102
+ display: none;
103
+ }
104
+
105
+ .qq-upload-list li.qq-upload-success .qq-image-name, .qq-upload-list li.qq-upload-success .qq-save-name {
106
+ display: none;
107
+ }
108
+
109
+ .qq-new-image{
110
+ display: inline;
111
+ }
112
+
113
+ .qq-upload-list li.qq-upload-fail {
114
+ background-color: #D60000;
115
+ color: #FFFFFF;
116
+ }
@@ -1,8 +1,10 @@
1
1
  Description:
2
- Explain the generator
2
+ Generates model for images and registers in active admin
3
3
 
4
4
  Example:
5
- rails generate install Thing
5
+ rails generate install Image
6
6
 
7
7
  This will create:
8
- what/will/it/create
8
+ app/model/image.rb
9
+ db/migration/create_images.rb
10
+ app/admin/image.rb
@@ -1,3 +1,27 @@
1
- class ActiveAdmin::Images::InstallGenerator < Rails::Generators::NamedBase
2
- source_root File.expand_path('../templates', __FILE__)
1
+ require 'rails/generators/active_record'
2
+
3
+ module ActiveAdmin
4
+ module Images
5
+ class InstallGenerator < ActiveRecord::Generators::Base
6
+ source_root File.expand_path('../templates', __FILE__)
7
+
8
+ def create_model
9
+ template 'model.rb', "app/models/#{name.gsub('/', '_').underscore}.rb"
10
+ end
11
+
12
+ def manifest
13
+ migration_template 'migration.rb', "db/migrate/create_table_#{name.underscore.gsub('/', '_').pluralize}.rb"
14
+ end
15
+
16
+ def create_register
17
+ template 'register.rb', "app/admin/#{name.gsub('/', '_').underscore}.rb"
18
+ end
19
+
20
+ def create_images_form
21
+ template 'form.rb', "app/views/admin/#{name.underscore.gsub('/', '_').pluralize}/_add_images.html.erb"
22
+ end
23
+
24
+
25
+ end
26
+ end
3
27
  end
@@ -24,3 +24,36 @@ Connecting to database specified by database.yml
24
24
  Connecting to database specified by database.yml
25
25
   (0.4ms) begin transaction
26
26
   (0.3ms) rollback transaction
27
+ Connecting to database specified by database.yml
28
+  (17.3ms) begin transaction
29
+  (0.1ms) rollback transaction
30
+ Connecting to database specified by database.yml
31
+  (0.4ms) begin transaction
32
+  (0.1ms) rollback transaction
33
+ Connecting to database specified by database.yml
34
+  (0.4ms) begin transaction
35
+  (0.1ms) rollback transaction
36
+ Connecting to database specified by database.yml
37
+  (0.5ms) begin transaction
38
+  (0.1ms) rollback transaction
39
+ Connecting to database specified by database.yml
40
+  (0.4ms) begin transaction
41
+  (0.1ms) rollback transaction
42
+ Connecting to database specified by database.yml
43
+  (0.4ms) begin transaction
44
+  (0.2ms) rollback transaction
45
+ Connecting to database specified by database.yml
46
+  (0.4ms) begin transaction
47
+  (0.3ms) rollback transaction
48
+ Connecting to database specified by database.yml
49
+  (0.4ms) begin transaction
50
+  (0.2ms) rollback transaction
51
+ Connecting to database specified by database.yml
52
+  (0.4ms) begin transaction
53
+  (0.1ms) rollback transaction
54
+ Connecting to database specified by database.yml
55
+  (0.4ms) begin transaction
56
+  (0.1ms) rollback transaction
57
+ Connecting to database specified by database.yml
58
+  (0.4ms) begin transaction
59
+  (0.1ms) rollback transaction
@@ -0,0 +1,16 @@
1
+ require 'test_helper'
2
+ require 'generators/active_admin/images/install/install_generator'
3
+
4
+ class InstalGeneratorTest < Rails::Generators::TestCase
5
+ tests ActiveAdmin::Images::InstallGenerator
6
+ destination File.expand_path("../../tmp", __FILE__)
7
+ setup :prepare_destination
8
+
9
+ test 'all files are properly created' do
10
+ run_generator %w(CustomImage)
11
+ assert_file 'app/models/custom_image.rb'
12
+ assert_file 'app/admin/custom_image.rb'
13
+ assert_file 'app/views/admin/custom_images/_add_images.html.erb'
14
+ end
15
+
16
+ end
@@ -0,0 +1,57 @@
1
+ ActiveAdmin.register CustomImage do
2
+ actions :all, except: [:edit]
3
+
4
+ collection_action :add_files, method: :post do
5
+ @custom_image = CustomImage.new(attachment: @raw_file)
6
+ if @custom_image.save!
7
+ render json: { success: true, :url => @custom_image.attachment.url(:thumb), :id => @custom_image.id }
8
+ else
9
+ render json: { success: false }
10
+ end
11
+ end
12
+
13
+ controller do
14
+ before_filter :parse_raw_upload, only: [:add_files]
15
+
16
+ private
17
+ def parse_raw_upload
18
+ if env['HTTP_X_FILE_UPLOAD'] == 'true'
19
+ @raw_file = env['rack.input']
20
+ @raw_file.class.class_eval { attr_accessor :original_filename, :content_type }
21
+ @raw_file.original_filename = env['HTTP_X_FILE_NAME']
22
+ @raw_file.content_type = env['HTTP_X_MIME_TYPE']
23
+ if @raw_file.class.name == 'Unicorn::TeeInput'
24
+ @raw_file = Paperclip::StringioAdapter.new(@raw_file)
25
+ end
26
+ end
27
+ end
28
+ end
29
+
30
+
31
+ index do
32
+ selectable_column
33
+ column :title do |image|
34
+ link_to image.attachment_file_name, admin_custom_image_path(image)
35
+ end
36
+
37
+ column :preview do |image|
38
+ image_tag image.attachment.url(:thumb)
39
+ end
40
+ end
41
+
42
+ show do
43
+ attributes_table do
44
+ row :title do |image|
45
+ image.attachment_file_name
46
+ end
47
+ row :preview do |image|
48
+ image_tag image.attachment.url(:original)
49
+ end
50
+ end
51
+ end
52
+
53
+
54
+
55
+
56
+ form partial: 'add_images'
57
+ end
@@ -0,0 +1,12 @@
1
+ class CustomImage < ActiveRecord::Base
2
+
3
+ attr_accessible :attachment
4
+
5
+ has_attached_file :attachment,
6
+ :styles => {
7
+ :thumb => ["50x50#", :png]
8
+ },
9
+ :path => ':rails_root/public/system/images/:style/:filename',
10
+ :url => '/system/images/:style/:filename'
11
+
12
+ end
@@ -0,0 +1,9 @@
1
+ <div id="my_file_uploader"></div>
2
+ <script type="text/javascript">
3
+ var uploader = new qq.FileUploader({
4
+ element: document.getElementById('my_file_uploader'),
5
+ action: "<%= add_files_admin_custom_images_path %>",
6
+ params: { "authenticity_token": "<%= form_authenticity_token %>" },
7
+ customHeaders: { "X-File-Upload": "true" }
8
+ });
9
+ </script>
@@ -0,0 +1,8 @@
1
+ class CreateTableCustomImages < ActiveRecord::Migration
2
+ def change
3
+ create_table :custom_images do |t|
4
+ t.attachment :attachment
5
+ t.timestamps
6
+ end
7
+ end
8
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activeadmin_images
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-11-28 00:00:00.000000000 Z
12
+ date: 2013-12-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &84054180 !ruby/object:Gem::Requirement
16
+ requirement: &75733560 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,8 +21,19 @@ dependencies:
21
21
  version: 3.2.13
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *84054180
25
- description: Description of ActiveadminImages.
24
+ version_requirements: *75733560
25
+ - !ruby/object:Gem::Dependency
26
+ name: activeadmin
27
+ requirement: &75733070 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *75733070
36
+ description: Active Admin plugin for generate the model of image
26
37
  email:
27
38
  - mk@kernel-corp.com
28
39
  executables: []
@@ -33,20 +44,22 @@ files:
33
44
  - lib/activeadmin_images/version.rb
34
45
  - lib/activeadmin_images/engine.rb
35
46
  - lib/tasks/activeadmin_images_tasks.rake
47
+ - lib/assets/javascripts/fileuploader.js
48
+ - lib/assets/stylesheets/fileuploader.css
36
49
  - lib/generators/active_admin/images/install/USAGE
37
50
  - lib/generators/active_admin/images/install/install_generator.rb
38
- - lib/generators/active_admin/images/model/USAGE
39
- - lib/generators/active_admin/images/model/templates/migration.rb
40
- - lib/generators/active_admin/images/model/templates/model.rb
41
- - lib/generators/active_admin/images/model/templates/form.rb
42
- - lib/generators/active_admin/images/model/templates/register.rb
43
- - lib/generators/active_admin/images/model/model_generator.rb
51
+ - lib/generators/active_admin/images/install/templates/migration.rb
52
+ - lib/generators/active_admin/images/install/templates/model.rb
53
+ - lib/generators/active_admin/images/install/templates/form.rb
54
+ - lib/generators/active_admin/images/install/templates/register.rb
44
55
  - lib/activeadmin_images.rb
45
56
  - MIT-LICENSE
46
57
  - Rakefile
47
58
  - README.rdoc
48
- - test/tmp/app/model/custom_image
49
- - test/tmp/app/model/custom_image.rb
59
+ - test/tmp/db/migrate/20131129135954_create_table_custom_images.rb
60
+ - test/tmp/app/admin/custom_image.rb
61
+ - test/tmp/app/models/custom_image.rb
62
+ - test/tmp/app/views/admin/custom_images/_add_images.html.erb
50
63
  - test/test_helper.rb
51
64
  - test/dummy/config.ru
52
65
  - test/dummy/config/routes.rb
@@ -81,7 +94,7 @@ files:
81
94
  - test/dummy/app/assets/stylesheets/application.css
82
95
  - test/dummy/app/views/layouts/application.html.erb
83
96
  - test/dummy/app/helpers/application_helper.rb
84
- - test/generators/model_generator_test.rb
97
+ - test/generators/instal_generator_test.rb
85
98
  - test/activeadmin_images_test.rb
86
99
  - test/integration/navigation_test.rb
87
100
  homepage: https://github.com/KernelCorp/activeadmin_images.git
@@ -107,10 +120,12 @@ rubyforge_project:
107
120
  rubygems_version: 1.8.11
108
121
  signing_key:
109
122
  specification_version: 3
110
- summary: Summary of ActiveadminImages.
123
+ summary: Active Admin plugin for generate the model of image
111
124
  test_files:
112
- - test/tmp/app/model/custom_image
113
- - test/tmp/app/model/custom_image.rb
125
+ - test/tmp/db/migrate/20131129135954_create_table_custom_images.rb
126
+ - test/tmp/app/admin/custom_image.rb
127
+ - test/tmp/app/models/custom_image.rb
128
+ - test/tmp/app/views/admin/custom_images/_add_images.html.erb
114
129
  - test/test_helper.rb
115
130
  - test/dummy/config.ru
116
131
  - test/dummy/config/routes.rb
@@ -145,7 +160,7 @@ test_files:
145
160
  - test/dummy/app/assets/stylesheets/application.css
146
161
  - test/dummy/app/views/layouts/application.html.erb
147
162
  - test/dummy/app/helpers/application_helper.rb
148
- - test/generators/model_generator_test.rb
163
+ - test/generators/instal_generator_test.rb
149
164
  - test/activeadmin_images_test.rb
150
165
  - test/integration/navigation_test.rb
151
166
  has_rdoc:
@@ -1,8 +0,0 @@
1
- Description:
2
- Explain the generator
3
-
4
- Example:
5
- rails generate model Thing
6
-
7
- This will create:
8
- what/will/it/create
@@ -1,27 +0,0 @@
1
- require 'rails/generators/active_record'
2
-
3
- module ActiveAdmin
4
- module Images
5
- class ModelGenerator < ActiveRecord::Generators::Base
6
- source_root File.expand_path('../templates', __FILE__)
7
-
8
- def create_model
9
- template 'model.rb', "app/models/#{name.gsub('/', '_').underscore}.rb"
10
- end
11
-
12
- def manifest
13
- migration_template 'migration.rb', "db/migrate/create_table_#{name.underscore.gsub('/', '_').pluralize}.rb"
14
- end
15
-
16
- def create_register
17
- template 'register.rb', "app/admin/#{name.gsub('/', '_').underscore}.rb"
18
- end
19
-
20
- def create_images_form
21
- template 'form.rb', "app/views/admin/#{name.underscore.gsub('/', '_').pluralize}/_add_images.html.erb"
22
- end
23
-
24
-
25
- end
26
- end
27
- end
@@ -1,14 +0,0 @@
1
- require 'test_helper'
2
- require 'generators/active_admin/images/model/model_generator'
3
-
4
- class ModelGeneratorTest < Rails::Generators::TestCase
5
- tests ActiveAdmin::Images::ModelGenerator
6
- destination File.expand_path("../../tmp", __FILE__)
7
- setup :prepare_destination
8
-
9
- test 'all files are properly created' do
10
- run_generator %w(CustomImage)
11
- assert_file 'app/models/custom_image'
12
- end
13
-
14
- end
@@ -1,7 +0,0 @@
1
- class CustomImage < ActiveRecord::Base
2
-
3
- attr_accessible attachment
4
-
5
- has_attached_file attachment
6
-
7
- end
@@ -1,7 +0,0 @@
1
- class CustomImage < ActiveRecord::Base
2
-
3
- attr_accessible attachment
4
-
5
- has_attached_file attachment
6
-
7
- end