rails_kindeditor 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -2,3 +2,6 @@ source "http://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in rails_kindeditor.gemspec
4
4
  gemspec
5
+
6
+ gem "carrierwave", "~> 0.5.4"
7
+
data/README.rdoc CHANGED
@@ -16,17 +16,33 @@ The generator will copy migration to your application. When you are done, rememb
16
16
 
17
17
  rake db:migrate
18
18
 
19
+ Don't forget add this to your Gemfile
20
+
21
+ gem "carrierwave", "~> 0.5.4"
22
+ gem "rails_kindeditor"
23
+
19
24
  == Usage
20
25
 
21
- Basically include this in the page you wish to use the editor in:
22
- <%= include_kindeditor %>
26
+ Basically include <%= include_kindeditor_if_needed %> under the <head> element of your in your layout file:
27
+
28
+ <%= include_kindeditor_if_needed %>
29
+
30
+ In your controller, use include_kindeditor method to load kindeditor javascript:
31
+
32
+ include_kindeditor
33
+
34
+ You can load kindeditor javascript only in some action if you needed:
35
+
36
+ include_kindeditor :only => [:new, :edit]
37
+ include_kindeditor :except => [:index, :show, :destroy, :create]
38
+
39
+ Assign your textarea with id
40
+
41
+ :id => "kindeditor_id"
23
42
 
24
- then use it like this:
25
- <%= f.text_area :content, :id => "editor_id" %>
26
- or <%= text_area_tag :content, :id => "editor_id" %>
27
- or <textarea id="editor_id"></textarea>
43
+ You can config kindeditor by rails_kindeditor-init.js file:
28
44
 
29
- just assign the id to "editor_id".
45
+ public/javascripts/kindeditor/kindeditor-init.js
30
46
 
31
47
  == License
32
48
 
@@ -16,9 +16,9 @@ class Kindeditor::FileUploader < CarrierWave::Uploader::Base
16
16
  "uploads/File/#{Time.now.strftime("%Y-%m")}"
17
17
  end
18
18
 
19
- #def cache_dir
20
- # "#{Rails.root}/tmp/uploads"
21
- #end
19
+ def cache_dir
20
+ "#{Rails.root}/tmp/uploads"
21
+ end
22
22
 
23
23
  # Provide a default URL as a default if there hasn't been a file uploaded:
24
24
  # def default_url
@@ -45,8 +45,23 @@ class Kindeditor::FileUploader < CarrierWave::Uploader::Base
45
45
 
46
46
  # Override the filename of the uploaded files:
47
47
  # Avoid using model.id or version_name here, see uploader/store.rb for details.
48
+ before :store, :remember_cache_id
49
+ after :store, :delete_tmp_dir
50
+
51
+ # store! nil's the cache_id after it finishes so we need to remember it for deletition
52
+ def remember_cache_id(new_file)
53
+ @cache_id_was = cache_id
54
+ end
55
+
56
+ def delete_tmp_dir(new_file)
57
+ # make sure we don't delete other things accidentally by checking the name pattern
58
+ if @cache_id_was.present? && @cache_id_was =~ /\A[\d]{8}\-[\d]{4}\-[\d]+\-[\d]{4}\z/
59
+ FileUtils.rm_rf(File.join(cache_dir, @cache_id_was))
60
+ end
61
+ end
62
+
48
63
  def filename
49
- @name ||= Time.now.to_date.to_s(:db) + "-" + ActiveSupport::SecureRandom.hex
64
+ @name ||= Time.now.to_s(:number)
50
65
  "#{@name}#{File.extname(original_filename).downcase}" if original_filename
51
66
  end
52
67
 
@@ -16,9 +16,9 @@ class Kindeditor::ImageUploader < CarrierWave::Uploader::Base
16
16
  "uploads/Image/#{Time.now.strftime("%Y-%m")}"
17
17
  end
18
18
 
19
- #def cache_dir
20
- # "#{Rails.root}/tmp/uploads"
21
- #end
19
+ def cache_dir
20
+ "#{Rails.root}/tmp/uploads"
21
+ end
22
22
 
23
23
  # Provide a default URL as a default if there hasn't been a file uploaded:
24
24
  # def default_url
@@ -45,8 +45,23 @@ class Kindeditor::ImageUploader < CarrierWave::Uploader::Base
45
45
 
46
46
  # Override the filename of the uploaded files:
47
47
  # Avoid using model.id or version_name here, see uploader/store.rb for details.
48
+ before :store, :remember_cache_id
49
+ after :store, :delete_tmp_dir
50
+
51
+ # store! nil's the cache_id after it finishes so we need to remember it for deletition
52
+ def remember_cache_id(new_file)
53
+ @cache_id_was = cache_id
54
+ end
55
+
56
+ def delete_tmp_dir(new_file)
57
+ # make sure we don't delete other things accidentally by checking the name pattern
58
+ if @cache_id_was.present? && @cache_id_was =~ /\A[\d]{8}\-[\d]{4}\-[\d]+\-[\d]{4}\z/
59
+ FileUtils.rm_rf(File.join(cache_dir, @cache_id_was))
60
+ end
61
+ end
62
+
48
63
  def filename
49
- @name ||= Time.now.to_date.to_s(:db) + "-" + ActiveSupport::SecureRandom.hex
64
+ @name ||= Time.now.to_s(:number)
50
65
  "#{@name}#{File.extname(original_filename).downcase}" if original_filename
51
66
  end
52
67
 
@@ -1,5 +1,6 @@
1
1
  KE.show({
2
2
  id : 'kindeditor_id',
3
+ width: "100%",
3
4
  allowFileManager: true,
4
5
  imageUploadJson : '/kindeditor/upload',
5
6
  fileManagerJson: '/kindeditor/filemanager'
@@ -0,0 +1,23 @@
1
+ module RailsKindeditor
2
+ module ControllerAdditions
3
+ module ClassMethods
4
+ def include_kindeditor(options = {})
5
+ proc = Proc.new do |c|
6
+ c.instance_variable_set(:@use_kindeditor, true)
7
+ end
8
+ before_filter(proc, options)
9
+ end
10
+ end
11
+
12
+ def self.included(base)
13
+ base.extend ClassMethods
14
+ end
15
+ end
16
+ end
17
+
18
+ if defined? ActionController
19
+ ActionController::Base.class_eval do
20
+ include RailsKindeditor::ControllerAdditions
21
+ end
22
+ end
23
+
@@ -0,0 +1,12 @@
1
+ module RailsKindeditor
2
+ module Helper
3
+ def include_kindeditor_if_needed
4
+ if @use_kindeditor
5
+ javascript_include_tag "kindeditor/kindeditor.js", "kindeditor/kindeditor-init.js"
6
+ end
7
+ end
8
+ end
9
+ end
10
+
11
+ ActionView::Base.send(:include, RailsKindeditor::Helper)
12
+
@@ -1,3 +1,4 @@
1
1
  module RailsKindeditor
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
4
+
@@ -1,10 +1,4 @@
1
- module RailsKindeditor
2
- require 'rails_kindeditor/engine'
3
-
4
- module ActionView::Helpers::AssetTagHelper
5
- def include_kindeditor
6
- javascript_include_tag "kindeditor/kindeditor.js", "kindeditor/kindeditor-init.js"
7
- end
8
- end
9
- end
1
+ require 'rails_kindeditor/engine'
2
+ require 'rails_kindeditor/helper'
3
+ require 'rails_kindeditor/controller_additions'
10
4
 
@@ -12,13 +12,13 @@ Gem::Specification.new do |s|
12
12
  s.summary = "kindeditor for rails3"
13
13
  s.description = "kindeditor for rails3, including image and file upload with carrierwave."
14
14
 
15
- s.add_dependency "carrierwave"
16
-
17
15
  s.rubyforge_project = "rails_kindeditor"
18
16
 
19
17
  s.files = `git ls-files`.split("\n")
20
18
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
22
20
  s.require_paths = ["lib"]
21
+
22
+ s.add_dependency("carrierwave", "~> 0.5.4")
23
23
  end
24
24
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: rails_kindeditor
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.1
5
+ version: 0.0.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Macrow
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-06-05 00:00:00 +08:00
13
+ date: 2011-06-12 00:00:00 +08:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -19,9 +19,9 @@ dependencies:
19
19
  requirement: &id001 !ruby/object:Gem::Requirement
20
20
  none: false
21
21
  requirements:
22
- - - ">="
22
+ - - ~>
23
23
  - !ruby/object:Gem::Version
24
- version: "0"
24
+ version: 0.5.4
25
25
  type: :runtime
26
26
  version_requirements: *id001
27
27
  description: kindeditor for rails3, including image and file upload with carrierwave.
@@ -224,7 +224,9 @@ files:
224
224
  - lib/generators/rails_kindeditor/migration/migration_generator.rb
225
225
  - lib/generators/rails_kindeditor/migration/templates/migration/migration.rb
226
226
  - lib/rails_kindeditor.rb
227
+ - lib/rails_kindeditor/controller_additions.rb
227
228
  - lib/rails_kindeditor/engine.rb
229
+ - lib/rails_kindeditor/helper.rb
228
230
  - lib/rails_kindeditor/version.rb
229
231
  - rails_kindeditor.gemspec
230
232
  has_rdoc: true