rails_kindeditor 0.2.3 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -37,6 +37,11 @@ Assign your textarea with id in your form:
37
37
 
38
38
  That's all.
39
39
 
40
+ == Customize upload directory(optional)
41
+
42
+ When you run "rails generate rails_kindeditor:install", installer will copy uploader files in you app/uploaders folder.
43
+ Just modify "BASE_DIR" or "store_dir" in asset_uploader.rb.
44
+
40
45
  == Save upload file information into database(optional)
41
46
 
42
47
  rails_kindeditor can save upload file information into database.
@@ -108,6 +113,11 @@ MIT License. Copyright 2011
108
113
 
109
114
  完毕!
110
115
 
116
+ == 自定义上传目录(可选)
117
+
118
+ 当你运行"rails generate rails_kindeditor:install"的时候,安装器会将uploader拷贝到app/uploaders文件夹。
119
+ 在asset_uploader.rb文件中修改"BASE_DIR"或者"store_dir"即可(可参考Carrierwave)。
120
+
111
121
  == 将上传文件信息记录入数据库(可选)
112
122
 
113
123
  rails_kindeditor 可以将上传文件信息记录入数据库,以便扩展应用.
@@ -34,8 +34,8 @@ class Kindeditor::AssetsController < ApplicationController
34
34
  end
35
35
 
36
36
  def list
37
- @root_path = Rails.public_path + "/uploads/"
38
- @root_url = "/uploads/"
37
+ @root_path = Rails.public_path + "/#{Kindeditor::AssetUploader::BASE_DIR}/"
38
+ @root_url = "/#{Kindeditor::AssetUploader::BASE_DIR}/"
39
39
  @img_ext = Kindeditor::AssetUploader::EXT_NAMES[:image]
40
40
  @dir = params[:dir].strip || ""
41
41
  unless Kindeditor::AssetUploader::EXT_NAMES.keys.map(&:to_s).push("").include?(@dir)
@@ -7,6 +7,8 @@ class Kindeditor::AssetUploader < CarrierWave::Uploader::Base
7
7
  :media => %w[swf flv mp3 wav wma wmv mid avi mpg asf rm rmvb],
8
8
  :file => %w[doc docx xls xlsx ppt htm html txt zip rar gz bz2]}
9
9
 
10
+ BASE_DIR = "uploads"
11
+
10
12
  # Include RMagick or ImageScience support:
11
13
  # include CarrierWave::RMagick
12
14
  # include CarrierWave::ImageScience
@@ -19,9 +21,9 @@ class Kindeditor::AssetUploader < CarrierWave::Uploader::Base
19
21
  # This is a sensible default for uploaders that are meant to be mounted:
20
22
  def store_dir
21
23
  if Kindeditor::AssetUploader.save_upload_info?
22
- "uploads/#{model.class.to_s.underscore}/#{model.created_at.strftime("%Y%m")}"
24
+ "#{BASE_DIR}/#{model.class.to_s.underscore.gsub(/(kindeditor\/)|(_uploader)/, '')}/#{model.created_at.strftime("%Y%m")}"
23
25
  else
24
- "uploads/#{self.class.to_s.underscore.gsub(/(kindeditor\/)|(_uploader)/, '')}/#{Time.now.strftime("%Y%m")}"
26
+ "#{BASE_DIR}/#{self.class.to_s.underscore.gsub(/(kindeditor\/)|(_uploader)/, '')}/#{Time.now.strftime("%Y%m")}"
25
27
  end
26
28
  end
27
29
 
@@ -5,5 +5,6 @@ Example:
5
5
  rails generate rails_kindeditor:install
6
6
 
7
7
  This will create:
8
- public/javascripts/kindeditor
8
+ public/kindeditor
9
+ app/uploaders/kindeditor
9
10
 
@@ -9,6 +9,7 @@ module RailsKindeditor
9
9
  else # Rails3.1+
10
10
  directory "kindeditor", "public/kindeditor"
11
11
  end
12
+ directory "uploaders", "app/uploaders"
12
13
  end
13
14
  end
14
15
  end
@@ -0,0 +1,88 @@
1
+ # encoding: utf-8
2
+
3
+ class Kindeditor::AssetUploader < CarrierWave::Uploader::Base
4
+
5
+ EXT_NAMES = {:image => %w[gif jpg jpeg png bmp],
6
+ :flash => %w[swf flv],
7
+ :media => %w[swf flv mp3 wav wma wmv mid avi mpg asf rm rmvb],
8
+ :file => %w[doc docx xls xlsx ppt htm html txt zip rar gz bz2]}
9
+
10
+ BASE_DIR = "uploads"
11
+
12
+ # Include RMagick or ImageScience support:
13
+ # include CarrierWave::RMagick
14
+ # include CarrierWave::ImageScience
15
+
16
+ # Choose what kind of storage to use for this uploader:
17
+ storage :file
18
+ # storage :fog
19
+
20
+ # Override the directory where uploaded files will be stored.
21
+ # This is a sensible default for uploaders that are meant to be mounted:
22
+ def store_dir
23
+ if Kindeditor::AssetUploader.save_upload_info?
24
+ "#{BASE_DIR}/#{model.class.to_s.underscore}/#{model.created_at.strftime("%Y%m")}"
25
+ else
26
+ "#{BASE_DIR}/#{self.class.to_s.underscore.gsub(/(kindeditor\/)|(_uploader)/, '')}/#{Time.now.strftime("%Y%m")}"
27
+ end
28
+ end
29
+
30
+ def cache_dir
31
+ "#{Rails.root}/tmp/uploads"
32
+ end
33
+
34
+ # Provide a default URL as a default if there hasn't been a file uploaded:
35
+ # def default_url
36
+ # "/images/fallback/" + [version_name, "default.png"].compact.join('_')
37
+ # end
38
+
39
+ # Process files as they are uploaded:
40
+ # process :scale => [200, 300]
41
+ #
42
+ # def scale(width, height)
43
+ # # do something
44
+ # end
45
+
46
+ # Create different versions of your uploaded files:
47
+ # version :thumb do
48
+ # process :scale => [50, 50]
49
+ # end
50
+
51
+ # Add a white list of extensions which are allowed to be uploaded.
52
+ # For images you might use something like this:
53
+
54
+ # Override the filename of the uploaded files:
55
+ # Avoid using model.id or version_name here, see uploader/store.rb for details.
56
+ before :store, :remember_cache_id
57
+ after :store, :delete_tmp_dir
58
+
59
+ # store! nil's the cache_id after it finishes so we need to remember it for deletition
60
+ def remember_cache_id(new_file)
61
+ @cache_id_was = cache_id
62
+ end
63
+
64
+ def delete_tmp_dir(new_file)
65
+ # make sure we don't delete other things accidentally by checking the name pattern
66
+ if @cache_id_was.present? && @cache_id_was =~ /\A[\d]{8}\-[\d]{4}\-[\d]+\-[\d]{4}\z/
67
+ FileUtils.rm_rf(File.join(cache_dir, @cache_id_was))
68
+ end
69
+ end
70
+
71
+ def filename
72
+ @name ||= Time.now.to_s(:number)
73
+ "#{@name}#{File.extname(original_filename).downcase}" if original_filename
74
+ end
75
+
76
+ def self.save_upload_info?
77
+ begin
78
+ %w(asset file flash image media).each do |s|
79
+ "Kindeditor::#{s.camelize}".constantize
80
+ end
81
+ return true
82
+ rescue
83
+ return false
84
+ end
85
+ end
86
+
87
+ end
88
+
@@ -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
+
@@ -1,13 +1,14 @@
1
1
  Description:
2
- Copy model , migration and uploader to your application.
2
+ Copy model, migration and uploader to your application.
3
3
 
4
4
  Example:
5
5
  rails generate rails_kindeditor:migration
6
6
 
7
7
  This will create:
8
- app/models/asset.rb
9
- app/models/image.rb
10
- app/models/file.rb
11
- app/uploaders/image_uploader.rb
12
- app/uploaders/file_uploader.rb
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
13
14
 
@@ -1,4 +1,4 @@
1
1
  module RailsKindeditor
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.5"
3
3
  end
4
4
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_kindeditor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-06 00:00:00.000000000Z
12
+ date: 2011-11-22 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: carrierwave
16
- requirement: &70222082057080 !ruby/object:Gem::Requirement
16
+ requirement: &70206492049000 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70222082057080
24
+ version_requirements: *70206492049000
25
25
  description: Kindeditor(4.x) for Rails3, including image and file upload with carrierwave.
26
26
  email: Macrow_wh@163.com
27
27
  executables: []
@@ -226,6 +226,11 @@ files:
226
226
  - lib/generators/rails_kindeditor/install/templates/kindeditor/themes/default/default.css
227
227
  - lib/generators/rails_kindeditor/install/templates/kindeditor/themes/default/default.png
228
228
  - lib/generators/rails_kindeditor/install/templates/kindeditor/themes/simple/simple.css
229
+ - lib/generators/rails_kindeditor/install/templates/uploaders/kindeditor/asset_uploader.rb
230
+ - lib/generators/rails_kindeditor/install/templates/uploaders/kindeditor/file_uploader.rb
231
+ - lib/generators/rails_kindeditor/install/templates/uploaders/kindeditor/flash_uploader.rb
232
+ - lib/generators/rails_kindeditor/install/templates/uploaders/kindeditor/image_uploader.rb
233
+ - lib/generators/rails_kindeditor/install/templates/uploaders/kindeditor/media_uploader.rb
229
234
  - lib/generators/rails_kindeditor/migration/USAGE
230
235
  - lib/generators/rails_kindeditor/migration/migration_generator.rb
231
236
  - lib/generators/rails_kindeditor/migration/templates/migration/migration.rb