ckeditor 3.5.4 → 3.6.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (179) hide show
  1. data/Gemfile +23 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +96 -97
  4. data/Rakefile +16 -33
  5. data/app/controllers/ckeditor/attachment_files_controller.rb +4 -4
  6. data/app/controllers/ckeditor/base_controller.rb +15 -42
  7. data/app/controllers/ckeditor/pictures_controller.rb +3 -3
  8. data/app/views/ckeditor/attachment_files/index.html.erb +13 -51
  9. data/app/views/ckeditor/pictures/index.html.erb +14 -52
  10. data/app/views/ckeditor/shared/_asset.html.erb +19 -0
  11. data/app/views/ckeditor/shared/_asset_tmpl.html.erb +21 -0
  12. data/app/views/layouts/ckeditor.html.erb +16 -23
  13. data/config/locales/en.ckeditor.yml +3 -7
  14. data/config/locales/ru.ckeditor.yml +4 -8
  15. data/config/locales/uk.ckeditor.yml +4 -8
  16. data/config/routes.rb +3 -3
  17. data/lib/ckeditor.rb +30 -79
  18. data/lib/ckeditor/engine.rb +14 -13
  19. data/lib/ckeditor/helpers/controllers.rb +30 -0
  20. data/lib/ckeditor/helpers/form_builder.rb +11 -0
  21. data/lib/ckeditor/helpers/form_helper.rb +25 -0
  22. data/lib/ckeditor/helpers/view_helper.rb +19 -0
  23. data/lib/ckeditor/http.rb +81 -0
  24. data/lib/ckeditor/orm/active_record.rb +91 -0
  25. data/lib/ckeditor/utils.rb +51 -70
  26. data/lib/ckeditor/version.rb +2 -7
  27. data/lib/generators/ckeditor/install_generator.rb +62 -0
  28. data/lib/generators/ckeditor/models_generator.rb +51 -0
  29. data/lib/generators/ckeditor/templates/ckeditor.rb +18 -0
  30. data/lib/generators/ckeditor/templates/ckeditor/config.js +52 -0
  31. data/lib/generators/ckeditor/templates/ckeditor/filebrowser/images/gal_add.jpg +0 -0
  32. data/lib/generators/ckeditor/templates/ckeditor/filebrowser/images/gal_add.png +0 -0
  33. data/lib/generators/ckeditor/templates/ckeditor/filebrowser/images/gal_del.png +0 -0
  34. data/lib/generators/ckeditor/templates/ckeditor/filebrowser/images/gal_more.gif +0 -0
  35. data/lib/generators/ckeditor/templates/ckeditor/filebrowser/images/preloader.gif +0 -0
  36. data/lib/generators/ckeditor/{base/templates/ckeditor/images → templates/ckeditor/filebrowser/images/thumbs}/ckfnothumb.gif +0 -0
  37. data/lib/generators/ckeditor/{base/templates/ckeditor/images → templates/ckeditor/filebrowser/images/thumbs}/mp3.gif +0 -0
  38. data/lib/generators/ckeditor/{base/templates/ckeditor/images → templates/ckeditor/filebrowser/images/thumbs}/pdf.gif +0 -0
  39. data/lib/generators/ckeditor/{base/templates/ckeditor/images → templates/ckeditor/filebrowser/images/thumbs}/rar.gif +0 -0
  40. data/lib/generators/ckeditor/{base/templates/ckeditor/images → templates/ckeditor/filebrowser/images/thumbs}/swf.gif +0 -0
  41. data/lib/generators/ckeditor/{base/templates/ckeditor/images → templates/ckeditor/filebrowser/images/thumbs}/xls.gif +0 -0
  42. data/lib/generators/ckeditor/templates/ckeditor/filebrowser/javascripts/application.js +222 -0
  43. data/lib/generators/ckeditor/templates/ckeditor/filebrowser/stylesheets/uploader.css +112 -0
  44. data/lib/generators/ckeditor/{base/templates → templates}/ckeditor/plugins/attachment/dialogs/attachment.js +0 -0
  45. data/lib/generators/ckeditor/{base/templates/ckeditor/_source → templates/ckeditor}/plugins/attachment/images/attachment.png +0 -0
  46. data/lib/generators/ckeditor/{base/templates/ckeditor/_source → templates/ckeditor}/plugins/attachment/lang/en.js +0 -0
  47. data/lib/generators/ckeditor/{base/templates/ckeditor/_source → templates/ckeditor}/plugins/attachment/lang/ru.js +0 -0
  48. data/lib/generators/ckeditor/{base/templates/ckeditor/_source → templates/ckeditor}/plugins/attachment/lang/uk.js +0 -0
  49. data/lib/generators/ckeditor/{base/templates → templates}/ckeditor/plugins/attachment/plugin.js +0 -0
  50. data/lib/generators/ckeditor/{base/templates → templates}/ckeditor/plugins/embed/dialogs/embed.js +0 -0
  51. data/lib/generators/ckeditor/{base/templates/ckeditor/_source → templates/ckeditor}/plugins/embed/images/embed.png +0 -0
  52. data/lib/generators/ckeditor/{base/templates/ckeditor/_source → templates/ckeditor}/plugins/embed/lang/en.js +0 -0
  53. data/lib/generators/ckeditor/{base/templates/ckeditor/_source → templates/ckeditor}/plugins/embed/lang/ru.js +0 -0
  54. data/lib/generators/ckeditor/{base/templates/ckeditor/_source → templates/ckeditor}/plugins/embed/lang/uk.js +0 -0
  55. data/lib/generators/ckeditor/{base/templates → templates}/ckeditor/plugins/embed/plugin.js +0 -0
  56. data/lib/generators/ckeditor/templates/models/active_record/asset.rb +7 -0
  57. data/lib/generators/ckeditor/templates/models/active_record/attachment_file.rb +15 -0
  58. data/lib/generators/ckeditor/{migration/templates/models/paperclip → templates/models/active_record}/migration.rb +3 -8
  59. data/lib/generators/ckeditor/templates/models/active_record/picture.rb +13 -0
  60. data/test/ckeditor_test.rb +13 -0
  61. data/test/controllers/attachment_files_controller_test.rb +52 -0
  62. data/test/controllers/pictures_controller_test.rb +52 -0
  63. data/test/dummy/Rakefile +7 -0
  64. data/test/dummy/app/controllers/application_controller.rb +4 -0
  65. data/test/dummy/app/controllers/posts_controller.rb +83 -0
  66. data/test/dummy/app/helpers/application_helper.rb +2 -0
  67. data/test/dummy/app/helpers/posts_helper.rb +2 -0
  68. data/test/dummy/app/models/ckeditor/asset.rb +7 -0
  69. data/test/dummy/app/models/ckeditor/attachment_file.rb +15 -0
  70. data/test/dummy/app/models/ckeditor/picture.rb +13 -0
  71. data/test/dummy/app/models/post.rb +3 -0
  72. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  73. data/test/dummy/app/views/posts/_form.html.erb +30 -0
  74. data/test/dummy/app/views/posts/edit.html.erb +6 -0
  75. data/test/dummy/app/views/posts/index.html.erb +27 -0
  76. data/test/dummy/app/views/posts/new.html.erb +5 -0
  77. data/test/dummy/app/views/posts/show.html.erb +5 -0
  78. data/test/dummy/config.ru +4 -0
  79. data/test/dummy/config/application.rb +46 -0
  80. data/test/dummy/config/boot.rb +10 -0
  81. data/test/dummy/config/database.yml +34 -0
  82. data/test/dummy/config/environment.rb +5 -0
  83. data/test/dummy/config/environments/development.rb +26 -0
  84. data/test/dummy/config/environments/production.rb +49 -0
  85. data/test/dummy/config/environments/test.rb +35 -0
  86. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  87. data/test/dummy/config/initializers/ckeditor.rb +18 -0
  88. data/test/dummy/config/initializers/inflections.rb +10 -0
  89. data/test/dummy/config/initializers/mime_types.rb +5 -0
  90. data/test/dummy/config/initializers/secret_token.rb +7 -0
  91. data/test/dummy/config/initializers/session_store.rb +8 -0
  92. data/test/dummy/config/locales/en.yml +5 -0
  93. data/test/dummy/config/routes.rb +4 -0
  94. data/test/dummy/db/migrate/20110623120047_create_posts.rb +14 -0
  95. data/test/dummy/db/migrate/20110705195648_create_ckeditor_assets.rb +26 -0
  96. data/test/dummy/db/schema.rb +36 -0
  97. data/test/dummy/log/development.log +818 -0
  98. data/test/dummy/log/production.log +0 -0
  99. data/test/dummy/log/server.log +0 -0
  100. data/test/dummy/log/test.log +5398 -0
  101. data/test/dummy/public/404.html +26 -0
  102. data/test/dummy/public/422.html +26 -0
  103. data/test/dummy/public/500.html +26 -0
  104. data/test/dummy/public/favicon.ico +0 -0
  105. data/test/dummy/public/javascripts/application.js +2 -0
  106. data/test/dummy/public/javascripts/controls.js +965 -0
  107. data/test/dummy/public/javascripts/dragdrop.js +974 -0
  108. data/test/dummy/public/javascripts/effects.js +1123 -0
  109. data/test/dummy/public/javascripts/prototype.js +6001 -0
  110. data/test/dummy/public/javascripts/rails.js +191 -0
  111. data/test/dummy/public/stylesheets/scaffold.css +56 -0
  112. data/test/dummy/script/rails +6 -0
  113. data/test/dummy/test/fixtures/files/rails.png +0 -0
  114. data/test/dummy/test/fixtures/files/rails.tar.gz +0 -0
  115. data/test/generators/install_generator_test.rb +18 -0
  116. data/test/generators/models_generator_test.rb +21 -0
  117. data/test/integration/navigation_test.rb +7 -0
  118. data/test/integration/posts_test.rb +41 -0
  119. data/test/routes_test.rb +47 -0
  120. data/test/support/integration_case.rb +5 -0
  121. data/test/test_helper.rb +28 -0
  122. data/test/tmp/app/models/ckeditor/asset.rb +7 -0
  123. data/test/tmp/app/models/ckeditor/attachment_file.rb +15 -0
  124. data/test/tmp/app/models/ckeditor/picture.rb +13 -0
  125. data/test/tmp/db/migrate/20110711170413_create_ckeditor_assets.rb +26 -0
  126. metadata +220 -99
  127. data/CHANGELOG +0 -15
  128. data/app/helpers/ckeditor/base_helper.rb +0 -21
  129. data/app/views/ckeditor/_asset.html.erb +0 -20
  130. data/app/views/ckeditor/_swfupload.html.erb +0 -73
  131. data/lib/ckeditor/form_builder.rb +0 -22
  132. data/lib/ckeditor/middleware.rb +0 -18
  133. data/lib/ckeditor/view_helper.rb +0 -92
  134. data/lib/generators/ckeditor/base/USAGE +0 -9
  135. data/lib/generators/ckeditor/base/base_generator.rb +0 -41
  136. data/lib/generators/ckeditor/base/templates/ckeditor.rb +0 -54
  137. data/lib/generators/ckeditor/base/templates/ckeditor/_source/plugins/attachment/dialogs/attachment.js +0 -384
  138. data/lib/generators/ckeditor/base/templates/ckeditor/_source/plugins/attachment/plugin.js +0 -44
  139. data/lib/generators/ckeditor/base/templates/ckeditor/_source/plugins/embed/dialogs/embed.js +0 -65
  140. data/lib/generators/ckeditor/base/templates/ckeditor/_source/plugins/embed/plugin.js +0 -43
  141. data/lib/generators/ckeditor/base/templates/ckeditor/config.js +0 -43
  142. data/lib/generators/ckeditor/base/templates/ckeditor/css/ckfinder.css +0 -316
  143. data/lib/generators/ckeditor/base/templates/ckeditor/css/fck_dialog.css +0 -119
  144. data/lib/generators/ckeditor/base/templates/ckeditor/css/fck_editor.css +0 -448
  145. data/lib/generators/ckeditor/base/templates/ckeditor/css/swfupload.css +0 -94
  146. data/lib/generators/ckeditor/base/templates/ckeditor/images/add.gif +0 -0
  147. data/lib/generators/ckeditor/base/templates/ckeditor/images/cancelbutton.gif +0 -0
  148. data/lib/generators/ckeditor/base/templates/ckeditor/images/doc.gif +0 -0
  149. data/lib/generators/ckeditor/base/templates/ckeditor/images/refresh.gif +0 -0
  150. data/lib/generators/ckeditor/base/templates/ckeditor/images/select_files.png +0 -0
  151. data/lib/generators/ckeditor/base/templates/ckeditor/images/spacer.gif +0 -0
  152. data/lib/generators/ckeditor/base/templates/ckeditor/images/toolbar.start.gif +0 -0
  153. data/lib/generators/ckeditor/base/templates/ckeditor/plugins/attachment/images/attachment.png +0 -0
  154. data/lib/generators/ckeditor/base/templates/ckeditor/plugins/attachment/lang/en.js +0 -10
  155. data/lib/generators/ckeditor/base/templates/ckeditor/plugins/attachment/lang/ru.js +0 -10
  156. data/lib/generators/ckeditor/base/templates/ckeditor/plugins/attachment/lang/uk.js +0 -10
  157. data/lib/generators/ckeditor/base/templates/ckeditor/plugins/embed/images/embed.png +0 -0
  158. data/lib/generators/ckeditor/base/templates/ckeditor/plugins/embed/lang/en.js +0 -9
  159. data/lib/generators/ckeditor/base/templates/ckeditor/plugins/embed/lang/ru.js +0 -9
  160. data/lib/generators/ckeditor/base/templates/ckeditor/plugins/embed/lang/uk.js +0 -9
  161. data/lib/generators/ckeditor/base/templates/ckeditor/swfupload/fileprogress.js +0 -266
  162. data/lib/generators/ckeditor/base/templates/ckeditor/swfupload/handlers.js +0 -181
  163. data/lib/generators/ckeditor/base/templates/ckeditor/swfupload/jquery-1.5.1.min.js +0 -16
  164. data/lib/generators/ckeditor/base/templates/ckeditor/swfupload/querystring.js +0 -40
  165. data/lib/generators/ckeditor/base/templates/ckeditor/swfupload/rails.js +0 -158
  166. data/lib/generators/ckeditor/base/templates/ckeditor/swfupload/swfupload.js +0 -1
  167. data/lib/generators/ckeditor/base/templates/ckeditor/swfupload/swfupload.queue.js +0 -1
  168. data/lib/generators/ckeditor/base/templates/ckeditor/swfupload/swfupload.swf +0 -0
  169. data/lib/generators/ckeditor/base/templates/ckeditor/swfupload/swfupload.swfobject.js +0 -111
  170. data/lib/generators/ckeditor/migration/USAGE +0 -12
  171. data/lib/generators/ckeditor/migration/migration_generator.rb +0 -46
  172. data/lib/generators/ckeditor/migration/templates/models/attachment_fu/asset.rb +0 -32
  173. data/lib/generators/ckeditor/migration/templates/models/attachment_fu/attachment_file.rb +0 -24
  174. data/lib/generators/ckeditor/migration/templates/models/attachment_fu/migration.rb +0 -30
  175. data/lib/generators/ckeditor/migration/templates/models/attachment_fu/picture.rb +0 -25
  176. data/lib/generators/ckeditor/migration/templates/models/paperclip/asset.rb +0 -97
  177. data/lib/generators/ckeditor/migration/templates/models/paperclip/attachment_file.rb +0 -40
  178. data/lib/generators/ckeditor/migration/templates/models/paperclip/picture.rb +0 -23
  179. data/lib/tasks/ckeditor_tasks.rake +0 -3
data/Gemfile ADDED
@@ -0,0 +1,23 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem "rails", "3.0.9"
6
+
7
+ platforms :ruby do
8
+ gem "mysql2", '0.2.11'
9
+
10
+ group :development, :test do
11
+ gem "capybara", ">= 0.4.0"
12
+ gem "redgreen", "~> 1.2.2"
13
+ gem "paperclip", "~> 2.3.12"
14
+
15
+ # To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
16
+ # gem 'ruby-debug'
17
+ # gem 'ruby-debug19'
18
+ end
19
+
20
+ group :development do
21
+ gem "mongrel"
22
+ end
23
+ end
@@ -0,0 +1,20 @@
1
+ Copyright 2011 AIMBULANCE
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,89 +1,59 @@
1
- = Rails CKEditor integration plugin with SWFUpload support
1
+ = Ckeditor
2
2
 
3
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
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
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.
6
+ == Features
8
7
 
9
- CKEditor version: any (http://ckeditor.com/download/releases)
8
+ * Rails 3 integration
9
+ * Files browser
10
+ * HTML5 files uploader
11
+ * Hooks for formtastic and simple_form forms generators
12
+ * Extra plugins: attachment and embed.
13
+ * Assets pagination (under construction)
10
14
 
11
- SWFUpload version: 2.2.0.1 Core (http://swfupload.org)
15
+ == Install (not currently available, under construction)
12
16
 
13
- Rails version: 3.x
14
-
15
- Demo appication (Rails 2.3.8):
16
- http://github.com/galetahub/rails-ckeditor-demo-app
17
-
18
- Demo appication (Rails 3.x):
19
- http://github.com/galetahub/ckeditor-demo-app
20
-
21
- == Install
22
-
23
- === Rails 3
24
-
25
- In your appication "Gemfile":
26
-
27
- gem 'ckeditor'
17
+ gem "ckeditor", "~> 3.6.0"
28
18
 
29
- or
30
- gem 'ckeditor', :git => 'git://github.com/galetahub/rails-ckeditor.git', :branch => 'rails3'
19
+ rails generate ckeditor:install
31
20
 
32
- Next step is download ckeditor core files and generate configuration file
33
- Check "config/initializers/ckeditor.rb" for more configuration options:
21
+ You can pass version of ckeditor to download (http://ckeditor.com/download/releases):
34
22
 
35
- rails generate ckeditor:base
23
+ rails generate ckeditor:install --version=3.5.4
36
24
 
37
- You can pass version of ckeditor to download (http://ckeditor.com/download/releases):
25
+ Now generate models for store uploading files:
38
26
 
39
- rails generate ckeditor:base --version=3.5.4
27
+ rails generate ckeditor:models --orm=active_record
40
28
 
41
- Generate ckeditor models for file upload support:
42
- For paperclip:
29
+ Available orms:
30
+ * active_record
31
+ * mongo_mapper (under construction)
32
+ * mongoid (under construction)
43
33
 
44
- rails generate ckeditor:migration
34
+ Autoload ckeditor models folder (application.rb):
45
35
 
46
- For attachment_fu:
36
+ config.autoload_paths += %W(#{config.root}/app/models/ckeditor)
47
37
 
48
- rails generate ckeditor:migration --backend=attachment_fu
38
+ === Dependencies
49
39
 
50
- Don't forget about migration:
40
+ For active_record orm is used paperclip gem (it's by default).
51
41
 
52
- rake db:migrate
42
+ gem "paperclip"
43
+
44
+ For gem "carrierwave" shortly I will give an example.
53
45
 
54
46
  == Usage
55
47
 
56
- Basically include this in the page you wish to use the editor in:
57
-
58
48
  <%= javascript_include_tag :ckeditor %>
49
+
50
+ cktext_area_tag("test_area", "Ckeditor is the best")
59
51
 
60
- Then instead of the normal textarea helper from Rails use this one:
61
-
62
- <%= ckeditor_textarea("object", "field", :width => '100%', :height => '200px') %>
63
-
64
- FormBuilder helper for more usefully:
65
-
66
- <%= form_for @page do |form| -%>
67
- ...
68
- <%= form.cktext_area :notes, :toolbar=>'Full', :width=>'400px', :height=>'200px' %>
69
- ...
70
- <%= form.cktext_area :content, :swf_params=>{:assetable_type=>'User', :assetable_id=>current_user.id} %>
71
- ...
72
- <% end -%>
52
+ cktext_area_tag("content", "Ckeditor", :input_html => {:cols => 10, :rows => 20}, :toolbar => 'Easy')
73
53
 
74
- === Support options
75
-
76
- :cols # Textarea cols (default: 70)
77
- :rows # Textarea rows (default: 20)
78
- :width # Editor width (default: 100%)
79
- :height # Editor height (default: 100%)
80
- :class # Textarea css class name
81
- :toolbar # Toolbar name
82
- :skin # Editor skin
83
- :language # Editor language (default: I18n.locale)
84
- :swf_params # SWFUpload additional params (Hash)
85
- :id # textarea DOM element id
86
- :index # element id index
54
+ * input_html - Options for text_area tag, others for ckeditor javascript configuration.
55
+ * language - appends automatically, by default is I18n.locale
56
+ * available ckeditor options - http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.config.html
87
57
 
88
58
  For configure ckeditor default options check:
89
59
 
@@ -92,22 +62,21 @@ For configure ckeditor default options check:
92
62
  This stylesheet use editor for displaying edit area:
93
63
 
94
64
  public/javascripts/ckeditor/contents.css
95
-
96
- === AJAX
97
65
 
98
- To use a remote form you need to call "ckeditor_ajax_script" helper method:
66
+ FormBuilder helper for more usefully:
99
67
 
100
- <%= form_for @page, :remote => true do |form| -%>
101
- <%= form.cktext_area("note", "content") %>
68
+ <%= form_for @page do |form| -%>
102
69
  ...
103
- <%= form.cktext_area("note", "about") %>
70
+ <%= form.cktext_area :notes, :toolbar => 'Full', :width => 800, :height => 400 %>
104
71
  ...
105
- <%= ckeditor_ajax_script %>
72
+ <%= form.cktext_area :content, :input_html => { :value => "Default value" } %>
106
73
  ...
107
- <%= form.submit "Save" %>
108
- <% end %>
74
+ <%= cktext_area :page, :info %>
75
+ <% end -%>
76
+
77
+ === AJAX
109
78
 
110
- Helper "ckeditor_ajax_script" generate next script (jquery):
79
+ Jquery sample:
111
80
 
112
81
  <script type='text/javascript' charset='UTF-8'>
113
82
  $(document).ready(function(){
@@ -119,46 +88,76 @@ Helper "ckeditor_ajax_script" generate next script (jquery):
119
88
  });
120
89
  </script>
121
90
 
122
- == File uploads
91
+ === Formtastic integration
123
92
 
124
- We recommend using a paperclip plugin for file storage and processing images. Controller @../rails-ckeditor/app/controllers/ckeditor_controller.rb@ has actions
125
- 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.
126
-
127
- http://github.com/thoughtbot/paperclip
93
+ <%= form.input :content, :as => :ckeditor %>
94
+ <%= form.input :content, :as => :ckeditor, :input_html => { :height => 400 } %>
128
95
 
129
- For S3 storage look at "../ckeditor/examples/s3"
96
+ === SimpleForm integration
130
97
 
131
- == Formtastic integration
98
+ <%= form.ckeditor :content, :label => false, :input_html => { :toolbar => 'Full' } %>
132
99
 
133
- <%= form.input :content, :as => :ckeditor %>
134
- <%= form.input :content, :as => :ckeditor, :input_html => { :height => 400, :swf_params => { ... } } %>
100
+ === Default scope
135
101
 
136
- == SimpleForm integration
102
+ For example, you need split assets collection for each user.
137
103
 
138
- <%= form.ckeditor :content, :label => false, :input_html => { :height => 400, :toolbar=>'Full' } %>
104
+ class ApplicationController < ActionController::Base
105
+
106
+ protected
107
+
108
+ def ckeditor_filebrowser_scope(options = {})
109
+ super { :assetable_id => current_user.id, :assetable_type => 'User' }.merge(options)
110
+ end
111
+ end
112
+
113
+ If your wont filter only pictures or attachment_files - redefine methods "ckeditor_pictures_scope" or "ckeditor_attachment_files_scope" respectively.
114
+ By default, both these methods call "ckeditor_filebrowser_scope" method:
139
115
 
140
- == Middleware
116
+ class ApplicationController < ActionController::Base
117
+
118
+ protected
141
119
 
142
- Ckeditor appends middleware ("Ckeditor::Middleware") before session store to
143
- support swf upload with AuthenticityToken.
120
+ def ckeditor_pictures_scope(options = {})
121
+ ckeditor_filebrowser_scope(options)
122
+ end
123
+
124
+ def ckeditor_attachment_files_scope(options = {})
125
+ ckeditor_filebrowser_scope(options)
126
+ end
127
+ end
144
128
 
145
- rake middleware
129
+ === Callbacks
146
130
 
147
- == I18n
131
+ class ApplicationController < ActionController::Base
132
+
133
+ protected
134
+
135
+ # Cancan example
136
+ def ckeditor_authenticate
137
+ authorize! action_name, @asset
138
+ end
139
+
140
+ # Set current_user as assetable
141
+ def ckeditor_before_create_asset(asset)
142
+ asset.assetable = current_user
143
+ return true
144
+ end
145
+ end
146
+
147
+
148
+ == I18n
148
149
 
149
150
  en:
150
151
  ckeditor:
151
152
  page_title: "CKEditor Files Manager"
152
- upload_files: "Upload New Files"
153
+ confirm_delete: "Delete file?"
153
154
  buttons:
154
155
  cancel: "Cancel"
155
- refresh:
156
- title: "Refresh"
157
- hint: "Refresh page"
158
- upload:
159
- title: "Upload"
160
- hint: "Upload New File"
156
+ upload: "Upload"
157
+ delete: "Delete"
158
+
159
+ == Tests
161
160
 
162
- == TODOs
161
+ rake test
163
162
 
164
- 1. HTML5 File uploads
163
+ This project rocks and uses MIT-LICENSE.
data/Rakefile CHANGED
@@ -1,46 +1,29 @@
1
- # encoding: utf-8
1
+ # encoding: UTF-8
2
+ require 'rubygems'
3
+ begin
4
+ require 'bundler/setup'
5
+ rescue LoadError
6
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
7
+ end
8
+
2
9
  require 'rake'
3
- require 'rake/testtask'
4
- require 'rake/rdoctask'
5
- require File.join(File.dirname(__FILE__), 'lib', 'ckeditor', 'version')
10
+ require 'rdoc/task'
6
11
 
7
- desc 'Default: run unit tests.'
8
- task :default => :test
12
+ require 'rake/testtask'
9
13
 
10
- desc 'Test the rails-ckeditor plugin.'
11
14
  Rake::TestTask.new(:test) do |t|
12
15
  t.libs << 'lib'
13
16
  t.libs << 'test'
14
17
  t.pattern = 'test/**/*_test.rb'
15
- t.verbose = true
18
+ t.verbose = false
16
19
  end
17
20
 
18
- desc 'Generate documentation for the rails-ckeditor plugin.'
19
- Rake::RDocTask.new(:rdoc) do |rdoc|
21
+ task :default => :test
22
+
23
+ RDoc::Task.new do |rdoc|
20
24
  rdoc.rdoc_dir = 'rdoc'
21
- rdoc.title = 'Rails Ckeditor'
25
+ rdoc.title = 'Ckeditor'
22
26
  rdoc.options << '--line-numbers' << '--inline-source'
23
- rdoc.rdoc_files.include('README.textile')
27
+ rdoc.rdoc_files.include('README.rdoc')
24
28
  rdoc.rdoc_files.include('lib/**/*.rb')
25
29
  end
26
-
27
- begin
28
- require 'jeweler'
29
- Jeweler::Tasks.new do |gemspec|
30
- gemspec.name = "ckeditor"
31
- gemspec.version = Ckeditor::Version.dup
32
- gemspec.summary = "Rails plugin for integration ckeditor 3.x"
33
- gemspec.description = "CKEditor is a WYSIWYG editor to be used inside web pages"
34
- gemspec.email = "galeta.igor@gmail.com"
35
- gemspec.homepage = "http://github.com/galetahub/rails-ckeditor"
36
- gemspec.authors = ["Igor Galeta"]
37
- gemspec.files = FileList["[A-Z]*", "{app,config,lib}/**/*"]
38
- gemspec.rubyforge_project = "ckeditor"
39
-
40
- gemspec.add_dependency('mime-types', '>= 1.16')
41
- end
42
-
43
- Jeweler::GemcutterTasks.new
44
- rescue LoadError
45
- puts "Jeweler not available. Install it with: gem install jeweler"
46
- end
@@ -1,23 +1,23 @@
1
1
  class Ckeditor::AttachmentFilesController < Ckeditor::BaseController
2
2
 
3
3
  def index
4
- @attachments = Ckeditor.file_model.order("id DESC")
4
+ @attachments = Ckeditor.attachment_file_model.find_all(ckeditor_attachment_files_scope)
5
5
  respond_with(@attachments)
6
6
  end
7
7
 
8
8
  def create
9
- @attachment = Ckeditor.file_model.new
9
+ @attachment = Ckeditor::AttachmentFile.new
10
10
  respond_with_asset(@attachment)
11
11
  end
12
12
 
13
13
  def destroy
14
14
  @attachment.destroy
15
- respond_with(@attachment, :location => ckeditor_attachments_path)
15
+ respond_with(@attachment, :location => ckeditor_attachment_files_path)
16
16
  end
17
17
 
18
18
  protected
19
19
 
20
20
  def find_asset
21
- @attachment = Ckeditor.file_model.find(params[:id])
21
+ @attachment = Ckeditor.attachment_file_model.get!(params[:id])
22
22
  end
23
23
  end
@@ -1,55 +1,28 @@
1
1
  class Ckeditor::BaseController < ApplicationController
2
- skip_before_filter :verify_authenticity_token, :only => [:create]
3
-
4
- before_filter :swf_options, :only => [:index, :create]
5
- before_filter :find_asset, :only => [:destroy]
6
-
7
2
  respond_to :html, :json
8
-
9
3
  layout "ckeditor"
4
+
5
+ before_filter :set_locale
6
+ before_filter :find_asset, :only => [:destroy]
7
+ before_filter :ckeditor_authenticate
10
8
 
11
9
  protected
12
10
 
13
- def swf_options
14
- @swf_file_post_name = Ckeditor.swf_file_post_name
15
-
16
- if params[:controller] == 'ckeditor/pictures'
17
- @file_size_limit = Ckeditor.swf_image_file_size_limit
18
- @file_types = Ckeditor.swf_image_file_types
19
- @file_types_description = Ckeditor.swf_image_file_types_description
20
- @file_upload_limit = Ckeditor.swf_image_file_upload_limit
21
- else
22
- @file_size_limit = Ckeditor.swf_file_size_limit
23
- @file_types = Ckeditor.swf_file_types
24
- @file_types_description = Ckeditor.swf_file_types_description
25
- @file_upload_limit = Ckeditor.swf_file_upload_limit
26
- end
27
-
28
- @swf_file_post_name ||= 'data'
29
- @file_size_limit ||= "5 MB"
30
- @file_types ||= "*.jpg;*.jpeg;*.png;*.gif"
31
- @file_types_description ||= "Images"
32
- @file_upload_limit ||= 10
11
+ def set_locale
12
+ if !params[:langCode].blank? && I18n.available_locales.include?(params[:langCode].to_sym)
13
+ I18n.locale = params[:langCode]
14
+ end
33
15
  end
34
16
 
35
- def respond_with_asset(record)
36
- unless params[:CKEditor].blank?
37
- params[@swf_file_post_name] = params.delete(:upload)
38
- end
17
+ def respond_with_asset(asset)
18
+ file = params[:CKEditor].blank? ? params[:qqfile] : params[:upload]
19
+ asset.data = Ckeditor::Http.normalize_param(file, request)
39
20
 
40
- options = {}
21
+ callback = ckeditor_before_create_asset(asset)
41
22
 
42
- params.each do |k, v|
43
- key = k.to_s.downcase
44
- options[key] = v if record.respond_to?("#{key}=")
45
- end
46
-
47
- record.attributes = options
48
- record.user ||= current_user if respond_to?(:current_user)
49
-
50
- if record.valid? && record.save
51
- body = params[:CKEditor].blank? ? record.to_json(:only=>[:id, :type], :methods=>[:url, :content_type, :size, :filename, :format_created_at], :root => "asset") : %Q"<script type='text/javascript'>
52
- window.parent.CKEDITOR.tools.callFunction(#{params[:CKEditorFuncNum]}, '#{Ckeditor::Utils.escape_single_quotes(record.url_content)}');
23
+ if callback && asset.save
24
+ body = params[:CKEditor].blank? ? asset.to_json(:only=>[:id, :type]) : %Q"<script type='text/javascript'>
25
+ window.parent.CKEDITOR.tools.callFunction(#{params[:CKEditorFuncNum]}, '#{Ckeditor::Utils.escape_single_quotes(asset.url_content)}');
53
26
  </script>"
54
27
 
55
28
  render :text => body