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
@@ -0,0 +1,191 @@
1
+ (function() {
2
+ // Technique from Juriy Zaytsev
3
+ // http://thinkweb2.com/projects/prototype/detecting-event-support-without-browser-sniffing/
4
+ function isEventSupported(eventName) {
5
+ var el = document.createElement('div');
6
+ eventName = 'on' + eventName;
7
+ var isSupported = (eventName in el);
8
+ if (!isSupported) {
9
+ el.setAttribute(eventName, 'return;');
10
+ isSupported = typeof el[eventName] == 'function';
11
+ }
12
+ el = null;
13
+ return isSupported;
14
+ }
15
+
16
+ function isForm(element) {
17
+ return Object.isElement(element) && element.nodeName.toUpperCase() == 'FORM'
18
+ }
19
+
20
+ function isInput(element) {
21
+ if (Object.isElement(element)) {
22
+ var name = element.nodeName.toUpperCase()
23
+ return name == 'INPUT' || name == 'SELECT' || name == 'TEXTAREA'
24
+ }
25
+ else return false
26
+ }
27
+
28
+ var submitBubbles = isEventSupported('submit'),
29
+ changeBubbles = isEventSupported('change')
30
+
31
+ if (!submitBubbles || !changeBubbles) {
32
+ // augment the Event.Handler class to observe custom events when needed
33
+ Event.Handler.prototype.initialize = Event.Handler.prototype.initialize.wrap(
34
+ function(init, element, eventName, selector, callback) {
35
+ init(element, eventName, selector, callback)
36
+ // is the handler being attached to an element that doesn't support this event?
37
+ if ( (!submitBubbles && this.eventName == 'submit' && !isForm(this.element)) ||
38
+ (!changeBubbles && this.eventName == 'change' && !isInput(this.element)) ) {
39
+ // "submit" => "emulated:submit"
40
+ this.eventName = 'emulated:' + this.eventName
41
+ }
42
+ }
43
+ )
44
+ }
45
+
46
+ if (!submitBubbles) {
47
+ // discover forms on the page by observing focus events which always bubble
48
+ document.on('focusin', 'form', function(focusEvent, form) {
49
+ // special handler for the real "submit" event (one-time operation)
50
+ if (!form.retrieve('emulated:submit')) {
51
+ form.on('submit', function(submitEvent) {
52
+ var emulated = form.fire('emulated:submit', submitEvent, true)
53
+ // if custom event received preventDefault, cancel the real one too
54
+ if (emulated.returnValue === false) submitEvent.preventDefault()
55
+ })
56
+ form.store('emulated:submit', true)
57
+ }
58
+ })
59
+ }
60
+
61
+ if (!changeBubbles) {
62
+ // discover form inputs on the page
63
+ document.on('focusin', 'input, select, texarea', function(focusEvent, input) {
64
+ // special handler for real "change" events
65
+ if (!input.retrieve('emulated:change')) {
66
+ input.on('change', function(changeEvent) {
67
+ input.fire('emulated:change', changeEvent, true)
68
+ })
69
+ input.store('emulated:change', true)
70
+ }
71
+ })
72
+ }
73
+
74
+ function handleRemote(element) {
75
+ var method, url, params;
76
+
77
+ var event = element.fire("ajax:before");
78
+ if (event.stopped) return false;
79
+
80
+ if (element.tagName.toLowerCase() === 'form') {
81
+ method = element.readAttribute('method') || 'post';
82
+ url = element.readAttribute('action');
83
+ params = element.serialize();
84
+ } else {
85
+ method = element.readAttribute('data-method') || 'get';
86
+ url = element.readAttribute('href');
87
+ params = {};
88
+ }
89
+
90
+ new Ajax.Request(url, {
91
+ method: method,
92
+ parameters: params,
93
+ evalScripts: true,
94
+
95
+ onComplete: function(request) { element.fire("ajax:complete", request); },
96
+ onSuccess: function(request) { element.fire("ajax:success", request); },
97
+ onFailure: function(request) { element.fire("ajax:failure", request); }
98
+ });
99
+
100
+ element.fire("ajax:after");
101
+ }
102
+
103
+ function handleMethod(element) {
104
+ var method = element.readAttribute('data-method'),
105
+ url = element.readAttribute('href'),
106
+ csrf_param = $$('meta[name=csrf-param]')[0],
107
+ csrf_token = $$('meta[name=csrf-token]')[0];
108
+
109
+ var form = new Element('form', { method: "POST", action: url, style: "display: none;" });
110
+ element.parentNode.insert(form);
111
+
112
+ if (method !== 'post') {
113
+ var field = new Element('input', { type: 'hidden', name: '_method', value: method });
114
+ form.insert(field);
115
+ }
116
+
117
+ if (csrf_param) {
118
+ var param = csrf_param.readAttribute('content'),
119
+ token = csrf_token.readAttribute('content'),
120
+ field = new Element('input', { type: 'hidden', name: param, value: token });
121
+ form.insert(field);
122
+ }
123
+
124
+ form.submit();
125
+ }
126
+
127
+
128
+ document.on("click", "*[data-confirm]", function(event, element) {
129
+ var message = element.readAttribute('data-confirm');
130
+ if (!confirm(message)) event.stop();
131
+ });
132
+
133
+ document.on("click", "a[data-remote]", function(event, element) {
134
+ if (event.stopped) return;
135
+ handleRemote(element);
136
+ event.stop();
137
+ });
138
+
139
+ document.on("click", "a[data-method]", function(event, element) {
140
+ if (event.stopped) return;
141
+ handleMethod(element);
142
+ event.stop();
143
+ });
144
+
145
+ document.on("submit", function(event) {
146
+ var element = event.findElement(),
147
+ message = element.readAttribute('data-confirm');
148
+ if (message && !confirm(message)) {
149
+ event.stop();
150
+ return false;
151
+ }
152
+
153
+ var inputs = element.select("input[type=submit][data-disable-with]");
154
+ inputs.each(function(input) {
155
+ input.disabled = true;
156
+ input.writeAttribute('data-original-value', input.value);
157
+ input.value = input.readAttribute('data-disable-with');
158
+ });
159
+
160
+ var element = event.findElement("form[data-remote]");
161
+ if (element) {
162
+ handleRemote(element);
163
+ event.stop();
164
+ }
165
+ });
166
+
167
+ document.on("ajax:after", "form", function(event, element) {
168
+ var inputs = element.select("input[type=submit][disabled=true][data-disable-with]");
169
+ inputs.each(function(input) {
170
+ input.value = input.readAttribute('data-original-value');
171
+ input.removeAttribute('data-original-value');
172
+ input.disabled = false;
173
+ });
174
+ });
175
+
176
+ Ajax.Responders.register({
177
+ onCreate: function(request) {
178
+ var csrf_meta_tag = $$('meta[name=csrf-token]')[0];
179
+
180
+ if (csrf_meta_tag) {
181
+ var header = 'X-CSRF-Token',
182
+ token = csrf_meta_tag.readAttribute('content');
183
+
184
+ if (!request.options.requestHeaders) {
185
+ request.options.requestHeaders = {};
186
+ }
187
+ request.options.requestHeaders[header] = token;
188
+ }
189
+ }
190
+ });
191
+ })();
@@ -0,0 +1,56 @@
1
+ body { background-color: #fff; color: #333; }
2
+
3
+ body, p, ol, ul, td {
4
+ font-family: verdana, arial, helvetica, sans-serif;
5
+ font-size: 13px;
6
+ line-height: 18px;
7
+ }
8
+
9
+ pre {
10
+ background-color: #eee;
11
+ padding: 10px;
12
+ font-size: 11px;
13
+ }
14
+
15
+ a { color: #000; }
16
+ a:visited { color: #666; }
17
+ a:hover { color: #fff; background-color:#000; }
18
+
19
+ div.field, div.actions {
20
+ margin-bottom: 10px;
21
+ }
22
+
23
+ #notice {
24
+ color: green;
25
+ }
26
+
27
+ .field_with_errors {
28
+ padding: 2px;
29
+ background-color: red;
30
+ display: table;
31
+ }
32
+
33
+ #error_explanation {
34
+ width: 450px;
35
+ border: 2px solid red;
36
+ padding: 7px;
37
+ padding-bottom: 0;
38
+ margin-bottom: 20px;
39
+ background-color: #f0f0f0;
40
+ }
41
+
42
+ #error_explanation h2 {
43
+ text-align: left;
44
+ font-weight: bold;
45
+ padding: 5px 5px 5px 15px;
46
+ font-size: 12px;
47
+ margin: -7px;
48
+ margin-bottom: 0px;
49
+ background-color: #c00;
50
+ color: #fff;
51
+ }
52
+
53
+ #error_explanation ul li {
54
+ font-size: 12px;
55
+ list-style: square;
56
+ }
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
@@ -0,0 +1,18 @@
1
+ require "test_helper"
2
+
3
+ class InstallGeneratorTest < Rails::Generators::TestCase
4
+ tests Ckeditor::Generators::InstallGenerator
5
+ destination File.expand_path("../../tmp", __FILE__)
6
+ setup :prepare_destination
7
+
8
+ test "Assert all files are properly created" do
9
+ run_generator
10
+
11
+ assert_file "config/initializers/ckeditor.rb"
12
+ assert_file "tmp/ckeditor_#{Ckeditor::Version::EDITOR}.tar.gz"
13
+
14
+ ["rails.js", "jquery.js", "fileuploader.js", "jquery.tmpl.js"].each do |file|
15
+ assert_file "public/javascripts/ckeditor/filebrowser/javascripts/#{file}"
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,21 @@
1
+ require "test_helper"
2
+
3
+ class ModelsGeneratorTest < Rails::Generators::TestCase
4
+ tests Ckeditor::Generators::ModelsGenerator
5
+ destination File.expand_path("../../tmp", __FILE__)
6
+ setup :prepare_destination
7
+
8
+ test "models and migration for active_record orm" do
9
+ run_generator %w(--orm=active_record)
10
+
11
+ assert_file "app/models/ckeditor/asset.rb"
12
+ assert_file "app/models/ckeditor/picture.rb"
13
+ assert_file "app/models/ckeditor/attachment_file.rb"
14
+
15
+ assert_migration "db/migrate/create_ckeditor_assets.rb" do |migration|
16
+ assert_class_method :up, migration do |up|
17
+ assert_match /create_table/, up
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class NavigationTest < ActiveSupport::IntegrationCase
4
+ test "truth" do
5
+ assert_kind_of Dummy::Application, Rails.application
6
+ end
7
+ end
@@ -0,0 +1,41 @@
1
+ require 'test_helper'
2
+
3
+ class PostsTest < ActiveSupport::IntegrationCase
4
+ def setup
5
+ @post = Post.create!(:title => "test", :content => "content", :info => "info")
6
+ end
7
+
8
+ def teardown
9
+ @post.destroy
10
+ end
11
+
12
+ test "include javascripts" do
13
+ visit(posts_path)
14
+
15
+ assert page.body.include?('/javascripts/ckeditor/ckeditor.js')
16
+ assert page.body.include?("CKEDITOR.replace('test_area', { language: 'en' });")
17
+ end
18
+
19
+ test "pass text_area with options" do
20
+ visit(posts_path)
21
+
22
+ assert page.body.include?('<textarea cols="10" id="content" name="content" rows="20">Ckeditor</textarea>')
23
+ assert page.body.include?("CKEDITOR.replace('content', { language: 'en',toolbar: 'Easy' });")
24
+ end
25
+
26
+ test "form builder helper" do
27
+ visit(new_post_path)
28
+
29
+ assert page.body.include?('<textarea cols="40" id="post_content" name="post[content]" rows="20"></textarea>')
30
+ assert page.body.include?("CKEDITOR.replace('post_content', { height: 400,language: 'en',width: 800 });")
31
+ assert page.body.include?('<textarea cols="40" id="post_info" name="post[info]" rows="20">Defaults info content</textarea>')
32
+ assert page.body.include?("CKEDITOR.replace('post_info', { language: 'en' });")
33
+ end
34
+
35
+ test "text_area value" do
36
+ visit(edit_post_path(@post))
37
+
38
+ assert page.body.include?('<textarea cols="40" id="post_content" name="post[content]" rows="20">content</textarea>')
39
+ assert page.body.include?('<textarea cols="50" id="post_info" name="post[info]" rows="70">info</textarea>')
40
+ end
41
+ end
@@ -0,0 +1,47 @@
1
+ require 'test_helper'
2
+
3
+ class CkeditorRoutingTest < ActionController::TestCase
4
+ test "should route to pictures" do
5
+ assert_generates "/ckeditor/pictures", { :controller => "ckeditor/pictures", :action => "index"}
6
+ assert_generates "/ckeditor/pictures/1", { :controller => "ckeditor/pictures", :action => "destroy", :id => 1}
7
+ end
8
+
9
+ test "should route to attachment_files" do
10
+ assert_generates "/ckeditor/attachment_files", { :controller => "ckeditor/attachment_files", :action => "index"}
11
+ assert_generates "/ckeditor/attachment_files/1", { :controller => "ckeditor/attachment_files", :action => "destroy", :id => 1}
12
+ end
13
+
14
+ test 'map index pictures' do
15
+ assert_named_route "/ckeditor/pictures", :ckeditor_pictures_path
16
+ assert_recognizes({:controller=>"ckeditor/pictures", :action=>"index"}, {:path => '/ckeditor/pictures', :method => :get})
17
+ end
18
+
19
+ test 'map create picture' do
20
+ assert_recognizes({:controller => 'ckeditor/pictures', :action => 'create'}, {:path => '/ckeditor/pictures', :method => :post})
21
+ end
22
+
23
+ test 'map destroy picture' do
24
+ assert_named_route "/ckeditor/pictures/1", :ckeditor_picture_path, 1
25
+ assert_recognizes({:controller => 'ckeditor/pictures', :action => 'destroy', :id => "1"}, {:path => '/ckeditor/pictures/1', :method => :delete})
26
+ end
27
+
28
+ test 'map index attachment_files' do
29
+ assert_named_route "/ckeditor/attachment_files", :ckeditor_attachment_files_path
30
+ assert_recognizes({:controller => 'ckeditor/attachment_files', :action => 'index'}, {:path => '/ckeditor/attachment_files', :method => :get})
31
+ end
32
+
33
+ test 'map create attachment_file' do
34
+ assert_recognizes({:controller => 'ckeditor/attachment_files', :action => 'create'}, {:path => '/ckeditor/attachment_files', :method => :post})
35
+ end
36
+
37
+ test 'map destroy attachment_file' do
38
+ assert_named_route "/ckeditor/attachment_files/1", :ckeditor_attachment_file_path, 1
39
+ assert_recognizes({:controller => 'ckeditor/attachment_files', :action => 'destroy', :id => "1"}, {:path => '/ckeditor/attachment_files/1', :method => :delete})
40
+ end
41
+
42
+ protected
43
+
44
+ def assert_named_route(result, *args)
45
+ assert_equal result, @routes.url_helpers.send(*args)
46
+ end
47
+ end
@@ -0,0 +1,5 @@
1
+ # Define a bare test case to use with Capybara
2
+ class ActiveSupport::IntegrationCase < ActiveSupport::TestCase
3
+ include Capybara::DSL
4
+ include Rails.application.routes.url_helpers
5
+ end
@@ -0,0 +1,28 @@
1
+ # Configure Rails Envinronment
2
+ ENV["RAILS_ENV"] = "test"
3
+
4
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
5
+ require "rails/test_help"
6
+ require 'redgreen'
7
+
8
+ ActionMailer::Base.delivery_method = :test
9
+ ActionMailer::Base.perform_deliveries = true
10
+ ActionMailer::Base.default_url_options[:host] = "test.com"
11
+
12
+ Rails.backtrace_cleaner.remove_silencers!
13
+
14
+ # Configure capybara for integration testing
15
+ require "capybara/rails"
16
+ Capybara.default_driver = :rack_test
17
+ Capybara.default_selector = :css
18
+
19
+ # Run any available migration
20
+ ActiveRecord::Migrator.migrate File.expand_path("../dummy/db/migrate/", __FILE__)
21
+
22
+ # Load support files
23
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
24
+
25
+ # For generators
26
+ require "rails/generators/test_case"
27
+ require "generators/ckeditor/install_generator"
28
+ require "generators/ckeditor/models_generator"
@@ -0,0 +1,7 @@
1
+ require 'mime/types'
2
+
3
+ class Ckeditor::Asset < ActiveRecord::Base
4
+ include Ckeditor::Orm::ActiveRecord::AssetBase
5
+
6
+ attr_accessible :data, :assetable_type, :assetable_id, :assetable
7
+ end
@@ -0,0 +1,15 @@
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
+ validates_attachment_presence :data
8
+
9
+ def url_thumb
10
+ @url_thumb ||= begin
11
+ extname = File.extname(filename).gsub(/^\./, '')
12
+ "/javascripts/ckeditor/filebrowser/images/thumbs/#{extname}.gif"
13
+ end
14
+ end
15
+ end