assetable 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +15 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +181 -0
  4. data/Rakefile +23 -0
  5. data/app/assets/images/assetable/icon-upload.png +0 -0
  6. data/app/assets/images/assetable/icons/icon-ai.png +0 -0
  7. data/app/assets/images/assetable/icons/icon-css.png +0 -0
  8. data/app/assets/images/assetable/icons/icon-desmos.png +0 -0
  9. data/app/assets/images/assetable/icons/icon-doc.png +0 -0
  10. data/app/assets/images/assetable/icons/icon-document.png +0 -0
  11. data/app/assets/images/assetable/icons/icon-docx.png +0 -0
  12. data/app/assets/images/assetable/icons/icon-eps.png +0 -0
  13. data/app/assets/images/assetable/icons/icon-flash.png +0 -0
  14. data/app/assets/images/assetable/icons/icon-html.png +0 -0
  15. data/app/assets/images/assetable/icons/icon-jpg.png +0 -0
  16. data/app/assets/images/assetable/icons/icon-js.png +0 -0
  17. data/app/assets/images/assetable/icons/icon-mov.png +0 -0
  18. data/app/assets/images/assetable/icons/icon-mp3.png +0 -0
  19. data/app/assets/images/assetable/icons/icon-mp4.png +0 -0
  20. data/app/assets/images/assetable/icons/icon-pdf.png +0 -0
  21. data/app/assets/images/assetable/icons/icon-php.png +0 -0
  22. data/app/assets/images/assetable/icons/icon-png.png +0 -0
  23. data/app/assets/images/assetable/icons/icon-ppt.png +0 -0
  24. data/app/assets/images/assetable/icons/icon-pptx.png +0 -0
  25. data/app/assets/images/assetable/icons/icon-txt.png +0 -0
  26. data/app/assets/images/assetable/icons/icon-xls.png +0 -0
  27. data/app/assets/images/assetable/icons/icon-xlsx.png +0 -0
  28. data/app/assets/images/assetable/icons/icon-xml.png +0 -0
  29. data/app/assets/javascripts/assetable/asset_gallery.js.coffee +74 -0
  30. data/app/assets/javascripts/assetable/assetable_uploader.js.coffee +204 -0
  31. data/app/assets/javascripts/assetable/gallery.js.coffee +33 -0
  32. data/app/assets/javascripts/assetable/uploader.js.coffee +10 -0
  33. data/app/assets/javascripts/vendor/bootstrap-modal.js +246 -0
  34. data/app/assets/javascripts/vendor/jquery-ui-1.10.3.custom.js +2252 -0
  35. data/app/assets/stylesheets/assetable/_assetable.css.sass +9 -0
  36. data/app/assets/stylesheets/assetable/_bootstrap.css.sass +5 -0
  37. data/app/assets/stylesheets/assetable/components/_buttons.css.sass +99 -0
  38. data/app/assets/stylesheets/assetable/components/_close.css.sass +28 -0
  39. data/app/assets/stylesheets/assetable/components/_forms.css.sass +219 -0
  40. data/app/assets/stylesheets/assetable/components/_gallery.css.sass +118 -0
  41. data/app/assets/stylesheets/assetable/components/_modals.css.sass +116 -0
  42. data/app/assets/stylesheets/assetable/components/_progress.css.sass +91 -0
  43. data/app/assets/stylesheets/assetable/components/_uploader.css.sass +175 -0
  44. data/app/assets/stylesheets/assetable/core/_mixins.css.sass +754 -0
  45. data/app/assets/stylesheets/assetable/core/_utilities.css.sass +5 -0
  46. data/app/assets/stylesheets/assetable/core/_variables.css.sass +165 -0
  47. data/app/controllers/assetable/assets_controller.rb +38 -0
  48. data/app/controllers/assetable/external_services_controller.rb +36 -0
  49. data/app/models/asset.rb +53 -0
  50. data/app/models/asset_attachment.rb +4 -0
  51. data/app/models/document.rb +5 -0
  52. data/app/models/external_service.rb +14 -0
  53. data/app/models/gallery.rb +7 -0
  54. data/app/models/image.rb +5 -0
  55. data/app/models/video.rb +5 -0
  56. data/app/uploaders/document_uploader.rb +50 -0
  57. data/app/uploaders/image_uploader.rb +67 -0
  58. data/app/uploaders/video_uploader.rb +40 -0
  59. data/app/views/assetable/assets/_asset.html.haml +20 -0
  60. data/app/views/assetable/assets/_gallery.html.haml +12 -0
  61. data/app/views/assetable/external_services/new.html.haml +31 -0
  62. data/config/initializers/carrierwave.rb +6 -0
  63. data/config/initializers/gallery_input.rb +37 -0
  64. data/config/initializers/uploader_input.rb +80 -0
  65. data/config/routes.rb +8 -0
  66. data/db/migrate/20131122232735_create_assets.rb +19 -0
  67. data/db/migrate/20131123172825_create_asset_attachments.rb +15 -0
  68. data/db/migrate/20131125200943_create_galleries.rb +14 -0
  69. data/lib/assetable.rb +18 -0
  70. data/lib/assetable/config.rb +23 -0
  71. data/lib/assetable/core.rb +41 -0
  72. data/lib/assetable/engine.rb +15 -0
  73. data/lib/assetable/version.rb +3 -0
  74. data/lib/tasks/assetable_tasks.rake +4 -0
  75. data/test/fixtures/asset_attachments.yml +11 -0
  76. data/test/fixtures/assets.yml +11 -0
  77. data/test/fixtures/images.yml +11 -0
  78. data/test/fixtures/videos.yml +11 -0
  79. data/test/models/asset_attachment_test.rb +7 -0
  80. data/test/models/asset_test.rb +7 -0
  81. data/test/models/image_test.rb +7 -0
  82. data/test/models/video_test.rb +7 -0
  83. metadata +371 -0
@@ -0,0 +1,5 @@
1
+ .pull-right
2
+ float: right
3
+
4
+ .pull-left
5
+ float: left
@@ -0,0 +1,165 @@
1
+ // Defaults
2
+ // -------------------------
3
+
4
+ $brand-primary: #428bca !default
5
+ $brand-success: #5cb85c !default
6
+ $brand-warning: #f0ad4e !default
7
+ $brand-danger: #d9534f !default
8
+ $brand-info: #5bc0de !default
9
+
10
+ $link-color: $brand-primary !default
11
+ $link-hover-color: darken($link-color, 15%) !default
12
+
13
+ $font-size-base: 14px !default
14
+ $line-height-base: 1.42857 !default
15
+ $line-height-computed: floor($font-size-base * $line-height-base) !default
16
+
17
+ $border-radius-base: 4px !default
18
+ $border-radius-large: 6px !default
19
+
20
+ $padding-base-vertical: 6px !default
21
+ $padding-base-horizontal: 12px !default
22
+
23
+ // Grays
24
+ // -------------------------
25
+
26
+ $gray-darker: lighten(#000, 13.5%) !default
27
+ $gray-dark: lighten(#000, 20%) !default
28
+ $gray: lighten(#000, 33.5%) !default
29
+ $gray-light: lighten(#000, 60%) !default
30
+ $gray-lighter: lighten(#000, 93.5%) !default
31
+
32
+
33
+
34
+ // Uploader defaults
35
+ // -------------------------
36
+
37
+ $droppable-bg: #feefd6 !default
38
+ $uploader-width: 200px !default
39
+ $uploader-padding: 20px !default
40
+ $uploader-border-radius: 3px !default
41
+ $uploader-background-color: transparent !default
42
+ $uploader-border: 1px dotted #ddd !default
43
+
44
+ // Images
45
+ $uploader-image: image-url('assetable/icon-upload.png') !default
46
+
47
+ // Text attributes
48
+ $uploader-text-color: #555 !default
49
+ $uploader-link-color: #3498db !default
50
+
51
+ // Gallery
52
+ $assetable-gallery-footer-height: 55px !default
53
+ $assetable-gallery-header-height: 55px !default
54
+
55
+
56
+
57
+ // Progress bars
58
+ // -------------------------
59
+
60
+ $brand-primary: #428bca !default
61
+ $brand-success: #5cb85c !default
62
+ $brand-warning: #f0ad4e !default
63
+ $brand-danger: #d9534f !default
64
+ $brand-info: #5bc0de !default
65
+
66
+ $progress-bg: whitesmoke !default
67
+ $progress-bar-color: #333 !default
68
+ $progress-bar-height: 20px !default
69
+
70
+ $progress-bar-bg: $brand-primary !default
71
+ $progress-bar-success-bg: $brand-success !default
72
+ $progress-bar-warning-bg: $brand-warning !default
73
+ $progress-bar-danger-bg: $brand-danger !default
74
+ $progress-bar-info-bg: $brand-info !default
75
+
76
+ $progress-bar-border-radius: 2px !default
77
+ $progress-bar-font-size: $font-size-base !default
78
+
79
+
80
+
81
+
82
+ // Modals
83
+ // -------------------------
84
+
85
+ $zindex-modal-background: 1040 !default
86
+ $zindex-modal: 1050 !default
87
+
88
+ $modal-inner-padding: 20px !default
89
+
90
+ $modal-title-padding: 15px !default
91
+ $modal-title-line-height: $line-height-base !default
92
+
93
+ $modal-content-bg: white !default
94
+ $modal-content-border-color: rgba(0, 0, 0, 0.2) !default
95
+ $modal-content-fallback-border-color: #999999 !default
96
+
97
+ $modal-backdrop-bg: black !default
98
+ $modal-header-border-color: #e5e5e5 !default
99
+ $modal-footer-border-color: $modal-header-border-color !default
100
+
101
+
102
+
103
+ // Close
104
+ // ------------------------
105
+ $close-color: black !default
106
+ $close-font-weight: bold !default
107
+ $close-text-shadow: 0 1px 0 white !default
108
+
109
+
110
+
111
+
112
+ // Forms
113
+ // -------------------------
114
+
115
+ $input-bg: white !default
116
+ $input-bg-disabled: $gray-lighter !default
117
+
118
+ $input-color: $gray !default
119
+ $input-border: #cccccc !default
120
+ $input-border-radius: $border-radius-base !default
121
+ $input-border-focus: #66afe9 !default
122
+
123
+ $input-color-placeholder: $gray-light !default
124
+
125
+ $input-height-base: $line-height-computed + $padding-base-vertical * 2 + 2 !default
126
+
127
+ $legend-color: $gray-dark !default
128
+ $legend-border-color: #e5e5e5 !default
129
+
130
+ $input-group-addon-bg: $gray-lighter !default
131
+ $input-group-addon-border-color: $input-border !default
132
+
133
+
134
+
135
+
136
+ // Buttons
137
+ // -------------------------
138
+
139
+ $btn-font-weight: normal !default
140
+
141
+ $btn-default-color: #333333 !default
142
+ $btn-default-bg: white !default
143
+ $btn-default-border: #cccccc !default
144
+
145
+ $btn-primary-color: white !default
146
+ $btn-primary-bg: $brand-primary !default
147
+ $btn-primary-border: darken($btn-primary-bg, 5%) !default
148
+
149
+ $btn-success-color: white !default
150
+ $btn-success-bg: $brand-success !default
151
+ $btn-success-border: darken($btn-success-bg, 5%) !default
152
+
153
+ $btn-warning-color: white !default
154
+ $btn-warning-bg: $brand-warning !default
155
+ $btn-warning-border: darken($btn-warning-bg, 5%) !default
156
+
157
+ $btn-danger-color: white !default
158
+ $btn-danger-bg: $brand-danger !default
159
+ $btn-danger-border: darken($btn-danger-bg, 5%) !default
160
+
161
+ $btn-info-color: white !default
162
+ $btn-info-bg: $brand-info !default
163
+ $btn-info-border: darken($btn-info-bg, 5%) !default
164
+
165
+ $btn-link-disabled-color: $gray-light !default
@@ -0,0 +1,38 @@
1
+ class Assetable::AssetsController < ActionController::Base
2
+
3
+ respond_to :html, :json
4
+
5
+ def index
6
+ @assets = Asset.page(params[:page]).per(20)
7
+ render json: { success: true, html: render_to_string(partial: "assetable/assets/gallery", locals: {assets: @assets, fieldname: params[:fieldname]})}
8
+ end
9
+
10
+ # Create a new asset
11
+ def create
12
+ # Get the content type
13
+ content_type = params[:file].content_type
14
+ asset_params = {name: params[:file].original_filename, filename: params[:file]}
15
+
16
+ puts "params:: #{params.inspect}"
17
+ puts "content_type:: #{content_type}"
18
+
19
+ # Create the appropriate model
20
+ if content_type.split("/").first == "image"
21
+ @asset = Image.new(asset_params)
22
+ elsif content_type.split("/").first == "video"
23
+ @asset = Video.new(asset_params)
24
+ elsif content_type.split("/").first == "application"
25
+ @asset = Document.new(asset_params)
26
+ end
27
+
28
+ puts "@asset:: #{@asset.inspect}"
29
+
30
+ # Return
31
+ if @asset.errors.empty? and @asset.save
32
+ render json: { success: true, html: render_to_string(partial: "assetable/assets/asset", locals: { asset: @asset, fieldname: params[:fieldname]})}
33
+ else
34
+ render json: { status: "error", errors: @asset.errors }
35
+ end
36
+ end
37
+
38
+ end
@@ -0,0 +1,36 @@
1
+ class Assetable::ExternalServicesController < ActionController::Base
2
+
3
+ respond_to :html, :json
4
+
5
+ # def index
6
+ # @assets = Asset.page(params[:page]).per(20)
7
+ # render json: { success: true, html: render_to_string(partial: "assetable/assets/gallery", locals: {assets: @assets, fieldname: params[:fieldname]})}
8
+ # end
9
+
10
+ # New template
11
+ def new
12
+ @external_service = ExternalService.new
13
+ end
14
+
15
+ # Create a new external service asset
16
+ def create
17
+ @external_service = ExternalService.new(permitted_params)
18
+
19
+ if @external_service.errors.empty? and @external_service.save
20
+ render json: { success: true, html: render_to_string(partial: "assetable/assets/asset", locals: { asset: @external_service, fieldname: params[:fieldname]})}
21
+ else
22
+ puts "errors:: #{@external_service.errors.full_messages}"
23
+ render json: { status: "error", errors: @external_service.errors.full_messages, html: render_to_string(:new) }
24
+ end
25
+ end
26
+
27
+ # Permitted params for the model
28
+ def permitted_params
29
+ params.require(:external_service).permit(
30
+ :name,
31
+ :body,
32
+ :content_type
33
+ )
34
+ end
35
+
36
+ end
@@ -0,0 +1,53 @@
1
+ class Asset < ActiveRecord::Base
2
+
3
+ has_many :asset_attachments, :as => :assetable, :dependent => :destroy
4
+ has_many :assetable, :through => :asset_attachments
5
+
6
+ before_save :update_asset_attributes
7
+
8
+
9
+
10
+ # File Type Helpers
11
+ # ---------------------------------------------------------------------
12
+
13
+ # Is the asset a image?
14
+ def image?
15
+ self.type == "Image"
16
+ end
17
+
18
+ # Is the asset a document?
19
+ def document?
20
+ self.type == "Document"
21
+ end
22
+
23
+ # Is the asset a video?
24
+ def video?
25
+ self.type == "Video"
26
+ end
27
+
28
+ def external_service?
29
+ self.type == "ExternalService"
30
+ end
31
+
32
+
33
+ # File meta and helpers
34
+ # ---------------------------------------------------------------------
35
+
36
+ # Get the file type extension from the filename
37
+ def extension
38
+ filename = File.extname(self.filename.to_s)
39
+ filename[0] = '' # remove the dot, i.e. (.docx or .pptx)
40
+ filename
41
+ end
42
+
43
+ # Add some custom attributes to the asset
44
+ def update_asset_attributes
45
+ if !self.external_service? and self.present? and self.changed?
46
+ self.content_type = self.filename.file.content_type
47
+ self.file_size = self.filename.file.size
48
+ self.width, self.height = `identify -format "%wx%h" #{self.filename.file.path}`.split(/x/) unless self.document?
49
+ self.checksum = Digest::MD5.file(self.filename.file.path).to_s
50
+ end
51
+ end
52
+
53
+ end
@@ -0,0 +1,4 @@
1
+ class AssetAttachment < ActiveRecord::Base
2
+ belongs_to :asset
3
+ belongs_to :assetable, polymorphic: true
4
+ end
@@ -0,0 +1,5 @@
1
+ class Document < Asset
2
+
3
+ mount_uploader :filename, DocumentUploader
4
+
5
+ end
@@ -0,0 +1,14 @@
1
+ class ExternalService < Asset
2
+
3
+ validates_presence_of :name, :body
4
+
5
+ # G
6
+ def self.possible_content_types
7
+ if user_defined_document_types = Assetable.external_document_types
8
+ return user_defined_document_types
9
+ else
10
+ return ["iFrame", "Third Party API"]
11
+ end
12
+ end
13
+
14
+ end
@@ -0,0 +1,7 @@
1
+ class Gallery < ActiveRecord::Base
2
+
3
+ belongs_to :galleryable, polymorphic: true
4
+ has_many :asset_attachments, as: :assetable, dependent: :destroy
5
+ has_many :assets, through: :asset_attachments
6
+
7
+ end
@@ -0,0 +1,5 @@
1
+ class Image < Asset
2
+
3
+ mount_uploader :filename, ImageUploader
4
+
5
+ end
@@ -0,0 +1,5 @@
1
+ class Video < Asset
2
+
3
+ mount_uploader :filename, VideoUploader
4
+
5
+ end
@@ -0,0 +1,50 @@
1
+ # encoding: utf-8
2
+
3
+ class DocumentUploader < CarrierWave::Uploader::Base
4
+
5
+ # Choose what kind of storage to use for this uploader:
6
+ storage Assetable.storage
7
+
8
+ # Override the directory where uploaded files will be stored.
9
+ # This is a sensible default for uploaders that are meant to be mounted:
10
+ def store_dir
11
+ if model.present?
12
+ "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
13
+ else
14
+ "uploads/#{mounted_as}"
15
+ end
16
+ end
17
+
18
+ # Provide a default URL as a default if there hasn't been a file uploaded:
19
+ # def default_url
20
+ # # For Rails 3.1+ asset pipeline compatibility:
21
+ # # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
22
+ #
23
+ # "/images/fallback/" + [version_name, "default.png"].compact.join('_')
24
+ # end
25
+
26
+ # Process files as they are uploaded:
27
+ # process :scale => [200, 300]
28
+ #
29
+ # def scale(width, height)
30
+ # # do something
31
+ # end
32
+
33
+ # Create different versions of your uploaded files:
34
+ # version :thumb do
35
+ # process :scale => [50, 50]
36
+ # end
37
+
38
+ # Add a white list of extensions which are allowed to be uploaded.
39
+ # For images you might use something like this:
40
+ # def extension_white_list
41
+ # %w(jpg jpeg gif png)
42
+ # end
43
+
44
+ # Override the filename of the uploaded files:
45
+ # Avoid using model.id or version_name here, see uploader/store.rb for details.
46
+ # def filename
47
+ # "something.jpg" if original_filename
48
+ # end
49
+
50
+ end
@@ -0,0 +1,67 @@
1
+ # encoding: utf-8
2
+
3
+ class ImageUploader < CarrierWave::Uploader::Base
4
+
5
+ include CarrierWave::MimeTypes
6
+ # Include RMagick or MiniMagick support:
7
+ include CarrierWave::RMagick
8
+
9
+ # Choose what kind of storage to use for this uploader:
10
+ storage Assetable.storage
11
+
12
+ # More reliable content types
13
+ process :set_content_type
14
+
15
+ # Override the directory where uploaded files will be stored.
16
+ # This is a sensible default for uploaders that are meant to be mounted:
17
+ def store_dir
18
+ if model.present?
19
+ "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
20
+ else
21
+ "uploads/#{mounted_as}"
22
+ end
23
+ end
24
+
25
+ # Add a white list of extensions which are allowed to be uploaded.
26
+ # For images you might use something like this:
27
+ def extension_white_list
28
+ %w(jpg jpeg gif png)
29
+ end
30
+
31
+ # Provide a default URL as a default if there hasn't been a file uploaded:
32
+ # def default_url
33
+ # # For Rails 3.1+ asset pipeline compatibility:
34
+ # # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
35
+ #
36
+ # "/images/fallback/" + [version_name, "default.png"].compact.join('_')
37
+ # end
38
+
39
+ version :preview do
40
+ process :resize_to_fill => [150, 150]
41
+ end
42
+
43
+ # Process files as they are uploaded:
44
+ # process :scale => [200, 300]
45
+ #
46
+ # def scale(width, height)
47
+ # # do something
48
+ # end
49
+
50
+ # Create different versions of your uploaded files:
51
+ # version :thumb do
52
+ # process :scale => [50, 50]
53
+ # end
54
+
55
+ # Add a white list of extensions which are allowed to be uploaded.
56
+ # For images you might use something like this:
57
+ # def extension_white_list
58
+ # %w(jpg jpeg gif png)
59
+ # end
60
+
61
+ # Override the filename of the uploaded files:
62
+ # Avoid using model.id or version_name here, see uploader/store.rb for details.
63
+ # def filename
64
+ # "something.jpg" if original_filename
65
+ # end
66
+
67
+ end