ckeditor 3.2.1 → 3.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,225 +0,0 @@
1
- h1. Rails CKEditor integration plugin with SWFUpload support
2
-
3
- CKEditor is a text editor to be used inside web pages. It's a WYSIWYG editor, which means that the text being edited on it looks as similar as possible to
4
- the results users have when publishing it. It brings to the web common editing features found on desktop editing applications like Microsoft Word and OpenOffice.
5
-
6
- Because CKEditor is licensed under flexible Open Source and commercial licenses, you'll be able to integrate and use it inside any kind of application.
7
- This is the ideal editor for developers, created to provide easy and powerful solutions to their users.
8
-
9
- CKEditor version: 3.2.1
10
- SWFUpload version: 2.2.0
11
- Rails version: 2.3.x
12
-
13
- "ckeditor.com":http://ckeditor.com/
14
- "swfupload.org":http://swfupload.org/
15
-
16
- Demo appication:
17
- "rails-ckeditor-demo-app":http://github.com/galetahub/rails-ckeditor-demo-app
18
-
19
- h2. Install
20
-
21
- h3. Rails 3.0
22
-
23
- @gem install ckeditor@
24
-
25
- In "Gemfile":
26
- @gem 'ckeditor', '3.2.1'@
27
-
28
- @rails generate ckeditor [options]@
29
-
30
- Runtime options:
31
- -f, [--force] # Overwrite files that already exist
32
- -p, [--pretend] # Run but do not make any changes
33
- -q, [--quiet] # Supress status output
34
- -s, [--skip] # Skip files that already exist
35
-
36
- Check @config/initializers/ckeditor.rb@ for more configuration options
37
-
38
- h3. Rails 2.x
39
-
40
- @./script/plugin install git://github.com/galetahub/rails-ckeditor.git@
41
-
42
- @rake ckeditor:install@
43
-
44
- @rake ckeditor:config@
45
-
46
- Last rake generated file config/ckeditor.yml:
47
-
48
- For attachment_fu: @swf_file_post_name: "uploaded_data"@
49
-
50
- h2. Usage
51
-
52
- Basically include this in the page you wish to use the editor in
53
- <pre><code>
54
- <%= javascript_include_tag :ckeditor %>
55
- </code></pre>
56
-
57
- Then instead of the normal textarea helper from Rails use this one
58
- <pre><code>
59
- <%= ckeditor_textarea("object", "field", :width => '100%', :height => '200px') %>
60
- </code></pre>
61
-
62
- FormBuilder helper for more usefully
63
-
64
- <pre><code>
65
- <%= form_for :page, :url => pages_path do |form| -%>
66
- ...
67
- <%= form.cktext_area :notes, :toolbar=>'Full', :width=>'400px', :heigth=>'200px' %>
68
- ...
69
- <%= form.cktext_area :content, :swf_params=>{:assetable_type=>'User', :assetable_id=>current_user.id} %>
70
- ...
71
- <% end -%>
72
- </code></pre>
73
-
74
- h3. Support options
75
- <pre><code>
76
- :cols # Textarea cols
77
- :rows # Textarea rows
78
- :width # Editor width
79
- :height # Editor height
80
- :class # Textarea css class name
81
- :toolbar # Toolbar name
82
- :skin # Editor skin
83
- :language # Editor language
84
- :swf_params # SWFUpload additional params
85
- </code></pre>
86
-
87
- Check @public/javascripts/ckeditor/config.js@ for config default options.
88
- Modify @public/javascripts/ckeditor/contents.css@ - this stylesheet use editor
89
-
90
- h3. AJAX
91
-
92
- To use a remote form you need to do something like this
93
- <pre><code>
94
- <%= form_remote_tag :url => @options.merge(:controller => @scaffold_controller),
95
- :before => Ckeditor_before_js('note', 'text') %>
96
-
97
- <%= ckeditor_textarea( "note", "text", :ajax => true ) %>
98
-
99
- <%= end_form_tag %>
100
- </code></pre>
101
-
102
- If you forget to put in the :before it won't work, you can also use the Ckeditor_form_remote_tag described below
103
-
104
- h3. Multiple Editors in a form
105
-
106
- To create a form using multiple editors use the Ckeditor_form_remote_tag helper and pass the :editors option. This takes an hash of model symbol keys with each having
107
- an array as its value. The array should contain the list of fields that will have editors attached to them.
108
- <pre><code>
109
- <%= ckeditor_form_remote_tag :url => @options.merge(:controller => @scaffold_controller),
110
- :editors => { :multinote => ['text1', 'text2'] } %>
111
-
112
- <%= ckeditor_textarea( "multinote", "text1", :ajax => true ) %>
113
- <%= ckeditor_textarea( "multinote", "text2", :ajax => true ) %>
114
-
115
- <%= end_form_tag %>
116
- </code></pre>
117
-
118
- h3. File uploads
119
-
120
- We recommend using a paperclip plugin for file storage and processing images. Controller @../rails-ckeditor/app/controllers/ckeditor_controller.rb@ has actions
121
- for displaying and uploading files. It uses classes Picture and AttachmentFile, who are descendants of the Asset class. So, your project must have these classes.
122
-
123
- "http://github.com/thoughtbot/paperclip":http://github.com/thoughtbot/paperclip
124
-
125
- For S3 storage look at @../rails-ckeditor/examples/s3@
126
-
127
- For paperclip:
128
- ActiveRecord model Asset (asset.rb):
129
- <pre><code>
130
- class Asset < ActiveRecord::Base
131
- belongs_to :user
132
- belongs_to :assetable, :polymorphic => true
133
-
134
- def url(*args)
135
- data.url(*args)
136
- end
137
- alias :public_filename :url
138
-
139
- def filename
140
- data_file_name
141
- end
142
-
143
- def content_type
144
- data_content_type
145
- end
146
-
147
- def size
148
- data_file_size
149
- end
150
-
151
- def path
152
- data.path
153
- end
154
-
155
- def styles
156
- data.styles
157
- end
158
-
159
- def format_created_at
160
- I18n.l(self.created_at, :format=>"%d.%m.%Y %H:%M")
161
- end
162
-
163
- def to_xml(options = {})
164
- xml = options[:builder] ||= Builder::XmlMarkup.new(:indent => options[:indent])
165
-
166
- xml.tag!(self.type.to_s.downcase) do
167
- xml.filename{ xml.cdata!(self.filename) }
168
- xml.size self.size
169
- xml.path{ xml.cdata!(self.url) }
170
-
171
- xml.styles do
172
- self.styles.each do |style|
173
- xml.tag!(style.first, self.url(style.first))
174
- end
175
- end unless self.styles.empty?
176
- end
177
- end
178
- end
179
- </pre></code>
180
-
181
- ActiveRecord model AttachmentFile (attachment_file.rb):
182
- <pre><code>
183
- class AttachmentFile < Asset
184
- has_attached_file :data,
185
- :url => "/assets/attachments/:id/:filename",
186
- :path => ":rails_root/public/assets/attachments/:id/:filename"
187
-
188
- validates_attachment_size :data, :less_than => 10.megabytes
189
- end
190
- </pre></code>
191
-
192
- ActiveRecord model Picture (picture.rb):
193
- <pre><code>
194
- class Picture < Asset
195
- has_attached_file :data,
196
- :url => "/assets/pictures/:id/:style_:basename.:extension",
197
- :path => ":rails_root/public/assets/pictures/:id/:style_:basename.:extension",
198
- :styles => { :content => '575>', :thumb => '100x100' }
199
-
200
- validates_attachment_size :data, :less_than => 2.megabytes
201
-
202
- def url_content
203
- url(:content)
204
- end
205
-
206
- def url_thumb
207
- url(:thumb)
208
- end
209
-
210
- def to_json(options = {})
211
- options[:methods] ||= []
212
- options[:methods] << :url_content
213
- options[:methods] << :url_thumb
214
- super options
215
- end
216
- end
217
- </code></pre>
218
-
219
- More info in @../rails-ckeditor/examples/models@.
220
- Do not forget about migration @../rails-ckeditor/examples/migrations@.
221
-
222
- h2. TODOs
223
-
224
- 1. Add support for choose filemanager storage
225
- 2. More integration upload system
data/TODO DELETED
@@ -1,3 +0,0 @@
1
- # Select different file upload process (currently is only swfupload)
2
- # Select file storage
3
- # Add more config options
@@ -1,15 +0,0 @@
1
- <div class="FCKThumb">
2
- <table border="0" cellpadding="0" cellspacing="0" height="100" width="100">
3
- <tbody>
4
- <tr>
5
- <td align="center" valign="middle">
6
- <%= file_image_tag(file.filename, file.url) %>
7
- </td>
8
- </tr>
9
- </tbody>
10
- </table>
11
-
12
- <div class="FCKFileName"><%= file.filename %></div>
13
- <div class="FCKFileDate"><%= file.format_created_at %></div>
14
- <div class="FCKFileSize"><%= number_to_human_size(file.size, :precision => 2) %></div>
15
- </div>
@@ -1,15 +0,0 @@
1
- <div class="FCKThumb">
2
- <table border="0" cellpadding="0" cellspacing="0" height="100" width="100">
3
- <tbody>
4
- <tr>
5
- <td align="center" valign="middle">
6
- <%= image_tag(image.url(:thumb), :alt=>image.url(:content), :title=>image.filename, :onerror=>"this.src='/javascripts/ckeditor/images/ckfnothumb.gif'", :class=>'image' ) %>
7
- </td>
8
- </tr>
9
- </tbody>
10
- </table>
11
-
12
- <div class="FCKFileName"><%= image.filename %></div>
13
- <div class="FCKFileDate"><%= image.format_created_at %></div>
14
- <div class="FCKFileSize"><%= number_to_human_size(image.size, :precision => 2) %></div>
15
- </div>
@@ -1,178 +0,0 @@
1
- module Ckeditor
2
- class CkeditorFileStorage
3
- UPLOAD_FOLDER = "/uploads"
4
- UPLOAD_ROOT = RAILS_ROOT + "/public" + UPLOAD_FOLDER
5
-
6
- MIME_TYPES = [
7
- "image/jpg",
8
- "image/jpeg",
9
- "image/pjpeg",
10
- "image/gif",
11
- "image/png",
12
- "application/x-shockwave-flash"
13
- ]
14
-
15
- def get_folders_and_files(include_files = true)
16
- @folders = Array.new
17
- @files = {}
18
- begin
19
- @ck_url = upload_directory_path
20
- @current_folder = current_directory_path
21
- Dir.entries(@current_folder).each do |entry|
22
- next if entry =~ /^\./
23
- path = @current_folder + entry
24
- @folders.push entry if FileTest.directory?(path)
25
- @files[entry] = (File.size(path) / 1024) if (include_files and FileTest.file?(path))
26
- end
27
- rescue => e
28
- @errorNumber = 110 if @errorNumber.nil?
29
- end
30
- end
31
-
32
- def create_folder
33
- begin
34
- @ck_url = current_directory_path
35
- path = @ck_url + params[:newFolderName]
36
- if !(File.stat(@ck_url).writable?)
37
- @errorNumber = 103
38
- elsif params[:newFolderName] !~ /[\w\d\s]+/
39
- @errorNumber = 102
40
- elsif FileTest.exists?(path)
41
- @errorNumber = 101
42
- else
43
- Dir.mkdir(path,0775)
44
- @errorNumber = 0
45
- end
46
- rescue => e
47
- @errorNumber = 110 if @errorNumber.nil?
48
- end
49
- end
50
-
51
- def upload_file
52
- begin
53
- load_file_from_params
54
- copy_tmp_file(@new_file) if mime_types_ok(@ftype)
55
- rescue => e
56
- @errorNumber = 110 if @errorNumber.nil?
57
- end
58
-
59
- render :text => %Q'
60
- <script>
61
- window.parent.OnUploadCompleted(#{@errorNumber}, "#{uploaded_file_path}");
62
- </script>'
63
- end
64
-
65
- def upload
66
- self.upload_file
67
- end
68
-
69
- #################################################################################
70
- #
71
- private
72
-
73
- def load_file_from_params
74
- @new_file = check_file(params[:newFile])
75
- @ck_url = upload_directory_path
76
- @ftype = @new_file.content_type.strip
77
- log_upload
78
- end
79
-
80
- ##############################################################################
81
- # Chek if mime type is included in the MIME_TYPES
82
- #
83
- def mime_types_ok(ftype)
84
- mime_type_ok = MIME_TYPES.include?(ftype) ? true : false
85
- if mime_type_ok
86
- @errorNumber = 0
87
- else
88
- @errorNumber = 202
89
- raise_mime_type_and_show_msg(ftype)
90
- end
91
- mime_type_ok
92
- end
93
-
94
- ##############################################################################
95
- # Raise and exception, log the msg error and show msg
96
- #
97
- def raise_mime_type_and_show_msg(ftype)
98
- msg = "#{ftype} is invalid MIME type"
99
- puts msg;
100
- raise msg;
101
- log msg
102
- end
103
-
104
- ##############################################################################
105
- # Copy tmp file to current_directory_path/tmp_file.original_filename
106
- #
107
- def copy_tmp_file(tmp_file)
108
- path = current_directory_path + "/" + tmp_file.original_filename
109
- File.open(path, "wb", 0664) do |fp|
110
- FileUtils.copy_stream(tmp_file, fp)
111
- end
112
- end
113
-
114
- ##############################################################################
115
- # Puts a messgae info in the current log, only if RAILS_ENV is 'development'
116
- #
117
- def log(str)
118
- RAILS_DEFAULT_LOGGER.info str if RAILS_ENV == 'development'
119
- end
120
-
121
- ##############################################################################
122
- # Puts some data in the current log
123
- #
124
- def log_upload
125
- log "CKEDITOR - #{params[:newFile]}"
126
- log "CKEDITOR - UPLOAD_FOLDER: #{UPLOAD_FOLDER}"
127
- log "CKEDITOR - #{File.expand_path(RAILS_ROOT)}/public#{UPLOAD_FOLDER}/" +
128
- "#{@new_file.original_filename}"
129
- end
130
-
131
- ##############################################################################
132
- # Returns the filesystem folder with the current folder
133
- #
134
- def current_directory_path
135
- base_dir = "#{UPLOAD_ROOT}/#{UPLOAD_FOLDER}/#{params[:type]}"
136
- Dir.mkdir(base_dir,0775) unless File.exists?(base_dir)
137
- check_path("#{base_dir}#{params[:currentFolder]}")
138
- end
139
-
140
- ##############################################################################
141
- # Returns the upload url folder with the current folder
142
- #
143
- def upload_directory_path
144
- url_root = ActionController::Base.relative_url_root.to_s
145
- uploaded = url_root + "#{UPLOAD_FOLDER}/#{params[:Type]}"
146
- "#{uploaded}#{params[:currentFolder]}"
147
- end
148
-
149
- ##############################################################################
150
- # Current uploaded file path
151
- #
152
- def uploaded_file_path
153
- "#{upload_directory_path}/#{@new_file.original_filename}"
154
- end
155
-
156
- ##############################################################################
157
- # check that the file is a tempfile object
158
- #
159
- def check_file(file)
160
- log "CKEDITOR ---- CLASS OF UPLOAD OBJECT: #{file.class}"
161
-
162
- unless "#{file.class}" == "Tempfile" || "StringIO"
163
- @errorNumber = 403
164
- throw Exception.new
165
- end
166
- file
167
- end
168
-
169
- def check_path(path)
170
- exp_path = File.expand_path path
171
- if exp_path !~ %r[^#{File.expand_path(UPLOAD_ROOT)}]
172
- @errorNumber = 403
173
- throw Exception.new
174
- end
175
- path
176
- end
177
- end
178
- end