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 +4 -4
- data/README.md +4 -4
- data/app/controllers/kindeditor/assets_controller.rb +2 -1
- data/lib/generators/rails_kindeditor/migration/templates/migration/migration.rb +1 -0
- data/lib/rails_kindeditor/active_record.rb +2 -2
- data/lib/rails_kindeditor/helper.rb +23 -4
- data/lib/rails_kindeditor/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3851f658444ef5cfa536213a825b41f3109b0948
|
4
|
+
data.tar.gz: 141f31b1dabbaa8419b7eb8dd5d6b9593acbf04d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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,
|
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, :
|
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,
|
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, :
|
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
|
-
|
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)
|
@@ -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', :
|
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, :
|
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
|
-
"
|
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.
|
66
|
-
options.
|
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
|