rails_kindeditor-plus 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (239) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +5 -0
  3. data/Gemfile +6 -0
  4. data/README.md +523 -0
  5. data/Rakefile +2 -0
  6. data/app/assets/javascripts/kindeditor.js +1 -0
  7. data/app/controllers/kindeditor/assets_controller.rb +126 -0
  8. data/app/uploaders/kindeditor/asset_uploader.rb +91 -0
  9. data/app/uploaders/kindeditor/file_uploader.rb +10 -0
  10. data/app/uploaders/kindeditor/flash_uploader.rb +10 -0
  11. data/app/uploaders/kindeditor/image_uploader.rb +10 -0
  12. data/app/uploaders/kindeditor/media_uploader.rb +10 -0
  13. data/config/routes.rb +6 -0
  14. data/lib/generators/rails_kindeditor/install/USAGE +10 -0
  15. data/lib/generators/rails_kindeditor/install/install_generator.rb +23 -0
  16. data/lib/generators/rails_kindeditor/install/templates/application.js +17 -0
  17. data/lib/generators/rails_kindeditor/install/templates/rails_kindeditor.rb +29 -0
  18. data/lib/generators/rails_kindeditor/migration/USAGE +14 -0
  19. data/lib/generators/rails_kindeditor/migration/migration_generator.rb +36 -0
  20. data/lib/generators/rails_kindeditor/migration/templates/migration/migration.rb +17 -0
  21. data/lib/generators/rails_kindeditor/migration/templates/models/active_record/kindeditor/asset.rb +14 -0
  22. data/lib/generators/rails_kindeditor/migration/templates/models/active_record/kindeditor/file.rb +3 -0
  23. data/lib/generators/rails_kindeditor/migration/templates/models/active_record/kindeditor/flash.rb +3 -0
  24. data/lib/generators/rails_kindeditor/migration/templates/models/active_record/kindeditor/image.rb +3 -0
  25. data/lib/generators/rails_kindeditor/migration/templates/models/active_record/kindeditor/media.rb +3 -0
  26. data/lib/generators/rails_kindeditor/migration/templates/models/mongoid/kindeditor/asset.rb +27 -0
  27. data/lib/generators/rails_kindeditor/migration/templates/models/mongoid/kindeditor/file.rb +3 -0
  28. data/lib/generators/rails_kindeditor/migration/templates/models/mongoid/kindeditor/flash.rb +3 -0
  29. data/lib/generators/rails_kindeditor/migration/templates/models/mongoid/kindeditor/image.rb +3 -0
  30. data/lib/generators/rails_kindeditor/migration/templates/models/mongoid/kindeditor/media.rb +3 -0
  31. data/lib/rails_kindeditor.rb +61 -0
  32. data/lib/rails_kindeditor/active_record.rb +14 -0
  33. data/lib/rails_kindeditor/engine.rb +34 -0
  34. data/lib/rails_kindeditor/formtastic.rb +12 -0
  35. data/lib/rails_kindeditor/helper.rb +96 -0
  36. data/lib/rails_kindeditor/simple_form.rb +11 -0
  37. data/lib/rails_kindeditor/version.rb +4 -0
  38. data/lib/tasks/assets.rake +9 -0
  39. data/rails_kindeditor-plus.gemspec +24 -0
  40. data/screenshots/rails_kindeditor.png +0 -0
  41. data/screenshots/simple_mode.png +0 -0
  42. data/vendor/assets/javascripts/kindeditor/kindeditor.js +5963 -0
  43. data/vendor/assets/javascripts/kindeditor/lang/ar.js +233 -0
  44. data/vendor/assets/javascripts/kindeditor/lang/en.js +232 -0
  45. data/vendor/assets/javascripts/kindeditor/lang/ko.js +237 -0
  46. data/vendor/assets/javascripts/kindeditor/lang/zh_CN.js +237 -0
  47. data/vendor/assets/javascripts/kindeditor/lang/zh_TW.js +235 -0
  48. data/vendor/assets/javascripts/kindeditor/plugins/anchor/anchor.js +46 -0
  49. data/vendor/assets/javascripts/kindeditor/plugins/autoheight/autoheight.js +54 -0
  50. data/vendor/assets/javascripts/kindeditor/plugins/baidumap/baidumap.js +93 -0
  51. data/vendor/assets/javascripts/kindeditor/plugins/baidumap/index.html +83 -0
  52. data/vendor/assets/javascripts/kindeditor/plugins/baidumap/map.html +43 -0
  53. data/vendor/assets/javascripts/kindeditor/plugins/clearhtml/clearhtml.js +29 -0
  54. data/vendor/assets/javascripts/kindeditor/plugins/code/code.js +62 -0
  55. data/vendor/assets/javascripts/kindeditor/plugins/code/prettify.css +13 -0
  56. data/vendor/assets/javascripts/kindeditor/plugins/code/prettify.js +28 -0
  57. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/emoticons.js +129 -0
  58. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/0.gif +0 -0
  59. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/1.gif +0 -0
  60. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/10.gif +0 -0
  61. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/100.gif +0 -0
  62. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/101.gif +0 -0
  63. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/102.gif +0 -0
  64. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/103.gif +0 -0
  65. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/104.gif +0 -0
  66. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/105.gif +0 -0
  67. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/106.gif +0 -0
  68. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/107.gif +0 -0
  69. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/108.gif +0 -0
  70. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/109.gif +0 -0
  71. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/11.gif +0 -0
  72. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/110.gif +0 -0
  73. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/111.gif +0 -0
  74. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/112.gif +0 -0
  75. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/113.gif +0 -0
  76. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/114.gif +0 -0
  77. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/115.gif +0 -0
  78. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/116.gif +0 -0
  79. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/117.gif +0 -0
  80. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/118.gif +0 -0
  81. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/119.gif +0 -0
  82. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/12.gif +0 -0
  83. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/120.gif +0 -0
  84. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/121.gif +0 -0
  85. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/122.gif +0 -0
  86. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/123.gif +0 -0
  87. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/124.gif +0 -0
  88. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/125.gif +0 -0
  89. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/126.gif +0 -0
  90. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/127.gif +0 -0
  91. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/128.gif +0 -0
  92. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/129.gif +0 -0
  93. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/13.gif +0 -0
  94. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/130.gif +0 -0
  95. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/131.gif +0 -0
  96. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/132.gif +0 -0
  97. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/133.gif +0 -0
  98. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/134.gif +0 -0
  99. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/14.gif +0 -0
  100. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/15.gif +0 -0
  101. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/16.gif +0 -0
  102. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/17.gif +0 -0
  103. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/18.gif +0 -0
  104. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/19.gif +0 -0
  105. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/2.gif +0 -0
  106. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/20.gif +0 -0
  107. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/21.gif +0 -0
  108. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/22.gif +0 -0
  109. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/23.gif +0 -0
  110. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/24.gif +0 -0
  111. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/25.gif +0 -0
  112. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/26.gif +0 -0
  113. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/27.gif +0 -0
  114. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/28.gif +0 -0
  115. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/29.gif +0 -0
  116. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/3.gif +0 -0
  117. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/30.gif +0 -0
  118. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/31.gif +0 -0
  119. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/32.gif +0 -0
  120. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/33.gif +0 -0
  121. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/34.gif +0 -0
  122. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/35.gif +0 -0
  123. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/36.gif +0 -0
  124. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/37.gif +0 -0
  125. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/38.gif +0 -0
  126. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/39.gif +0 -0
  127. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/4.gif +0 -0
  128. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/40.gif +0 -0
  129. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/41.gif +0 -0
  130. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/42.gif +0 -0
  131. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/43.gif +0 -0
  132. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/44.gif +0 -0
  133. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/45.gif +0 -0
  134. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/46.gif +0 -0
  135. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/47.gif +0 -0
  136. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/48.gif +0 -0
  137. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/49.gif +0 -0
  138. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/5.gif +0 -0
  139. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/50.gif +0 -0
  140. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/51.gif +0 -0
  141. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/52.gif +0 -0
  142. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/53.gif +0 -0
  143. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/54.gif +0 -0
  144. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/55.gif +0 -0
  145. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/56.gif +0 -0
  146. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/57.gif +0 -0
  147. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/58.gif +0 -0
  148. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/59.gif +0 -0
  149. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/6.gif +0 -0
  150. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/60.gif +0 -0
  151. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/61.gif +0 -0
  152. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/62.gif +0 -0
  153. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/63.gif +0 -0
  154. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/64.gif +0 -0
  155. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/65.gif +0 -0
  156. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/66.gif +0 -0
  157. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/67.gif +0 -0
  158. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/68.gif +0 -0
  159. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/69.gif +0 -0
  160. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/7.gif +0 -0
  161. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/70.gif +0 -0
  162. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/71.gif +0 -0
  163. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/72.gif +0 -0
  164. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/73.gif +0 -0
  165. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/74.gif +0 -0
  166. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/75.gif +0 -0
  167. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/76.gif +0 -0
  168. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/77.gif +0 -0
  169. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/78.gif +0 -0
  170. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/79.gif +0 -0
  171. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/8.gif +0 -0
  172. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/80.gif +0 -0
  173. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/81.gif +0 -0
  174. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/82.gif +0 -0
  175. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/83.gif +0 -0
  176. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/84.gif +0 -0
  177. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/85.gif +0 -0
  178. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/86.gif +0 -0
  179. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/87.gif +0 -0
  180. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/88.gif +0 -0
  181. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/89.gif +0 -0
  182. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/9.gif +0 -0
  183. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/90.gif +0 -0
  184. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/91.gif +0 -0
  185. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/92.gif +0 -0
  186. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/93.gif +0 -0
  187. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/94.gif +0 -0
  188. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/95.gif +0 -0
  189. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/96.gif +0 -0
  190. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/97.gif +0 -0
  191. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/98.gif +0 -0
  192. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/99.gif +0 -0
  193. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/static.gif +0 -0
  194. data/vendor/assets/javascripts/kindeditor/plugins/filemanager/filemanager.js +189 -0
  195. data/vendor/assets/javascripts/kindeditor/plugins/filemanager/images/file-16.gif +0 -0
  196. data/vendor/assets/javascripts/kindeditor/plugins/filemanager/images/file-64.gif +0 -0
  197. data/vendor/assets/javascripts/kindeditor/plugins/filemanager/images/folder-16.gif +0 -0
  198. data/vendor/assets/javascripts/kindeditor/plugins/filemanager/images/folder-64.gif +0 -0
  199. data/vendor/assets/javascripts/kindeditor/plugins/filemanager/images/go-up.gif +0 -0
  200. data/vendor/assets/javascripts/kindeditor/plugins/flash/flash.js +161 -0
  201. data/vendor/assets/javascripts/kindeditor/plugins/image/image.js +328 -0
  202. data/vendor/assets/javascripts/kindeditor/plugins/image/images/align_left.gif +0 -0
  203. data/vendor/assets/javascripts/kindeditor/plugins/image/images/align_right.gif +0 -0
  204. data/vendor/assets/javascripts/kindeditor/plugins/image/images/align_top.gif +0 -0
  205. data/vendor/assets/javascripts/kindeditor/plugins/image/images/refresh.png +0 -0
  206. data/vendor/assets/javascripts/kindeditor/plugins/insertfile/insertfile.js +144 -0
  207. data/vendor/assets/javascripts/kindeditor/plugins/lineheight/lineheight.js +38 -0
  208. data/vendor/assets/javascripts/kindeditor/plugins/link/link.js +66 -0
  209. data/vendor/assets/javascripts/kindeditor/plugins/map/map.html +57 -0
  210. data/vendor/assets/javascripts/kindeditor/plugins/map/map.js +137 -0
  211. data/vendor/assets/javascripts/kindeditor/plugins/media/media.js +170 -0
  212. data/vendor/assets/javascripts/kindeditor/plugins/multiimage/images/image.png +0 -0
  213. data/vendor/assets/javascripts/kindeditor/plugins/multiimage/images/select-files-en.png +0 -0
  214. data/vendor/assets/javascripts/kindeditor/plugins/multiimage/images/select-files-zh_CN.png +0 -0
  215. data/vendor/assets/javascripts/kindeditor/plugins/multiimage/images/swfupload.swf +0 -0
  216. data/vendor/assets/javascripts/kindeditor/plugins/multiimage/multiimage.js +1384 -0
  217. data/vendor/assets/javascripts/kindeditor/plugins/pagebreak/pagebreak.js +27 -0
  218. data/vendor/assets/javascripts/kindeditor/plugins/plainpaste/plainpaste.js +41 -0
  219. data/vendor/assets/javascripts/kindeditor/plugins/preview/preview.js +33 -0
  220. data/vendor/assets/javascripts/kindeditor/plugins/quickformat/quickformat.js +81 -0
  221. data/vendor/assets/javascripts/kindeditor/plugins/table/table.js +712 -0
  222. data/vendor/assets/javascripts/kindeditor/plugins/template/html/1.html +14 -0
  223. data/vendor/assets/javascripts/kindeditor/plugins/template/html/2.html +42 -0
  224. data/vendor/assets/javascripts/kindeditor/plugins/template/html/3.html +36 -0
  225. data/vendor/assets/javascripts/kindeditor/plugins/template/template.js +58 -0
  226. data/vendor/assets/javascripts/kindeditor/plugins/wordpaste/wordpaste.js +51 -0
  227. data/vendor/assets/javascripts/kindeditor/themes/common/anchor.gif +0 -0
  228. data/vendor/assets/javascripts/kindeditor/themes/common/blank.gif +0 -0
  229. data/vendor/assets/javascripts/kindeditor/themes/common/flash.gif +0 -0
  230. data/vendor/assets/javascripts/kindeditor/themes/common/loading.gif +0 -0
  231. data/vendor/assets/javascripts/kindeditor/themes/common/media.gif +0 -0
  232. data/vendor/assets/javascripts/kindeditor/themes/common/rm.gif +0 -0
  233. data/vendor/assets/javascripts/kindeditor/themes/default/background.png +0 -0
  234. data/vendor/assets/javascripts/kindeditor/themes/default/default.css +1149 -0
  235. data/vendor/assets/javascripts/kindeditor/themes/default/default.png +0 -0
  236. data/vendor/assets/javascripts/kindeditor/themes/qq/editor.gif +0 -0
  237. data/vendor/assets/javascripts/kindeditor/themes/qq/qq.css +143 -0
  238. data/vendor/assets/javascripts/kindeditor/themes/simple/simple.css +100 -0
  239. metadata +309 -0
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1 @@
1
+ //= require kindeditor/kindeditor.js
@@ -0,0 +1,126 @@
1
+ #coding: utf-8
2
+ require "find"
3
+ class Kindeditor::AssetsController < ApplicationController
4
+ skip_before_filter :verify_authenticity_token
5
+ def create
6
+ @imgFile, @dir = params[:imgFile], params[:dir]
7
+ unless @imgFile.nil?
8
+ if Kindeditor::AssetUploader.save_upload_info? # save upload info into database
9
+ begin
10
+ @asset = "Kindeditor::#{@dir.camelize}".constantize.new(:asset => @imgFile)
11
+ @asset.owner_id = params[:owner_id] ? params[:owner_id] : 0
12
+ logger.warn '========= Warning: the owner_id is 0, "delete uploaded files automatically" will not work. =========' if defined?(logger) && @asset.owner_id == 0
13
+ @asset.asset_type = @dir
14
+ if @asset.save
15
+ render :text => ({:error => 0, :url => @asset.asset.url}.to_json)
16
+ else
17
+ show_error(@asset.errors.full_messages)
18
+ end
19
+ rescue Exception => e
20
+ show_error(e.to_s)
21
+ end
22
+ else # do not touch database
23
+ begin
24
+ uploader = "Kindeditor::#{@dir.camelize}Uploader".constantize.new
25
+ uploader.store!(@imgFile)
26
+ render :text => ({:error => 0, :url => uploader.url}.to_json)
27
+ rescue CarrierWave::UploadError => e
28
+ show_error(e.message)
29
+ rescue Exception => e
30
+ show_error(e.to_s)
31
+ end
32
+ end
33
+ else
34
+ show_error("No File Selected!")
35
+ end
36
+ end
37
+
38
+ def list
39
+ @root_path = "#{Rails.public_path}/#{RailsKindeditor.upload_store_dir}/"
40
+ @root_url = "/#{RailsKindeditor.upload_store_dir}/"
41
+ @img_ext = Kindeditor::AssetUploader::EXT_NAMES[:image]
42
+ @dir = params[:dir].strip || ""
43
+ unless Kindeditor::AssetUploader::EXT_NAMES.keys.map(&:to_s).push("").include?(@dir)
44
+ render :text => "Invalid Directory name."
45
+ return
46
+ end
47
+
48
+ Dir.chdir(Rails.public_path)
49
+ RailsKindeditor.upload_store_dir.split('/').each do |dir|
50
+ Dir.mkdir(dir) unless Dir.exist?(dir)
51
+ Dir.chdir(dir)
52
+ end
53
+
54
+ Dir.mkdir(@dir) unless Dir.exist?(@dir)
55
+
56
+ @root_path += @dir + "/"
57
+ @root_url += @dir + "/"
58
+
59
+ @path = params[:path].strip || ""
60
+ if @path.empty?
61
+ @current_path = @root_path
62
+ @current_url = @root_url
63
+ @current_dir_path = ""
64
+ @moveup_dir_path = ""
65
+ else
66
+ @current_path = @root_path + @path + "/"
67
+ @current_url = @root_url + @path + "/"
68
+ @current_dir_path = @path
69
+ @moveup_dir_path = @current_dir_path.gsub(/(.*?)[^\/]+\/$/, "")
70
+ end
71
+ @order = %w(name size type).include?(params[:order].downcase) ? params[:order].downcase : "name"
72
+ if !@current_path.match(/\.\./).nil?
73
+ render :text => "Access is not allowed."
74
+ return
75
+ end
76
+ if @current_path.match(/\/$/).nil?
77
+ render :text => "Parameter is not valid."
78
+ return
79
+ end
80
+ if !File.exist?(@current_path) || !File.directory?(@current_path)
81
+ render :text => "Directory does not exist."
82
+ return
83
+ end
84
+ @file_list = []
85
+ Dir.foreach(@current_path) do |filename|
86
+ hash = {}
87
+ if filename != "." and filename != ".." and filename != ".DS_Store"
88
+ file = @current_path + filename
89
+ if File.directory?(file)
90
+ hash[:is_dir] = true
91
+ hash[:has_file] = (Dir.foreach(file).count > 2)
92
+ hash[:filesize] = 0
93
+ hash[:is_photo] = false
94
+ hash[:filetype] = ""
95
+ else
96
+ hash[:is_dir] = false
97
+ hash[:has_file] = false
98
+ hash[:filesize] = File.size(file)
99
+ hash[:dir_path] = ""
100
+ file_ext = file.gsub(/.*\./,"")
101
+ hash[:is_photo] = @img_ext.include?(file_ext)
102
+ hash[:filetype] = file_ext
103
+ end
104
+ hash[:filename] = filename
105
+ hash[:datetime] = File.mtime(file).to_s(:db)
106
+ @file_list << hash
107
+ end
108
+ end
109
+
110
+ @file_list.sort! {|a, b| a["file#{@order}".to_sym] <=> b["file#{@order}".to_sym]}
111
+
112
+ @result = {}
113
+ @result[:moveup_dir_path] = @moveup_dir_path
114
+ @result[:current_dir_path] = @current_dir_path
115
+ @result[:current_url] = @current_url
116
+ @result[:total_count] = @file_list.count
117
+ @result[:file_list] = @file_list
118
+ render :text => @result.to_json
119
+ end
120
+
121
+ private
122
+ def show_error(msg)
123
+ render :text => ({:error => 1, :message => msg}.to_json)
124
+ end
125
+
126
+ end
@@ -0,0 +1,91 @@
1
+ # encoding: utf-8
2
+
3
+ require 'carrierwave/processing/mime_types'
4
+
5
+ class Kindeditor::AssetUploader < CarrierWave::Uploader::Base
6
+
7
+ EXT_NAMES = {:image => RailsKindeditor.upload_image_ext,
8
+ :flash => RailsKindeditor.upload_flash_ext,
9
+ :media => RailsKindeditor.upload_media_ext,
10
+ :file => RailsKindeditor.upload_file_ext}
11
+
12
+ # Include RMagick or ImageScience support:
13
+ # include CarrierWave::RMagick
14
+ # include CarrierWave::ImageScience
15
+ # include CarrierWave::MiniMagick
16
+
17
+ # Choose what kind of storage to use for this uploader:
18
+ storage :file
19
+ # storage :fog
20
+
21
+ # Override the directory where uploaded files will be stored.
22
+ # This is a sensible default for uploaders that are meant to be mounted:
23
+ def store_dir
24
+ if Kindeditor::AssetUploader.save_upload_info?
25
+ "#{RailsKindeditor.upload_store_dir}/#{model.asset_type.to_s.underscore.gsub(/(kindeditor\/)|(_uploader)/, '')}/#{model.created_at.strftime("%Y%m")}"
26
+ else
27
+ "#{RailsKindeditor.upload_store_dir}/#{self.class.to_s.underscore.gsub(/(kindeditor\/)|(_uploader)/, '')}/#{Time.now.strftime("%Y%m")}"
28
+ end
29
+ end
30
+
31
+ def cache_dir
32
+ "#{Rails.root}/tmp/uploads"
33
+ end
34
+
35
+ # Provide a default URL as a default if there hasn't been a file uploaded:
36
+ # def default_url
37
+ # "/images/fallback/" + [version_name, "default.png"].compact.join('_')
38
+ # end
39
+
40
+ # Process files as they are uploaded:
41
+ # process :scale => [200, 300]
42
+ #
43
+ # def scale(width, height)
44
+ # # do something
45
+ # end
46
+
47
+ # Create different versions of your uploaded files:
48
+ # version :thumb do
49
+ # process :scale => [50, 50]
50
+ # end
51
+
52
+ # Add a white list of extensions which are allowed to be uploaded.
53
+ # For images you might use something like this:
54
+
55
+ # Override the filename of the uploaded files:
56
+ # Avoid using model.id or version_name here, see uploader/store.rb for details.
57
+ before :store, :remember_cache_id
58
+ after :store, :delete_tmp_dir
59
+
60
+ # store! nil's the cache_id after it finishes so we need to remember it for deletition
61
+ def remember_cache_id(new_file)
62
+ @cache_id_was = cache_id
63
+ end
64
+
65
+ def delete_tmp_dir(new_file)
66
+ # make sure we don't delete other things accidentally by checking the name pattern
67
+ if @cache_id_was.present? && @cache_id_was =~ /\A[\d]{8}\-[\d]{4}\-[\d]+\-[\d]{4}\z/
68
+ FileUtils.rm_rf(File.join(cache_dir, @cache_id_was))
69
+ end
70
+ end
71
+
72
+ def filename
73
+ if original_filename
74
+ @name ||= Digest::MD5.hexdigest(File.dirname(current_path)).slice(0, 12)
75
+ "#{@name}.#{file.extension}"
76
+ end
77
+ end
78
+
79
+ def self.save_upload_info?
80
+ begin
81
+ %w(asset file flash image media).each do |s|
82
+ "Kindeditor::#{s.camelize}".constantize
83
+ end
84
+ return true
85
+ rescue
86
+ return false
87
+ end
88
+ end
89
+
90
+ end
91
+
@@ -0,0 +1,10 @@
1
+ # encoding: utf-8
2
+
3
+ class Kindeditor::FileUploader < Kindeditor::AssetUploader
4
+
5
+ def extension_white_list
6
+ EXT_NAMES[:file]
7
+ end
8
+
9
+ end
10
+
@@ -0,0 +1,10 @@
1
+ # encoding: utf-8
2
+
3
+ class Kindeditor::FlashUploader < Kindeditor::AssetUploader
4
+
5
+ def extension_white_list
6
+ EXT_NAMES[:flash]
7
+ end
8
+
9
+ end
10
+
@@ -0,0 +1,10 @@
1
+ # encoding: utf-8
2
+
3
+ class Kindeditor::ImageUploader < Kindeditor::AssetUploader
4
+
5
+ def extension_white_list
6
+ EXT_NAMES[:image]
7
+ end
8
+
9
+ end
10
+
@@ -0,0 +1,10 @@
1
+ # encoding: utf-8
2
+
3
+ class Kindeditor::MediaUploader < Kindeditor::AssetUploader
4
+
5
+ def extension_white_list
6
+ EXT_NAMES[:media]
7
+ end
8
+
9
+ end
10
+
data/config/routes.rb ADDED
@@ -0,0 +1,6 @@
1
+ Rails.application.routes.draw do
2
+ namespace :kindeditor do
3
+ post "/upload" => "assets#create"
4
+ get "/filemanager" => "assets#list"
5
+ end
6
+ end
@@ -0,0 +1,10 @@
1
+ Description:
2
+ install kindeditor for your application
3
+
4
+ Example:
5
+ rails generate rails_kindeditor:install
6
+
7
+ This will create:
8
+ config/kindeditor.rb
9
+
10
+
@@ -0,0 +1,23 @@
1
+ module RailsKindeditor
2
+ class InstallGenerator < Rails::Generators::Base
3
+ source_root File.expand_path('../templates', __FILE__)
4
+ desc "Install kindeditor for your application."
5
+
6
+ def copy_kindeditor_files
7
+ if ::Rails.version < "3.1.0"
8
+ warn "Warning: rails_kindeditor ~> v0.3.0 only support Rails3.1+!"
9
+ warn "If you're using rails3.0.x, please check rails_kindeditor v0.2.8"
10
+ else
11
+ template "rails_kindeditor.rb", "config/initializers/rails_kindeditor.rb"
12
+ end
13
+ end
14
+
15
+ def insert_or_copy_js_files
16
+ if File.exist?('app/assets/javascripts/application.js')
17
+ insert_into_file "app/assets/javascripts/application.js", "//= require kindeditor\n", :after => "jquery_ujs\n"
18
+ else
19
+ copy_file "application.js", "app/assets/javascripts/application.js"
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,17 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // the compiled file.
9
+ //
10
+ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
+ // GO AFTER THE REQUIRES BELOW.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require kindeditor
16
+ //= require_tree .
17
+
@@ -0,0 +1,29 @@
1
+ RailsKindeditor.setup do |config|
2
+
3
+ # Specify the subfolders in public directory.
4
+ # You can customize it , eg: config.upload_dir = 'this/is/my/folder'
5
+ config.upload_dir = 'uploads'
6
+
7
+ # Allowed file types for upload.
8
+ config.upload_image_ext = %w[gif jpg jpeg png bmp]
9
+ config.upload_flash_ext = %w[swf flv]
10
+ config.upload_media_ext = %w[swf flv mp3 wav wma wmv mid avi mpg asf rm rmvb]
11
+ config.upload_file_ext = %w[doc docx xls xlsx ppt htm html txt zip rar gz bz2]
12
+
13
+ # Porcess upload image size
14
+ # eg: 1600x1600 => 800x800
15
+ # 1600x800 => 800x400
16
+ # 400x400 => 400x400 # No Change
17
+ # config.image_resize_to_limit = [800, 800]
18
+
19
+ # if you have config in your rails application like this:
20
+ # /config/enviroments/production.rb
21
+ # # config.action_controller.asset_host = "http://asset.example.com"
22
+ # # config.assets.prefix = "assets_prefx"
23
+ # then you should:
24
+ #
25
+ # config.asset_url_prefix = "http://asset.example.com/assets_prefx/" if Rails.env.production?
26
+
27
+
28
+
29
+ end
@@ -0,0 +1,14 @@
1
+ Description:
2
+ Copy model, migration and uploader to your application.
3
+
4
+ Example:
5
+ rails generate rails_kindeditor:migration
6
+
7
+ This will create:
8
+ app/models/kindeditor/asset.rb
9
+ app/models/kindeditor/file.rb
10
+ app/models/kindeditor/flash.rb
11
+ app/models/kindeditor/image.rb
12
+ app/models/kindeditor/media.rb
13
+ db/migrate/xxxxxxxxx_create_kindeditor_assets.rb
14
+
@@ -0,0 +1,36 @@
1
+ module RailsKindeditor
2
+ class MigrationGenerator < Rails::Generators::Base
3
+ include Rails::Generators::Migration
4
+ source_root File.expand_path('../templates', __FILE__)
5
+ desc "Copy model and migration to your application."
6
+ class_option :orm, :type => :string, :aliases => "-o", :default => "active_record", :desc => "ORM options: active_record or mongoid"
7
+
8
+ def copy_files
9
+ orm = options[:orm].to_s
10
+ orm = "active_record" unless %w{active_record mongoid}.include?(orm)
11
+ %w(asset file flash image media).each do |file|
12
+ copy_model(orm, file)
13
+ end
14
+ if Rails.version < '4.0.0' && Rails.version >= '3.0.0' # insert code for rails3
15
+ insert_into_file "app/models/kindeditor/asset.rb", " attr_accessible :asset\n", :after => "before_save :update_asset_attributes\n"
16
+ end
17
+ if orm == "active_record"
18
+ migration_template "migration/migration.rb", "db/migrate/create_kindeditor_assets.rb"
19
+ end
20
+ end
21
+
22
+ def self.next_migration_number(dirname)
23
+ if ActiveRecord::Base.timestamped_migrations
24
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
25
+ else
26
+ "%.3d" % (current_migration_number(dirname) + 1)
27
+ end
28
+ end
29
+
30
+ private
31
+ def copy_model(orm, name)
32
+ template "models/#{orm}/kindeditor/#{name}.rb", "app/models/kindeditor/#{name}.rb"
33
+ end
34
+ end
35
+ end
36
+
@@ -0,0 +1,17 @@
1
+ class CreateKindeditorAssets < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :kindeditor_assets do |t|
4
+ t.string :asset
5
+ t.integer :file_size
6
+ t.string :file_type
7
+ t.integer :owner_id
8
+ t.string :asset_type # list by kindeditor: image, file, media, flash
9
+ t.timestamps
10
+ end
11
+ end
12
+
13
+ def self.down
14
+ drop_table :kindeditor_assets
15
+ end
16
+ end
17
+
@@ -0,0 +1,14 @@
1
+ class Kindeditor::Asset < ActiveRecord::Base
2
+ self.table_name = 'kindeditor_assets'
3
+ mount_uploader :asset, Kindeditor::AssetUploader
4
+ validates_presence_of :asset
5
+ before_save :update_asset_attributes
6
+
7
+ private
8
+ def update_asset_attributes
9
+ if asset.present? && asset_changed?
10
+ self.file_size = asset.file.size
11
+ self.file_type = asset.file.content_type
12
+ end
13
+ end
14
+ end