ckeditor 3.6.0 → 3.6.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +5 -1
- data/README.rdoc +44 -9
- data/Rakefile +28 -0
- data/config/locales/pt-BR.ckeditor.yml +8 -0
- data/lib/ckeditor.rb +6 -1
- data/lib/ckeditor/backend/carrierwave.rb +64 -0
- data/lib/ckeditor/backend/paperclip.rb +53 -0
- data/lib/ckeditor/http.rb +10 -2
- data/lib/ckeditor/orm/active_record.rb +4 -69
- data/lib/ckeditor/orm/base.rb +46 -0
- data/lib/ckeditor/orm/mongoid.rb +20 -71
- data/lib/ckeditor/version.rb +1 -1
- data/lib/generators/ckeditor/install_generator.rb +1 -0
- data/lib/generators/ckeditor/models_generator.rb +28 -9
- data/lib/generators/ckeditor/templates/ckeditor.rb +1 -2
- data/lib/generators/ckeditor/templates/ckeditor/filebrowser/javascripts/application.js +1 -1
- data/lib/generators/ckeditor/templates/models/active_record/carrierwave/ckeditor/asset.rb +7 -0
- data/lib/generators/ckeditor/templates/models/active_record/carrierwave/ckeditor/attachment_file.rb +10 -0
- data/lib/generators/ckeditor/templates/models/active_record/carrierwave/ckeditor/picture.rb +7 -0
- data/lib/generators/ckeditor/templates/models/active_record/{migration.rb → carrierwave/migration.rb} +0 -0
- data/lib/generators/ckeditor/templates/models/active_record/{ckeditor → paperclip/ckeditor}/asset.rb +1 -4
- data/lib/generators/ckeditor/templates/models/active_record/{ckeditor → paperclip/ckeditor}/attachment_file.rb +0 -0
- data/lib/generators/ckeditor/templates/models/active_record/{ckeditor → paperclip/ckeditor}/picture.rb +0 -0
- data/lib/generators/ckeditor/templates/models/active_record/paperclip/migration.rb +26 -0
- data/lib/generators/ckeditor/templates/models/base/carrierwave/uploaders/ckeditor_attachment_file_uploader.rb +42 -0
- data/lib/generators/ckeditor/templates/models/base/carrierwave/uploaders/ckeditor_picture_uploader.rb +53 -0
- data/lib/generators/ckeditor/templates/models/mongoid/carrierwave/ckeditor/asset.rb +7 -0
- data/lib/generators/ckeditor/templates/models/mongoid/carrierwave/ckeditor/attachment_file.rb +10 -0
- data/lib/generators/ckeditor/templates/models/mongoid/carrierwave/ckeditor/picture.rb +7 -0
- data/lib/generators/ckeditor/templates/models/mongoid/paperclip/ckeditor/asset.rb +5 -0
- data/lib/generators/ckeditor/templates/models/mongoid/{ckeditor → paperclip/ckeditor}/attachment_file.rb +3 -3
- data/lib/generators/ckeditor/templates/models/mongoid/{ckeditor → paperclip/ckeditor}/picture.rb +0 -0
- data/test/controllers/attachment_files_controller_test.rb +9 -0
- data/test/controllers/pictures_controller_test.rb +9 -0
- data/test/dummy/config/application.rb +6 -2
- data/test/dummy/db/migrate/20110705195648_create_ckeditor_assets.rb +2 -2
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/test.log +2808 -0
- data/test/dummy/public/ckeditor_assets/attachments/4e53723cde2f151212000001/rails_tar.gz +0 -0
- data/test/dummy/public/ckeditor_assets/attachments/4e537333de2f15123b000001/rails_tar.gz +0 -0
- data/test/dummy/public/ckeditor_assets/attachments/4e537621de2f1514e9000001/rails_tar.gz +0 -0
- data/test/dummy/public/ckeditor_assets/attachments/4e53766ade2f15152c000001/rails_tar.gz +0 -0
- data/test/dummy/public/ckeditor_assets/attachments/4e53781ede2f1515b7000001/rails.tar.gz +0 -0
- data/test/dummy/public/ckeditor_assets/attachments/4e537849de2f151651000001/rails_tar.gz +0 -0
- data/test/dummy/public/ckeditor_assets/pictures/4e53723dde2f151212000002/content_rails.png +0 -0
- data/test/dummy/public/ckeditor_assets/pictures/4e53723dde2f151212000002/original_rails.png +0 -0
- data/test/dummy/public/ckeditor_assets/pictures/4e53723dde2f151212000002/thumb_rails.png +0 -0
- data/test/dummy/public/ckeditor_assets/pictures/4e537334de2f15123b000002/content_rails.png +0 -0
- data/test/dummy/public/ckeditor_assets/pictures/4e537334de2f15123b000002/original_rails.png +0 -0
- data/test/dummy/public/ckeditor_assets/pictures/4e537334de2f15123b000002/thumb_rails.png +0 -0
- data/test/dummy/public/ckeditor_assets/pictures/4e537637de2f1514e9000007/content_rails.png +0 -0
- data/test/dummy/public/ckeditor_assets/pictures/4e537637de2f1514e9000007/original_rails.png +0 -0
- data/test/dummy/public/ckeditor_assets/pictures/4e537637de2f1514e9000007/thumb_rails.png +0 -0
- data/test/dummy/public/ckeditor_assets/pictures/4e53768ade2f15152c000007/content_rails.png +0 -0
- data/test/dummy/public/ckeditor_assets/pictures/4e53768ade2f15152c000007/original_rails.png +0 -0
- data/test/dummy/public/ckeditor_assets/pictures/4e53768ade2f15152c000007/thumb_rails.png +0 -0
- data/test/dummy/public/ckeditor_assets/pictures/4e53783ade2f1515b7000007/content_rails.png +0 -0
- data/test/dummy/public/ckeditor_assets/pictures/4e53783ade2f1515b7000007/rails.png +0 -0
- data/test/dummy/public/ckeditor_assets/pictures/4e53783ade2f1515b7000007/thumb_rails.png +0 -0
- data/test/dummy/public/ckeditor_assets/pictures/4e537868de2f151651000007/content_rails.png +0 -0
- data/test/dummy/public/ckeditor_assets/pictures/4e537868de2f151651000007/original_rails.png +0 -0
- data/test/dummy/public/ckeditor_assets/pictures/4e537868de2f151651000007/thumb_rails.png +0 -0
- data/test/dummy/public/uploads/tmp/20110823-1231-4694-7541/rails.png +0 -0
- data/test/dummy/public/uploads/tmp/20110823-1232-4702-5501/rails.png +0 -0
- data/test/dummy/public/uploads/tmp/20110823-1245-5487-0966/rails.png +0 -0
- data/test/dummy/public/uploads/tmp/20110823-1245-5487-1597/rails.tar.gz +0 -0
- data/test/dummy/public/uploads/tmp/20110823-1245-5487-3892/rails.tar.gz +0 -0
- data/test/dummy/public/uploads/tmp/20110823-1245-5487-5787/rails.tar.gz +0 -0
- data/test/dummy/public/uploads/tmp/20110823-1245-5487-5790/rails.png +0 -0
- data/test/dummy/public/uploads/tmp/20110823-1245-5487-6435/rails.png +0 -0
- data/test/dummy/public/uploads/tmp/20110823-1245-5487-6978/rails.png +0 -0
- data/test/dummy/public/uploads/tmp/20110823-1245-5487-7226/rails.tar.gz +0 -0
- data/test/dummy/public/uploads/tmp/20110823-1245-5487-7290/rails.tar.gz +0 -0
- data/test/dummy/public/uploads/tmp/20110823-1245-5487-9279/rails.png +0 -0
- data/test/generators/models_generator_test.rb +34 -4
- data/test/models/attachment_file_test.rb +16 -0
- data/test/models/picture_test.rb +16 -0
- data/test/support/helpers.rb +30 -0
- data/test/support/raw_post.rb +9 -0
- data/test/test_helper.rb +2 -0
- data/test/tmp/app/models/ckeditor/asset.rb +2 -4
- data/test/tmp/app/models/ckeditor/attachment_file.rb +3 -3
- metadata +104 -11
- data/lib/generators/ckeditor/templates/models/mongoid/ckeditor/asset.rb +0 -7
data/Gemfile
CHANGED
@@ -7,6 +7,7 @@ gem "rails", "3.0.9"
|
|
7
7
|
platforms :mri_18 do
|
8
8
|
group :test do
|
9
9
|
gem 'ruby-debug'
|
10
|
+
gem 'SystemTimer'
|
10
11
|
end
|
11
12
|
end
|
12
13
|
|
@@ -23,12 +24,15 @@ platforms :ruby do
|
|
23
24
|
end
|
24
25
|
|
25
26
|
group :active_record do
|
26
|
-
gem "paperclip"
|
27
|
+
gem "paperclip"
|
28
|
+
gem "carrierwave"
|
29
|
+
gem "mini_magick"
|
27
30
|
end
|
28
31
|
|
29
32
|
group :mongoid do
|
30
33
|
gem "mongoid"
|
31
34
|
gem "bson_ext"
|
32
35
|
gem 'mongoid-paperclip', :require => 'mongoid_paperclip'
|
36
|
+
gem 'carrierwave-mongoid', :require => 'carrierwave/mongoid'
|
33
37
|
end
|
34
38
|
end
|
data/README.rdoc
CHANGED
@@ -14,7 +14,13 @@ the results users have when publishing it. It brings to the web common editing f
|
|
14
14
|
|
15
15
|
== Install
|
16
16
|
|
17
|
+
gem install ckeditor
|
18
|
+
|
19
|
+
Or via bundler:
|
20
|
+
|
17
21
|
gem "ckeditor", "~> 3.6.0"
|
22
|
+
|
23
|
+
=== Download ckeditor
|
18
24
|
|
19
25
|
rails generate ckeditor:install
|
20
26
|
|
@@ -22,31 +28,59 @@ You can pass version of ckeditor to download (http://ckeditor.com/download/relea
|
|
22
28
|
|
23
29
|
rails generate ckeditor:install --version=3.5.4
|
24
30
|
|
25
|
-
Now generate models for store uploading files
|
31
|
+
=== Now generate models for store uploading files
|
32
|
+
|
33
|
+
==== ActiveRecord + paperclip
|
34
|
+
|
35
|
+
For active_record orm is used paperclip gem (it's by default).
|
36
|
+
|
37
|
+
gem "paperclip"
|
38
|
+
|
39
|
+
rails generate ckeditor:models --orm=active_record --backend=paperclip
|
40
|
+
|
41
|
+
==== ActiveRecord + carrierwave
|
42
|
+
|
43
|
+
gem "carrierwave"
|
44
|
+
gem "mini_magick"
|
45
|
+
|
46
|
+
rails generate ckeditor:models --orm=active_record --backend=carrierwave
|
47
|
+
|
48
|
+
==== Mongoid + paperclip
|
49
|
+
|
50
|
+
gem 'mongoid-paperclip', :require => 'mongoid_paperclip'
|
51
|
+
|
52
|
+
rails generate ckeditor:models --orm=mongoid --backend=paperclip
|
53
|
+
|
54
|
+
==== Mongoid + carrierwave
|
55
|
+
|
56
|
+
gem "carrierwave-mongoid", :require => 'carrierwave/mongoid'
|
57
|
+
gem "mini_magick"
|
58
|
+
|
59
|
+
rails generate ckeditor:models --orm=mongoid --backend=carrierwave
|
26
60
|
|
27
|
-
rails generate ckeditor:models --orm=active_record
|
28
61
|
|
29
62
|
Available orms:
|
30
63
|
* active_record
|
31
64
|
* mongoid (Thanks Dmitry Lihachev https://github.com/lda)
|
32
65
|
* mongo_mapper (under construction)
|
33
66
|
|
67
|
+
|
34
68
|
Autoload ckeditor models folder (application.rb):
|
35
69
|
|
36
70
|
config.autoload_paths += %W(#{config.root}/app/models/ckeditor)
|
37
71
|
|
38
|
-
|
72
|
+
== Usage
|
39
73
|
|
40
|
-
|
74
|
+
Include ckeditor javascripts:
|
41
75
|
|
42
|
-
|
43
|
-
|
44
|
-
For gem "carrierwave" shortly I will give an example.
|
76
|
+
<%= javascript_include_tag :ckeditor %>
|
45
77
|
|
46
|
-
|
78
|
+
or (for rails 3.1):
|
47
79
|
|
48
|
-
<%= javascript_include_tag
|
80
|
+
<%= javascript_include_tag "/javascripts/ckeditor/ckeditor.js" %>
|
49
81
|
|
82
|
+
Form helpers:
|
83
|
+
|
50
84
|
cktext_area_tag("test_area", "Ckeditor is the best")
|
51
85
|
|
52
86
|
cktext_area_tag("content", "Ckeditor", :input_html => {:cols => 10, :rows => 20}, :toolbar => 'Easy')
|
@@ -160,5 +194,6 @@ By default, both these methods call "ckeditor_filebrowser_scope" method:
|
|
160
194
|
|
161
195
|
rake test
|
162
196
|
rake test CKEDITOR_ORM=mongoid
|
197
|
+
rake test CKEDITOR_BACKEND=carrierwave
|
163
198
|
|
164
199
|
This project rocks and uses MIT-LICENSE.
|
data/Rakefile
CHANGED
@@ -18,6 +18,34 @@ Rake::TestTask.new(:test) do |t|
|
|
18
18
|
t.verbose = false
|
19
19
|
end
|
20
20
|
|
21
|
+
Rake::TestTask.new("test:controllers") do |t|
|
22
|
+
t.libs << 'lib'
|
23
|
+
t.libs << 'test'
|
24
|
+
t.pattern = 'test/controllers/*_test.rb'
|
25
|
+
t.verbose = false
|
26
|
+
end
|
27
|
+
|
28
|
+
Rake::TestTask.new("test:generators") do |t|
|
29
|
+
t.libs << 'lib'
|
30
|
+
t.libs << 'test'
|
31
|
+
t.pattern = 'test/generators/*_test.rb'
|
32
|
+
t.verbose = false
|
33
|
+
end
|
34
|
+
|
35
|
+
Rake::TestTask.new("test:integration") do |t|
|
36
|
+
t.libs << 'lib'
|
37
|
+
t.libs << 'test'
|
38
|
+
t.pattern = 'test/integration/*_test.rb'
|
39
|
+
t.verbose = false
|
40
|
+
end
|
41
|
+
|
42
|
+
Rake::TestTask.new("test:models") do |t|
|
43
|
+
t.libs << 'lib'
|
44
|
+
t.libs << 'test'
|
45
|
+
t.pattern = 'test/models/*_test.rb'
|
46
|
+
t.verbose = false
|
47
|
+
end
|
48
|
+
|
21
49
|
task :default => :test
|
22
50
|
|
23
51
|
RDoc::Task.new do |rdoc|
|
data/lib/ckeditor.rb
CHANGED
@@ -18,6 +18,11 @@ module Ckeditor
|
|
18
18
|
autoload :SimpleFormBuilder, 'ckeditor/hooks/simple_form'
|
19
19
|
end
|
20
20
|
|
21
|
+
module Backend
|
22
|
+
autoload :Paperclip, 'ckeditor/backend/paperclip'
|
23
|
+
autoload :CarrierWave, 'ckeditor/backend/carrierwave'
|
24
|
+
end
|
25
|
+
|
21
26
|
# Allowed image file types for upload.
|
22
27
|
# Set to nil or [] (empty array) for all file types
|
23
28
|
mattr_accessor :image_file_types
|
@@ -26,7 +31,7 @@ module Ckeditor
|
|
26
31
|
# Allowed attachment file types for upload.
|
27
32
|
# Set to nil or [] (empty array) for all file types
|
28
33
|
mattr_accessor :attachment_file_types
|
29
|
-
@@attachment_file_types = ["doc", "docx", "rar", "zip", "
|
34
|
+
@@attachment_file_types = ["doc", "docx", "xls", "odt", "ods", "pdf", "rar", "zip", "tar", "tar.gz", "swf"]
|
30
35
|
|
31
36
|
# Default way to setup Ckeditor. Run rails generate ckeditor to create
|
32
37
|
# a fresh initializer with all configuration values.
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'mime/types'
|
2
|
+
require 'mini_magick'
|
3
|
+
|
4
|
+
module Ckeditor
|
5
|
+
module Backend
|
6
|
+
module CarrierWave
|
7
|
+
def self.included(base)
|
8
|
+
base.send(:include, InstanceMethods)
|
9
|
+
base.send(:extend, ClassMethods)
|
10
|
+
end
|
11
|
+
|
12
|
+
module ClassMethods
|
13
|
+
def self.extended(base)
|
14
|
+
base.class_eval do
|
15
|
+
process :extract_content_type
|
16
|
+
process :set_size
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
module InstanceMethods
|
22
|
+
# process :strip
|
23
|
+
def strip
|
24
|
+
manipulate! do |img|
|
25
|
+
img.strip
|
26
|
+
img = yield(img) if block_given?
|
27
|
+
img
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# process :quality => 85
|
32
|
+
def quality(percentage)
|
33
|
+
manipulate! do |img|
|
34
|
+
img.quality(percentage)
|
35
|
+
img = yield(img) if block_given?
|
36
|
+
img
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def extract_content_type
|
41
|
+
if file.content_type == 'application/octet-stream' || file.content_type.blank?
|
42
|
+
content_type = MIME::Types.type_for(original_filename).first
|
43
|
+
else
|
44
|
+
content_type = file.content_type
|
45
|
+
end
|
46
|
+
|
47
|
+
model.data_content_type = content_type.to_s
|
48
|
+
end
|
49
|
+
|
50
|
+
def set_size
|
51
|
+
model.data_file_size = file.size
|
52
|
+
end
|
53
|
+
|
54
|
+
def read_dimensions
|
55
|
+
if model.image? && model.has_dimensions?
|
56
|
+
magick = ::MiniMagick::Image.new(current_path)
|
57
|
+
model.width, model.height = magick[:width], magick[:height]
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'mime/types'
|
2
|
+
|
3
|
+
module Ckeditor
|
4
|
+
module Backend
|
5
|
+
module Paperclip
|
6
|
+
def self.included(base)
|
7
|
+
base.send(:include, InstanceMethods)
|
8
|
+
base.send(:extend, ClassMethods)
|
9
|
+
end
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
def self.extended(base)
|
13
|
+
base.class_eval do
|
14
|
+
before_validation :extract_content_type
|
15
|
+
before_create :read_dimensions, :parameterize_filename
|
16
|
+
|
17
|
+
delegate :url, :path, :styles, :size, :content_type, :to => :data
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
module InstanceMethods
|
23
|
+
def geometry
|
24
|
+
@geometry ||= ::Paperclip::Geometry.from_file(data.to_file)
|
25
|
+
end
|
26
|
+
|
27
|
+
protected
|
28
|
+
|
29
|
+
def parameterize_filename
|
30
|
+
unless data_file_name.blank?
|
31
|
+
filename = Ckeditor::Utils.parameterize_filename(data_file_name)
|
32
|
+
self.data.instance_write(:file_name, filename)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def read_dimensions
|
37
|
+
if image? && has_dimensions?
|
38
|
+
self.width = geometry.width
|
39
|
+
self.height = geometry.height
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# Extract content_type from filename using mime/types gem
|
44
|
+
def extract_content_type
|
45
|
+
if data_content_type == "application/octet-stream" && !data_file_name.blank?
|
46
|
+
content_types = MIME::Types.type_for(data_file_name)
|
47
|
+
self.data_content_type = content_types.first.to_s unless content_types.empty?
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/lib/ckeditor/http.rb
CHANGED
@@ -50,7 +50,7 @@ module Ckeditor
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def fetch
|
53
|
-
self.write
|
53
|
+
self.write(body)
|
54
54
|
self.rewind
|
55
55
|
self
|
56
56
|
end
|
@@ -60,9 +60,17 @@ module Ckeditor
|
|
60
60
|
end
|
61
61
|
|
62
62
|
def content_type
|
63
|
-
types = MIME::Types.type_for(
|
63
|
+
types = MIME::Types.type_for(original_filename)
|
64
64
|
types.empty? ? @request.content_type : types.first.to_s
|
65
65
|
end
|
66
|
+
|
67
|
+
def body
|
68
|
+
if @request.raw_post.respond_to?(:force_encoding)
|
69
|
+
@request.raw_post.force_encoding("UTF-8")
|
70
|
+
else
|
71
|
+
@request.raw_post
|
72
|
+
end
|
73
|
+
end
|
66
74
|
end
|
67
75
|
|
68
76
|
# Convert nested Hash to HashWithIndifferentAccess and replace
|
@@ -1,9 +1,11 @@
|
|
1
|
+
require 'ckeditor/orm/base'
|
2
|
+
|
1
3
|
module Ckeditor
|
2
4
|
module Orm
|
3
5
|
module ActiveRecord
|
4
6
|
module AssetBase
|
5
7
|
def self.included(base)
|
6
|
-
base.send(:include, InstanceMethods)
|
8
|
+
base.send(:include, Base::AssetBase::InstanceMethods)
|
7
9
|
base.send(:extend, ClassMethods)
|
8
10
|
end
|
9
11
|
|
@@ -13,78 +15,11 @@ module Ckeditor
|
|
13
15
|
set_table_name "ckeditor_assets"
|
14
16
|
|
15
17
|
belongs_to :assetable, :polymorphic => true
|
16
|
-
|
17
|
-
before_validation :extract_content_type
|
18
|
-
before_create :read_dimensions, :parameterize_filename
|
19
18
|
|
20
|
-
|
19
|
+
attr_accessible :data, :assetable_type, :assetable_id, :assetable
|
21
20
|
end
|
22
21
|
end
|
23
22
|
end
|
24
|
-
|
25
|
-
module InstanceMethods
|
26
|
-
def filename
|
27
|
-
data_file_name
|
28
|
-
end
|
29
|
-
|
30
|
-
def format_created_at
|
31
|
-
I18n.l(created_at, :format => "%d.%m.%Y")
|
32
|
-
end
|
33
|
-
|
34
|
-
def has_dimensions?
|
35
|
-
respond_to?(:width) && respond_to?(:height)
|
36
|
-
end
|
37
|
-
|
38
|
-
def image?
|
39
|
-
Ckeditor::IMAGE_TYPES.include?(data_content_type)
|
40
|
-
end
|
41
|
-
|
42
|
-
def geometry
|
43
|
-
@geometry ||= Paperclip::Geometry.from_file(data.to_file)
|
44
|
-
@geometry
|
45
|
-
end
|
46
|
-
|
47
|
-
def url_content
|
48
|
-
url
|
49
|
-
end
|
50
|
-
|
51
|
-
def url_thumb
|
52
|
-
url(:thumb)
|
53
|
-
end
|
54
|
-
|
55
|
-
def as_json(options = nil)
|
56
|
-
options = {
|
57
|
-
:methods => [:url_content, :url_thumb, :size, :filename, :format_created_at],
|
58
|
-
:root => "asset"
|
59
|
-
}.merge(options || {})
|
60
|
-
|
61
|
-
super options
|
62
|
-
end
|
63
|
-
|
64
|
-
protected
|
65
|
-
|
66
|
-
def parameterize_filename
|
67
|
-
unless data_file_name.blank?
|
68
|
-
filename = Ckeditor::Utils.parameterize_filename(data_file_name)
|
69
|
-
self.data.instance_write(:file_name, filename)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
def read_dimensions
|
74
|
-
if image? && has_dimensions?
|
75
|
-
self.width = geometry.width
|
76
|
-
self.height = geometry.height
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
# Extract content_type from filename using mime/types gem
|
81
|
-
def extract_content_type
|
82
|
-
if data_content_type == "application/octet-stream" && !data_file_name.blank?
|
83
|
-
content_types = MIME::Types.type_for(data_file_name)
|
84
|
-
self.data_content_type = content_types.first.to_s unless content_types.empty?
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
23
|
end
|
89
24
|
end
|
90
25
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Ckeditor
|
2
|
+
module Orm
|
3
|
+
module Base
|
4
|
+
module AssetBase
|
5
|
+
module InstanceMethods
|
6
|
+
def filename
|
7
|
+
data_file_name
|
8
|
+
end
|
9
|
+
|
10
|
+
def has_dimensions?
|
11
|
+
respond_to?(:width) && respond_to?(:height)
|
12
|
+
end
|
13
|
+
|
14
|
+
def image?
|
15
|
+
Ckeditor::IMAGE_TYPES.include?(data_content_type)
|
16
|
+
end
|
17
|
+
|
18
|
+
def format_created_at
|
19
|
+
self.created_at.strftime("%d.%m.%Y")
|
20
|
+
end
|
21
|
+
|
22
|
+
def url_content
|
23
|
+
url
|
24
|
+
end
|
25
|
+
|
26
|
+
def url_thumb
|
27
|
+
url(:thumb)
|
28
|
+
end
|
29
|
+
|
30
|
+
def as_json_methods
|
31
|
+
[:url_content, :url_thumb, :size, :filename, :format_created_at]
|
32
|
+
end
|
33
|
+
|
34
|
+
def as_json(options = nil)
|
35
|
+
options = {
|
36
|
+
:methods => as_json_methods,
|
37
|
+
:root => "asset"
|
38
|
+
}.merge(options || {})
|
39
|
+
|
40
|
+
super options
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|