loft 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 391b496e43ed6be6213e78ebaafd043f3e10cd61
4
- data.tar.gz: 312c8ac2abbec5cfb6ee5038917d104b32f6fa3b
3
+ metadata.gz: f2cfe80ea9bf7470e4e7760e0e7bddff1e9fc996
4
+ data.tar.gz: 94813b10dd84a9ab5fa7bf58e12daf2efd6e11d1
5
5
  SHA512:
6
- metadata.gz: f57ee9453fc99a64b80551e2ca8b1311848bd203f4b2e8414d23d4f27b877376188b43b9cc05ef80b82efe7b760d1b6efa50eb5724fc1c74176c87edec2fb73a
7
- data.tar.gz: 7d565f0e5e16f69889cf9caf6851cdba6614079965afe2d0f329b352cdce2798a4847b8fafb9c28cd4c7cfecd7064299ac713b04747df744c60ad7e11e39465c
6
+ metadata.gz: 58854467080de4c4e89aa253b265f5f0d5e2ba6174d10d68f79eff40cb687c6b4d75954501b003a75c66455c39b3a13532a120cd7c92235cc143ad8410db6c4f
7
+ data.tar.gz: 602c1514e663e63929adea8c03661ff5752745a0136f3cfd01f5e857ad498041235fd5a779986a3e34ec6f02eaaaaa246048afc3b04c2b1e4371c6a4113414b7
@@ -0,0 +1,5 @@
1
+ class Admin::AssetsController < Admin::BaseController
2
+ mongosteen
3
+
4
+ has_scope :by_type
5
+ end
@@ -0,0 +1,5 @@
1
+ class Asset
2
+ include Mongoid::Document
3
+ include Mongoid::Timestamps
4
+ include LoftAsset
5
+ end
@@ -0,0 +1,150 @@
1
+ require 'autoinc'
2
+ require 'mongoid_search'
3
+
4
+ module LoftAsset
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+
9
+ include Mongoid::Timestamps
10
+ include Mongoid::Autoinc
11
+ include Mongoid::Search
12
+
13
+ include Ants::Id
14
+
15
+ include ActionView::Helpers::DateHelper
16
+ include ActionView::Helpers::NumberHelper
17
+
18
+
19
+ ## Attributes
20
+ field :name, default: ''
21
+ field :filename, default: ''
22
+ field :size, type: Integer
23
+ field :humanized_size, default: ''
24
+ field :type, default: 'other'
25
+ # - image
26
+ # - video
27
+ # - audio
28
+ # - archive
29
+ # - text
30
+
31
+ # increment value, used by uploader
32
+ field :_number, type: Integer
33
+ increments :_number
34
+
35
+
36
+ ## Uploaders
37
+ mount_uploader :file, AssetFileUploader
38
+
39
+
40
+ ## Validations
41
+ validates :file, presence: true
42
+
43
+
44
+ ## Search
45
+ search_in :name, :filename
46
+
47
+
48
+ ## Scopes
49
+ default_scope -> { desc(:created_at) }
50
+ scope :by_type, -> asset_type { where(type: asset_type) }
51
+
52
+
53
+ ## Indexes
54
+ index({ created_at: -1 })
55
+
56
+
57
+ ## Callbacks
58
+ before_save :update_asset_attributes
59
+
60
+
61
+ ## Helpers
62
+ def _list_item_title
63
+ name
64
+ end
65
+
66
+
67
+ def _list_item_subtitle
68
+ time_ago_in_words(self.created_at) + " ago"
69
+ end
70
+
71
+
72
+ def _list_item_thumbnail
73
+ if is_image?
74
+ { medium: file._200x150_2x.url, small: file._40x40_2x.url }
75
+ else
76
+ {}
77
+ end
78
+ end
79
+
80
+
81
+ def content_type
82
+ @content_type ||= file.content_type
83
+ end
84
+
85
+
86
+ def is_image?
87
+ return false unless file?
88
+ content_type.match(/image\//) ? true : false
89
+ end
90
+
91
+
92
+ def is_text?
93
+ return false unless file?
94
+ content_type.match(/text\//) ? true : false
95
+ end
96
+
97
+
98
+ def is_pdf?
99
+ return false unless file?
100
+ content_type.match(/pdf/) ? true : false
101
+ end
102
+
103
+
104
+ def is_archive?
105
+ return false unless file?
106
+ # need to add more archive types: rar, gz, bz2, gzip
107
+ content_type.match(/zip/) ? true : false
108
+ end
109
+
110
+
111
+ def is_audio?
112
+ return false unless file?
113
+ content_type.match(/audio\//) ? true : false
114
+ end
115
+
116
+
117
+ def is_video?
118
+ return false unless file?
119
+ content_type.match(/video\//) ? true : false
120
+ end
121
+
122
+
123
+ def update_asset_attributes
124
+ if file.present? && file_changed?
125
+
126
+ # save original file name for search
127
+ self.filename = file.file.original_filename
128
+
129
+ # save file size in plain for search
130
+ self.size = file.file.size
131
+
132
+ # save humanized file size
133
+ self.humanized_size = number_to_human_size(self.size)
134
+
135
+ # asset types
136
+ self.type = 'image' if self.is_image?
137
+ self.type = 'text' if self.is_text?
138
+ self.type = 'text' if self.is_pdf?
139
+ self.type = 'archive' if self.is_archive?
140
+ self.type = 'audio' if self.is_audio?
141
+ self.type = 'video' if self.is_video?
142
+ end
143
+
144
+ # use filename as an asset name if name is empty ''
145
+ self.name = self.name.empty? ? self.filename : self.name
146
+ end
147
+ private :update_asset_attributes
148
+
149
+ end
150
+ end
@@ -0,0 +1,28 @@
1
+ module LoftAssetFileUploader
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ include CarrierWave::MiniMagick
6
+
7
+ def store_dir
8
+ "loft/#{ model._number }"
9
+ end
10
+
11
+
12
+ version :_200x150_2x, if: :is_image? do
13
+ process :resize_to_fill => [400, 300]
14
+ end
15
+
16
+
17
+ version :_40x40_2x, if: :is_image? do
18
+ process :resize_to_fill => [80, 80]
19
+ end
20
+
21
+
22
+ def is_image? new_file
23
+ model.is_image?
24
+ end
25
+ private :is_image?
26
+
27
+ end
28
+ end
@@ -1,7 +1,3 @@
1
1
  class AssetFileUploader < CarrierWave::Uploader::Base
2
- include Loft::AssetFileUploader
2
+ include LoftAssetFileUploader
3
3
  end
4
-
5
-
6
-
7
-
data/lib/loft.rb CHANGED
@@ -1,7 +1,10 @@
1
+ require 'chr'
2
+ require 'ants'
3
+ require 'mongosteen'
4
+ require 'mini_magick'
5
+ require 'mongoid-grid_fs'
1
6
  require 'carrierwave/mongoid'
2
7
 
3
8
  module Loft
4
9
  require 'loft/engine'
5
- require 'mongoid/loft_asset'
6
- require 'concerns/asset_file_uploader'
7
- end
10
+ end
data/lib/loft/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Loft
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: loft
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Kravets
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-04 00:00:00.000000000 Z
11
+ date: 2015-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chr
@@ -159,12 +159,14 @@ files:
159
159
  - app/assets/javascripts/loft/redactor-loft.coffee
160
160
  - app/assets/stylesheets/inputs/loft-image.scss
161
161
  - app/assets/stylesheets/loft.scss
162
+ - app/controllers/admin/assets_controller.rb
163
+ - app/models/asset.rb
164
+ - app/models/concerns/loft_asset.rb
165
+ - app/models/concerns/loft_asset_file_uploader.rb
162
166
  - app/uploaders/asset_file_uploader.rb
163
- - lib/concerns/asset_file_uploader.rb
164
167
  - lib/loft.rb
165
168
  - lib/loft/engine.rb
166
169
  - lib/loft/version.rb
167
- - lib/mongoid/loft_asset.rb
168
170
  - loft.gemspec
169
171
  homepage: http://slatestudio.com
170
172
  licenses:
@@ -1,31 +0,0 @@
1
- module Loft
2
- module AssetFileUploader
3
- extend ActiveSupport::Concern
4
- included do
5
-
6
- include CarrierWave::MiniMagick
7
-
8
-
9
- def store_dir
10
- "loft/#{ model._number }"
11
- end
12
-
13
-
14
- version :_200x150_2x, if: :is_image? do
15
- process :resize_to_fill => [400, 300]
16
- end
17
-
18
-
19
- version :_40x40_2x, if: :is_image? do
20
- process :resize_to_fill => [80, 80]
21
- end
22
-
23
-
24
- def is_image? new_file
25
- model.is_image?
26
- end
27
- private :is_image?
28
-
29
- end
30
- end
31
- end
@@ -1,156 +0,0 @@
1
- require 'autoinc'
2
- require 'mongoid_search'
3
-
4
- module Mongoid
5
- module LoftAsset
6
- extend ActiveSupport::Concern
7
-
8
- included do
9
-
10
- include Mongoid::Timestamps
11
- include Mongoid::Autoinc
12
- include Mongoid::Search
13
-
14
- include Ants::Id
15
-
16
- include ActionView::Helpers::DateHelper
17
- include ActionView::Helpers::NumberHelper
18
-
19
-
20
- ## Attributes
21
- field :name, default: ''
22
- field :filename, default: ''
23
- field :size, type: Integer
24
- field :humanized_size, default: ''
25
- field :type, default: 'other'
26
- # - image
27
- # - video
28
- # - audio
29
- # - archive
30
- # - text
31
-
32
- # increment value, used by uploader
33
- field :_number, type: Integer
34
- increments :_number
35
-
36
-
37
- ## Uploaders
38
- mount_uploader :file, AssetFileUploader
39
-
40
-
41
- ## Validations
42
- validates :file, presence: true
43
-
44
-
45
- ## Search
46
- search_in :name, :filename
47
-
48
-
49
- ## Scopes
50
- default_scope -> { desc(:created_at) }
51
- scope :by_type, -> asset_type { where(type: asset_type) }
52
-
53
-
54
- ## Indexes
55
- index({ created_at: -1 })
56
-
57
-
58
- ## Callbacks
59
- before_save :update_asset_attributes
60
-
61
-
62
- ## Helpers
63
- def _list_item_title
64
- name
65
- end
66
-
67
-
68
- def _list_item_subtitle
69
- time_ago_in_words(self.created_at) + " ago"
70
- end
71
-
72
-
73
- def _list_item_thumbnail
74
- if is_image?
75
- { medium: file._200x150_2x.url, small: file._40x40_2x.url }
76
- else
77
- {}
78
- end
79
- end
80
-
81
-
82
- def content_type
83
- @content_type ||= file.content_type
84
- end
85
-
86
-
87
- def is_image?
88
- return false unless file?
89
- content_type.match(/image\//) ? true : false
90
- end
91
-
92
-
93
- def is_text?
94
- return false unless file?
95
- content_type.match(/text\//) ? true : false
96
- end
97
-
98
-
99
- def is_pdf?
100
- return false unless file?
101
- content_type.match(/pdf/) ? true : false
102
- end
103
-
104
-
105
- def is_archive?
106
- return false unless file?
107
- # need to add more archive types: rar, gz, bz2, gzip
108
- content_type.match(/zip/) ? true : false
109
- end
110
-
111
-
112
- def is_audio?
113
- return false unless file?
114
- content_type.match(/audio\//) ? true : false
115
- end
116
-
117
-
118
- def is_video?
119
- return false unless file?
120
- content_type.match(/video\//) ? true : false
121
- end
122
-
123
-
124
- def update_asset_attributes
125
- if file.present? && file_changed?
126
-
127
- # save original file name for search
128
- self.filename = file.file.original_filename
129
-
130
- # save file size in plain for search
131
- self.size = file.file.size
132
-
133
- # save humanized file size
134
- self.humanized_size = number_to_human_size(self.size)
135
-
136
- # asset types
137
- self.type = 'image' if self.is_image?
138
- self.type = 'text' if self.is_text?
139
- self.type = 'text' if self.is_pdf?
140
- self.type = 'archive' if self.is_archive?
141
- self.type = 'audio' if self.is_audio?
142
- self.type = 'video' if self.is_video?
143
- end
144
-
145
- # use filename as an asset name if name is empty ''
146
- self.name = self.name.empty? ? self.filename : self.name
147
- end
148
- private :update_asset_attributes
149
-
150
- end
151
- end
152
- end
153
-
154
-
155
-
156
-