ckeditor 3.2.1 → 3.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. data/README.rdoc +136 -0
  2. data/app/controllers/ckeditor_controller.rb +5 -4
  3. data/app/helpers/ckeditor_helper.rb +2 -18
  4. data/app/views/ckeditor/_asset.html.erb +15 -0
  5. data/app/views/ckeditor/files.html.erb +1 -1
  6. data/app/views/ckeditor/images.html.erb +1 -1
  7. data/app/views/layouts/ckeditor.html.erb +0 -1
  8. data/lib/ckeditor.rb +20 -0
  9. data/lib/ckeditor/engine.rb +11 -0
  10. data/lib/ckeditor/formtastic.rb +12 -0
  11. data/lib/ckeditor/middleware.rb +18 -0
  12. data/lib/ckeditor/version.rb +1 -1
  13. data/lib/ckeditor/view_helper.rb +40 -63
  14. data/lib/generators/USAGE +17 -0
  15. data/lib/generators/{ckeditor_generator.rb → ckeditor_core_generator.rb} +2 -7
  16. data/lib/generators/ckeditor_models_generator.rb +41 -0
  17. data/lib/generators/templates/ckeditor.rb +3 -2
  18. data/lib/generators/templates/ckeditor/swfupload/fileprogress.js +2 -20
  19. data/lib/generators/templates/ckeditor/swfupload/swfupload.js +1 -980
  20. data/lib/generators/templates/ckeditor/swfupload/swfupload.queue.js +1 -98
  21. data/lib/generators/templates/ckeditor/swfupload/swfupload.swf +0 -0
  22. data/lib/generators/templates/models/attachment_fu/asset.rb +32 -0
  23. data/lib/generators/templates/models/attachment_fu/attachment_file.rb +24 -0
  24. data/lib/generators/templates/models/attachment_fu/migration.rb +30 -0
  25. data/lib/generators/templates/models/attachment_fu/picture.rb +25 -0
  26. data/lib/generators/templates/models/paperclip/asset.rb +86 -0
  27. data/lib/generators/templates/models/paperclip/attachment_file.rb +40 -0
  28. data/lib/generators/templates/models/paperclip/migration.rb +31 -0
  29. data/lib/generators/templates/models/paperclip/picture.rb +23 -0
  30. metadata +21 -13
  31. data/README.textile +0 -225
  32. data/TODO +0 -3
  33. data/app/views/ckeditor/_file.html.erb +0 -15
  34. data/app/views/ckeditor/_image.html.erb +0 -15
  35. data/lib/ckeditor/file_storage.rb +0 -178
@@ -1,98 +1 @@
1
- /*
2
- Queue Plug-in
3
-
4
- Features:
5
- *Adds a cancelQueue() method for cancelling the entire queue.
6
- *All queued files are uploaded when startUpload() is called.
7
- *If false is returned from uploadComplete then the queue upload is stopped.
8
- If false is not returned (strict comparison) then the queue upload is continued.
9
- *Adds a QueueComplete event that is fired when all the queued files have finished uploading.
10
- Set the event handler with the queue_complete_handler setting.
11
-
12
- */
13
-
14
- var SWFUpload;
15
- if (typeof(SWFUpload) === "function") {
16
- SWFUpload.queue = {};
17
-
18
- SWFUpload.prototype.initSettings = (function (oldInitSettings) {
19
- return function () {
20
- if (typeof(oldInitSettings) === "function") {
21
- oldInitSettings.call(this);
22
- }
23
-
24
- this.queueSettings = {};
25
-
26
- this.queueSettings.queue_cancelled_flag = false;
27
- this.queueSettings.queue_upload_count = 0;
28
-
29
- this.queueSettings.user_upload_complete_handler = this.settings.upload_complete_handler;
30
- this.queueSettings.user_upload_start_handler = this.settings.upload_start_handler;
31
- this.settings.upload_complete_handler = SWFUpload.queue.uploadCompleteHandler;
32
- this.settings.upload_start_handler = SWFUpload.queue.uploadStartHandler;
33
-
34
- this.settings.queue_complete_handler = this.settings.queue_complete_handler || null;
35
- };
36
- })(SWFUpload.prototype.initSettings);
37
-
38
- SWFUpload.prototype.startUpload = function (fileID) {
39
- this.queueSettings.queue_cancelled_flag = false;
40
- this.callFlash("StartUpload", [fileID]);
41
- };
42
-
43
- SWFUpload.prototype.cancelQueue = function () {
44
- this.queueSettings.queue_cancelled_flag = true;
45
- this.stopUpload();
46
-
47
- var stats = this.getStats();
48
- while (stats.files_queued > 0) {
49
- this.cancelUpload();
50
- stats = this.getStats();
51
- }
52
- };
53
-
54
- SWFUpload.queue.uploadStartHandler = function (file) {
55
- var returnValue;
56
- if (typeof(this.queueSettings.user_upload_start_handler) === "function") {
57
- returnValue = this.queueSettings.user_upload_start_handler.call(this, file);
58
- }
59
-
60
- // To prevent upload a real "FALSE" value must be returned, otherwise default to a real "TRUE" value.
61
- returnValue = (returnValue === false) ? false : true;
62
-
63
- this.queueSettings.queue_cancelled_flag = !returnValue;
64
-
65
- return returnValue;
66
- };
67
-
68
- SWFUpload.queue.uploadCompleteHandler = function (file) {
69
- var user_upload_complete_handler = this.queueSettings.user_upload_complete_handler;
70
- var continueUpload;
71
-
72
- if (file.filestatus === SWFUpload.FILE_STATUS.COMPLETE) {
73
- this.queueSettings.queue_upload_count++;
74
- }
75
-
76
- if (typeof(user_upload_complete_handler) === "function") {
77
- continueUpload = (user_upload_complete_handler.call(this, file) === false) ? false : true;
78
- } else if (file.filestatus === SWFUpload.FILE_STATUS.QUEUED) {
79
- // If the file was stopped and re-queued don't restart the upload
80
- continueUpload = false;
81
- } else {
82
- continueUpload = true;
83
- }
84
-
85
- if (continueUpload) {
86
- var stats = this.getStats();
87
- if (stats.files_queued > 0 && this.queueSettings.queue_cancelled_flag === false) {
88
- this.startUpload();
89
- } else if (this.queueSettings.queue_cancelled_flag === false) {
90
- this.queueEvent("queue_complete_handler", [this.queueSettings.queue_upload_count]);
91
- this.queueSettings.queue_upload_count = 0;
92
- } else {
93
- this.queueSettings.queue_cancelled_flag = false;
94
- this.queueSettings.queue_upload_count = 0;
95
- }
96
- }
97
- };
98
- }
1
+ var SWFUpload;if(typeof(SWFUpload)==="function"){SWFUpload.queue={};SWFUpload.prototype.initSettings=(function(oldInitSettings){return function(){if(typeof(oldInitSettings)==="function"){oldInitSettings.call(this)}this.queueSettings={};this.queueSettings.queue_cancelled_flag=false;this.queueSettings.queue_upload_count=0;this.queueSettings.user_upload_complete_handler=this.settings.upload_complete_handler;this.queueSettings.user_upload_start_handler=this.settings.upload_start_handler;this.settings.upload_complete_handler=SWFUpload.queue.uploadCompleteHandler;this.settings.upload_start_handler=SWFUpload.queue.uploadStartHandler;this.settings.queue_complete_handler=this.settings.queue_complete_handler||null}})(SWFUpload.prototype.initSettings);SWFUpload.prototype.startUpload=function(fileID){this.queueSettings.queue_cancelled_flag=false;this.callFlash("StartUpload",[fileID])};SWFUpload.prototype.cancelQueue=function(){this.queueSettings.queue_cancelled_flag=true;this.stopUpload();var stats=this.getStats();while(stats.files_queued>0){this.cancelUpload();stats=this.getStats()}};SWFUpload.queue.uploadStartHandler=function(file){var returnValue;if(typeof(this.queueSettings.user_upload_start_handler)==="function"){returnValue=this.queueSettings.user_upload_start_handler.call(this,file)}returnValue=(returnValue===false)?false:true;this.queueSettings.queue_cancelled_flag=!returnValue;return returnValue};SWFUpload.queue.uploadCompleteHandler=function(file){var user_upload_complete_handler=this.queueSettings.user_upload_complete_handler;var continueUpload;if(file.filestatus===SWFUpload.FILE_STATUS.COMPLETE){this.queueSettings.queue_upload_count++}if(typeof(user_upload_complete_handler)==="function"){continueUpload=(user_upload_complete_handler.call(this,file)===false)?false:true}else if(file.filestatus===SWFUpload.FILE_STATUS.QUEUED){continueUpload=false}else{continueUpload=true}if(continueUpload){var stats=this.getStats();if(stats.files_queued>0&&this.queueSettings.queue_cancelled_flag===false){this.startUpload()}else if(this.queueSettings.queue_cancelled_flag===false){this.queueEvent("queue_complete_handler",[this.queueSettings.queue_upload_count]);this.queueSettings.queue_upload_count=0}else{this.queueSettings.queue_cancelled_flag=false;this.queueSettings.queue_upload_count=0}}}}
@@ -0,0 +1,32 @@
1
+ class Ckeditor::Asset < ActiveRecord::Base
2
+ set_table_name "ckeditor_assets"
3
+
4
+ belongs_to :user
5
+ belongs_to :assetable, :polymorphic => true
6
+
7
+ scope :masters, where("parent_id IS NULL")
8
+
9
+ def url(*args)
10
+ public_filename(*args)
11
+ end
12
+
13
+ def format_created_at
14
+ I18n.l(self.created_at, :format=>"%d.%m.%Y %H:%M")
15
+ end
16
+
17
+ def to_xml(options = {})
18
+ xml = options[:builder] ||= Builder::XmlMarkup.new(:indent => options[:indent])
19
+
20
+ xml.tag!(self.read_attribute(:type).to_s.downcase) do
21
+ xml.filename{ xml.cdata!(self.filename) }
22
+ xml.size self.size
23
+ xml.path{ xml.cdata!(self.public_filename) }
24
+
25
+ xml.thumbnails do
26
+ self.thumbnails.each do |t|
27
+ xml.tag!(t.thumbnail, self.public_filename(t.thumbnail))
28
+ end
29
+ end unless self.thumbnails.empty?
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,24 @@
1
+ class Ckeditor::AttachmentFile < Ckeditor::Asset
2
+ has_attachment :storage => :file_system, :path_prefix => 'public/assets/attachments',
3
+ :max_size => 10.megabytes
4
+
5
+ validates_as_attachment
6
+
7
+ # Map file extensions to mime types.
8
+ # Thanks to bug in Flash 8 the content type is always set to application/octet-stream.
9
+ # From: http://blog.airbladesoftware.com/2007/8/8/uploading-files-with-swfupload
10
+ def swf_uploaded_data=(data)
11
+ data.content_type = MIME::Types.type_for(data.original_filename)
12
+ self.uploaded_data = data
13
+ end
14
+
15
+ def full_filename(thumbnail = nil)
16
+ file_system_path = self.attachment_options[:path_prefix]
17
+ Rails.root.join(file_system_path, file_name_for(self.id))
18
+ end
19
+
20
+ def file_name_for(asset = nil)
21
+ extension = filename.scan(/\.\w+$/)
22
+ return "#{asset}_#{filename}"
23
+ end
24
+ end
@@ -0,0 +1,30 @@
1
+ class CreateCkeditorAssets < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :ckeditor_assets do |t|
4
+ t.integer "parent_id"
5
+ t.string "content_type"
6
+ t.string "filename", :limit=>80
7
+ t.string "thumbnail", :limit=>20
8
+ t.integer "size"
9
+ t.integer "width"
10
+ t.integer "height"
11
+ t.string "type", :limit=>40
12
+ t.integer "user_id"
13
+ t.integer "assetable_id"
14
+ t.string "assetable_type", :limit=>40
15
+
16
+ t.timestamps
17
+ end
18
+
19
+ add_index "ckeditor_assets", ["assetable_id", "assetable_type", "type"], :name => "ndx_type_assetable"
20
+ add_index "ckeditor_assets", ["assetable_id", "assetable_type"], :name => "fk_assets"
21
+ add_index "ckeditor_assets", ["parent_id", "type"], :name => "ndx_type_name"
22
+ add_index "ckeditor_assets", ["thumbnail", "parent_id"], :name => "assets_thumbnail_parent_id"
23
+ add_index "ckeditor_assets", ["user_id", "assetable_type", "assetable_id"], :name => "assets_user_type_assetable_id"
24
+ add_index :ckeditor_assets, :user_id, :name => "fk_user"
25
+ end
26
+
27
+ def self.down
28
+ drop_table :ckeditor_assets
29
+ end
30
+ end
@@ -0,0 +1,25 @@
1
+ class Ckeditor::Picture < Ckeditor::Asset
2
+ has_attachment :content_type => :image,
3
+ :storage => :file_system, :path_prefix => 'public/assets/pictures',
4
+ :max_size => 2.megabytes,
5
+ :size => 0.kilobytes..2000.kilobytes,
6
+ :processor => 'Rmagick',
7
+ :thumbnails => { :content => '575>', :thumb => '100x100!' }
8
+
9
+ validates_as_attachment
10
+
11
+ def url_content
12
+ public_filename(:content)
13
+ end
14
+
15
+ def url_thumb
16
+ public_filename(:thumb)
17
+ end
18
+
19
+ def to_json(options = {})
20
+ options[:methods] ||= []
21
+ options[:methods] << :url_content
22
+ options[:methods] << :url_thumb
23
+ super options
24
+ end
25
+ end
@@ -0,0 +1,86 @@
1
+ class Ckeditor::Asset < ActiveRecord::Base
2
+ set_table_name "ckeditor_assets"
3
+
4
+ belongs_to :user
5
+ belongs_to :assetable, :polymorphic => true
6
+
7
+ before_validation :make_content_type
8
+ before_create :make_dimensions
9
+
10
+ def url(*args)
11
+ data.url(*args)
12
+ end
13
+ alias :public_filename :url
14
+
15
+ def filename
16
+ data_file_name
17
+ end
18
+
19
+ def content_type
20
+ data_content_type
21
+ end
22
+
23
+ def size
24
+ data_file_size
25
+ end
26
+
27
+ def path
28
+ data.path
29
+ end
30
+
31
+ def styles
32
+ data.styles
33
+ end
34
+
35
+ def format_created_at
36
+ I18n.l(self.created_at, :format=>"%d.%m.%Y %H:%M")
37
+ end
38
+
39
+ def to_xml(options = {})
40
+ builder = options[:builder] ||= Nokogiri::XML::Builder.new(options)
41
+
42
+ builder.send(self.type.to_s.downcase) do |xml|
43
+ xml.id_ self.id
44
+ xml.filename self.filename
45
+ xml.size self.size
46
+ xml.path self.url
47
+
48
+ xml.styles do
49
+ self.styles.each do |style|
50
+ xml.send(style.first, self.url(style.first))
51
+ end
52
+ end unless self.styles.empty?
53
+ end
54
+
55
+ builder.to_xml
56
+ end
57
+
58
+ def has_dimensions?
59
+ self.respond_to?(:width) && self.respond_to?(:height)
60
+ end
61
+
62
+ def image?
63
+ ["image/jpeg", "image/tiff", "image/png", "image/gif", "image/bmp"].include?(self.data_content_type)
64
+ end
65
+
66
+ def geometry
67
+ @geometry ||= Paperclip::Geometry.from_file(data.to_file)
68
+ @geometry
69
+ end
70
+
71
+ private
72
+
73
+ def make_dimensions
74
+ if image? && has_dimensions?
75
+ self.width = geometry.width
76
+ self.height = geometry.height
77
+ end
78
+ end
79
+
80
+ def make_content_type
81
+ if data_content_type == "application/octet-stream"
82
+ content_types = MIME::Types.type_for(filename)
83
+ self.data_content_type = content_types.first.to_s unless content_types.empty?
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,40 @@
1
+ class Ckeditor::AttachmentFile < Ckeditor::Asset
2
+ has_attached_file :data,
3
+ :url => "/ckeditor_assets/attachments/:id/:filename",
4
+ :path => ":rails_root/public/ckeditor_assets/attachments/:id/:filename"
5
+
6
+ validates_attachment_size :data, :less_than=>100.megabytes
7
+
8
+ def url(*args)
9
+ if [:thumb, :content].include?(args.first)
10
+ send("url_#{args.first}")
11
+ else
12
+ data.url(*args)
13
+ end
14
+ end
15
+
16
+ def url_content
17
+ data.url
18
+ end
19
+
20
+ def url_thumb
21
+ extname = File.extname(filename)
22
+
23
+ case extname.to_s
24
+ when '.swf' then '/javascripts/ckeditor/images/swf.gif'
25
+ when '.pdf' then '/javascripts/ckeditor/images/pdf.gif'
26
+ when '.doc', '.txt' then '/javascripts/ckeditor/images/doc.gif'
27
+ when '.mp3' then '/javascripts/ckeditor/images/mp3.gif'
28
+ when '.rar', '.zip', '.tg' then '/javascripts/ckeditor/images/rar.gif'
29
+ when '.xls' then '/javascripts/ckeditor/images/xls.gif'
30
+ else '/javascripts/ckeditor/images/ckfnothumb.gif'
31
+ end
32
+ end
33
+
34
+ def to_json(options = {})
35
+ options[:methods] ||= []
36
+ options[:methods] << :url_content
37
+ options[:methods] << :url_thumb
38
+ super options
39
+ end
40
+ end
@@ -0,0 +1,31 @@
1
+ class CreateCkeditorAssets < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :ckeditor_assets do |t|
4
+ t.string :data_file_name, :null => false
5
+ t.string :data_content_type
6
+ t.integer :data_file_size
7
+
8
+ t.integer :assetable_id
9
+ t.string :assetable_type, :limit => 30
10
+ t.string :type, :limit => 25
11
+ t.string :guid, :limit => 10
12
+
13
+ t.integer :locale, :limit => 1, :default => 0
14
+ t.integer :user_id
15
+
16
+ # Uncomment it to save images dimensions, if your need it
17
+ # t.integer :width
18
+ # t.integer :height
19
+
20
+ t.timestamps
21
+ end
22
+
23
+ add_index "ckeditor_assets", ["assetable_type", "type", "assetable_id"], :name => "idx_assetable_type"
24
+ add_index "ckeditor_assets", ["assetable_type", "assetable_id"], :name => "fk_assetable"
25
+ add_index "ckeditor_assets", ["user_id"], :name => "fk_user"
26
+ end
27
+
28
+ def self.down
29
+ drop_table :ckeditor_assets
30
+ end
31
+ end
@@ -0,0 +1,23 @@
1
+ class Ckeditor::Picture < Ckeditor::Asset
2
+ has_attached_file :data,
3
+ :url => "/ckeditor_assets/pictures/:id/:style_:basename.:extension",
4
+ :path => ":rails_root/public/ckeditor_assets/pictures/:id/:style_:basename.:extension",
5
+ :styles => { :content => '575>', :thumb => '80x80#' }
6
+
7
+ validates_attachment_size :data, :less_than=>2.megabytes
8
+
9
+ def url_content
10
+ url(:content)
11
+ end
12
+
13
+ def url_thumb
14
+ url(:thumb)
15
+ end
16
+
17
+ def to_json(options = {})
18
+ options[:methods] ||= []
19
+ options[:methods] << :url_content
20
+ options[:methods] << :url_thumb
21
+ super options
22
+ end
23
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 3
7
7
  - 2
8
- - 1
9
- version: 3.2.1
8
+ - 3
9
+ version: 3.2.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Igor Galeta
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-16 00:00:00 +03:00
17
+ date: 2010-05-18 00:00:00 +03:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
@@ -25,17 +25,14 @@ executables: []
25
25
  extensions: []
26
26
 
27
27
  extra_rdoc_files:
28
- - README.textile
29
- - TODO
28
+ - README.rdoc
30
29
  files:
31
30
  - CHANGELOG
32
- - README.textile
31
+ - README.rdoc
33
32
  - Rakefile
34
- - TODO
35
33
  - app/controllers/ckeditor_controller.rb
36
34
  - app/helpers/ckeditor_helper.rb
37
- - app/views/ckeditor/_file.html.erb
38
- - app/views/ckeditor/_image.html.erb
35
+ - app/views/ckeditor/_asset.html.erb
39
36
  - app/views/ckeditor/_swfupload.html.erb
40
37
  - app/views/ckeditor/files.html.erb
41
38
  - app/views/ckeditor/images.html.erb
@@ -43,12 +40,15 @@ files:
43
40
  - config/routes.rb
44
41
  - lib/ckeditor.rb
45
42
  - lib/ckeditor/engine.rb
46
- - lib/ckeditor/file_storage.rb
47
43
  - lib/ckeditor/form_builder.rb
44
+ - lib/ckeditor/formtastic.rb
45
+ - lib/ckeditor/middleware.rb
48
46
  - lib/ckeditor/utils.rb
49
47
  - lib/ckeditor/version.rb
50
48
  - lib/ckeditor/view_helper.rb
51
- - lib/generators/ckeditor_generator.rb
49
+ - lib/generators/USAGE
50
+ - lib/generators/ckeditor_core_generator.rb
51
+ - lib/generators/ckeditor_models_generator.rb
52
52
  - lib/generators/templates/ckeditor.rb
53
53
  - lib/generators/templates/ckeditor.yml
54
54
  - lib/generators/templates/ckeditor/CHANGES.html
@@ -650,6 +650,14 @@ files:
650
650
  - lib/generators/templates/ckeditor/swfupload/swfupload.swf
651
651
  - lib/generators/templates/ckeditor/swfupload/swfupload.swfobject.js
652
652
  - lib/generators/templates/ckeditor/themes/default/theme.js
653
+ - lib/generators/templates/models/attachment_fu/asset.rb
654
+ - lib/generators/templates/models/attachment_fu/attachment_file.rb
655
+ - lib/generators/templates/models/attachment_fu/migration.rb
656
+ - lib/generators/templates/models/attachment_fu/picture.rb
657
+ - lib/generators/templates/models/paperclip/asset.rb
658
+ - lib/generators/templates/models/paperclip/attachment_file.rb
659
+ - lib/generators/templates/models/paperclip/migration.rb
660
+ - lib/generators/templates/models/paperclip/picture.rb
653
661
  - lib/tasks/ckeditor_tasks.rake
654
662
  has_rdoc: true
655
663
  homepage: http://github.com/galetahub/rails-ckeditor
@@ -686,9 +694,9 @@ test_files:
686
694
  - examples/migrations/paperclip/create_assets.rb
687
695
  - examples/s3/attachment_file.rb
688
696
  - examples/s3/picture.rb
689
- - examples/models/attachment_fu/attachment_file.rb
690
697
  - examples/models/attachment_fu/asset.rb
698
+ - examples/models/attachment_fu/attachment_file.rb
691
699
  - examples/models/attachment_fu/picture.rb
692
- - examples/models/paperclip/attachment_file.rb
693
700
  - examples/models/paperclip/asset.rb
701
+ - examples/models/paperclip/attachment_file.rb
694
702
  - examples/models/paperclip/picture.rb