rails_kindeditor 0.4.6 → 0.4.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 34a1caa64fbe3191d4baf1d8e46e0c534ae01515
4
- data.tar.gz: 161088b41104740736b8de6c40e020651e046b34
3
+ metadata.gz: 3851f658444ef5cfa536213a825b41f3109b0948
4
+ data.tar.gz: 141f31b1dabbaa8419b7eb8dd5d6b9593acbf04d
5
5
  SHA512:
6
- metadata.gz: 622feef63934646240973a3c750bb0591ab63763c5ddab7de72fb5c9c8a813c0877725d9904faefc94134c84d73a720f3c88e94ebf606f47f3fb7497c05028fe
7
- data.tar.gz: e39d0698e0c0191d5ee179458db002be90a0e3c24d4f17cb01237908fed1922dfb12943061adb4bd8b22783a2c5f3ab483d66cd359e6fc3c927f2249943cb1cf
6
+ metadata.gz: 3b556f25d5d5bf6c6b89090e4c3693b3b7b51745aaac74f1b3a8934b8136fe5c18ba26c90707b34ffaa78ce5a94853695c7ab544277921717a2667c284a7e536
7
+ data.tar.gz: 18cd4eb2c47a4e5717482ad6f0d08a04adc3fcfdad4693f497fa0e1c5d02c16ad115b839be55c4324de5c3f7e322b1352ad31c07581177828a1ac4dcd5e66868
data/README.md CHANGED
@@ -102,7 +102,7 @@ simple mode
102
102
  When you need to specify the owner_id:
103
103
 
104
104
  ```ruby
105
- f.kindeditor :content, owner_id: @article.id, data: {upload: kindeditor_upload_json_path(owner_id: @article.id), filemanager: kindeditor_file_manager_json_path}
105
+ f.kindeditor :content, owner: @article
106
106
  ```
107
107
 
108
108
  ```coffeescript
@@ -224,7 +224,7 @@ You can specify the owner for uploaded files, when the owner was destroying, all
224
224
  ```ruby
225
225
  <%= form_for @article do |f| %>
226
226
  ...
227
- <%= f.kindeditor :content, :owner_id => @article.id %>
227
+ <%= f.kindeditor :content, :owner => @article %>
228
228
  ...
229
229
  <% end %>
230
230
  ```
@@ -366,7 +366,7 @@ simple模式也需要手动设定
366
366
  需要指定owner_id的方法:
367
367
 
368
368
  ```ruby
369
- f.kindeditor :content, owner_id: @article.id, data: {upload: kindeditor_upload_json_path(owner_id: @article.id), filemanager: kindeditor_file_manager_json_path}
369
+ f.kindeditor :content, owner: @article
370
370
  ```
371
371
 
372
372
  ```coffeescript
@@ -484,7 +484,7 @@ rails_kindeditor 可以将上传文件信息记录入数据库,以便扩展应
484
484
  ```ruby
485
485
  <%= form_for @article do |f| %>
486
486
  ...
487
- <%= f.kindeditor :content, :owner_id => @article.id %>
487
+ <%= f.kindeditor :content, :owner => @article %>
488
488
  ...
489
489
  <% end %>
490
490
  ```
@@ -9,7 +9,8 @@ class Kindeditor::AssetsController < ApplicationController
9
9
  begin
10
10
  @asset = "Kindeditor::#{@dir.camelize}".constantize.new(:asset => @imgFile)
11
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
12
+ @asset.owner_type = params[:owner_type] ? params[:owner_type] : ''
13
+ logger.warn '========= Warning: the owner have not been created, "delete uploaded files automatically" will not work. =========' if defined?(logger) && @asset.owner_id == 0
13
14
  @asset.asset_type = @dir
14
15
  if @asset.save
15
16
  render :text => ({:error => 0, :url => @asset.asset.url}.to_json)
@@ -5,6 +5,7 @@ class CreateKindeditorAssets < ActiveRecord::Migration
5
5
  t.integer :file_size
6
6
  t.string :file_type
7
7
  t.integer :owner_id
8
+ t.string :owner_type
8
9
  t.string :asset_type # list by kindeditor: image, file, media, flash
9
10
  t.timestamps
10
11
  end
@@ -3,11 +3,11 @@ if defined?(ActiveRecord)
3
3
  def self.has_many_kindeditor_assets(*args)
4
4
  options = args.extract_options!
5
5
  asset_name = args[0] ? args[0].to_s : 'assets'
6
- has_many asset_name.to_sym, :class_name => 'Kindeditor::Asset', :foreign_key => 'owner_id', :dependent => options[:dependent]
6
+ has_many asset_name.to_sym, :class_name => 'Kindeditor::Asset', :as => :owner, :dependent => options[:dependent]
7
7
 
8
8
  class_name = self.name
9
9
  Kindeditor::Asset.class_eval do
10
- belongs_to :owner, :class_name => class_name, :foreign_key => 'owner_id'
10
+ belongs_to :owner, :polymorphic => true
11
11
  end
12
12
  end
13
13
  end
@@ -12,14 +12,33 @@ module RailsKindeditor
12
12
  # TODO: Refactory options: 1. kindeditor_option 2. html_option
13
13
  input_html = (options.delete(:input_html) || {}).stringify_keys
14
14
  output_buffer = ActiveSupport::SafeBuffer.new
15
- output_buffer << build_text_area_tag(name, method, self, options, input_html)
15
+ output_buffer << build_text_area_tag(name, method, self, merge_assets_info(options), input_html)
16
16
  output_buffer << javascript_tag(js_replace(input_html['id'], options))
17
17
  end
18
18
 
19
+ def merge_assets_info(options)
20
+ owner = options.delete(:owner)
21
+ if Kindeditor::AssetUploader.save_upload_info? && (!owner.nil?) && (!owner.id.nil?)
22
+ begin
23
+ owner_id = owner.id
24
+ owner_type = owner.class.name
25
+ options.reverse_merge!(owner_id: owner_id, owner_type: owner_type, data: {upload: kindeditor_upload_json_path(owner_id: owner_id, owner_type: owner_type), filemanager: kindeditor_file_manager_json_path})
26
+ return options
27
+ end
28
+ else
29
+ options.reverse_merge!(data: {upload: kindeditor_upload_json_path, filemanager: kindeditor_file_manager_json_path})
30
+ end
31
+ end
32
+
19
33
  def kindeditor_upload_json_path(*args)
20
34
  options = args.extract_options!
21
35
  owner_id_query_string = options[:owner_id] ? "?owner_id=#{options[:owner_id]}" : ''
22
- "#{main_app_root_url}kindeditor/upload#{owner_id_query_string}"
36
+ owner_type_query_string = options[:owner_type] ? "&owner_type=#{options[:owner_type]}" : ''
37
+ if owner_id_query_string == '' && owner_type_query_string == ''
38
+ "#{main_app_root_url}kindeditor/upload"
39
+ else
40
+ "#{main_app_root_url}kindeditor/upload#{owner_id_query_string}#{owner_type_query_string}"
41
+ end
23
42
  end
24
43
 
25
44
  def kindeditor_file_manager_json_path
@@ -62,8 +81,8 @@ module RailsKindeditor
62
81
  options.reverse_merge!(:width => '100%')
63
82
  options.reverse_merge!(:height => 300)
64
83
  options.reverse_merge!(:allowFileManager => true)
65
- options.merge!(:uploadJson => kindeditor_upload_json_path(:owner_id => options.delete(:owner_id)))
66
- options.merge!(:fileManagerJson => kindeditor_file_manager_json_path)
84
+ options.reverse_merge!(:uploadJson => kindeditor_upload_json_path(:owner_id => options.delete(:owner_id), :owner_type => options.delete(:owner_type)))
85
+ options.reverse_merge!(:fileManagerJson => kindeditor_file_manager_json_path)
67
86
  if options[:simple_mode] == true
68
87
  options.merge!(:items => %w{fontname fontsize | forecolor hilitecolor bold italic underline removeformat | justifyleft justifycenter justifyright insertorderedlist insertunorderedlist | emoticons image link})
69
88
  end
@@ -1,4 +1,4 @@
1
1
  module RailsKindeditor
2
- VERSION = "0.4.6"
2
+ VERSION = "0.4.7"
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.4.6
4
+ version: 0.4.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Macrow