baidu_ueditor_rails5 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +93 -0
- data/Rakefile +34 -0
- data/app/assets/javascripts/baidu_ueditor.js +16 -0
- data/app/assets/javascripts/ueditor/preinit.js.erb +3 -0
- data/app/controllers/baidu_ueditor_rails/assets_controller.rb +77 -0
- data/app/controllers/baidu_ueditor_rails/base_controller.rb +9 -0
- data/app/helpers/baidu_ueditor_rails/application_helper.rb +4 -0
- data/app/models/ueditor/asset.rb +6 -0
- data/app/models/ueditor/attachment_file.rb +4 -0
- data/app/models/ueditor/image.rb +4 -0
- data/config/routes.rb +6 -0
- data/lib/baidu_ueditor_rails.rb +49 -0
- data/lib/baidu_ueditor_rails/engine.rb +18 -0
- data/lib/baidu_ueditor_rails/utils.rb +40 -0
- data/lib/baidu_ueditor_rails/version.rb +3 -0
- data/lib/generators/baidu_ueditor_rails/install/install_generator.rb +41 -0
- data/lib/generators/baidu_ueditor_rails/install/templates/migration.rb +11 -0
- data/lib/generators/baidu_ueditor_rails/install/templates/ueditor.rb +9 -0
- data/lib/generators/baidu_ueditor_rails/install/templates/ueditor_custom_config.js +12 -0
- data/lib/tasks/baidu_ueditor_rails_tasks.rake +34 -0
- data/test/baidu_ueditor_rails_test.rb +7 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +23 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +29 -0
- data/test/dummy/config/environments/production.rb +80 -0
- data/test/dummy/config/environments/test.rb +36 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +12 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +4 -0
- data/test/dummy/public/404.html +58 -0
- data/test/dummy/public/422.html +58 -0
- data/test/dummy/public/500.html +57 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/integration/navigation_test.rb +10 -0
- data/test/test_helper.rb +15 -0
- metadata +160 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b904f63166aac4adf820ee0c39b1dc630db074a620003056daac227f11519a95
|
4
|
+
data.tar.gz: e550e093386c0552adaf1086a2d8c0bb8de65d3975ef22725237a2d3bcc1bc09
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 974ba5af876471c7798f67de0fc54758c03e5dd9adf97990803a80d700718010069a6302e573718c698fa94d3025b9715daf6784fb3078434b04db815090a3c9
|
7
|
+
data.tar.gz: 22c1107a8c1dc84ae4fda7c86f76238fb3c93fdcfb1e0fe3eb4c7d65f0b33011c45000dbf92c053a55068cc552b132d057477f7fbbcc9c89a819ee134775b27e
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2013 Doabit
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
# Baidu ueditor for rails
|
2
|
+
|
3
|
+
[baidu ueditor][1] for rails, precompile codes from [tinymce-rails][2]
|
4
|
+
|
5
|
+
[1]: http://ueditor.baidu.com/website/
|
6
|
+
[2]: https://github.com/spohlenz/tinymce-rails
|
7
|
+
|
8
|
+
### Notice: The project is unreleased.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
gem 'baidu_ueditor_rails5', github: 'doabit/baidu_ueditor_rails'
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
|
21
|
+
## Generating custom config js
|
22
|
+
|
23
|
+
Usage:
|
24
|
+
|
25
|
+
|
26
|
+
rails g baidu_ueditor_rails:install
|
27
|
+
|
28
|
+
|
29
|
+
Then add codes in application.js
|
30
|
+
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
//= require baidu_ueditor
|
34
|
+
//= require ueditor_custom_config
|
35
|
+
```
|
36
|
+
|
37
|
+
config `routes.rb`
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
mount BaiduUeditorRails::Engine => "/ueditor"
|
41
|
+
```
|
42
|
+
|
43
|
+
## Custom config
|
44
|
+
|
45
|
+
In ueditor_custom_config.js, it looks like:
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
//ueditor custom config
|
49
|
+
(function () {
|
50
|
+
window.CUSTOM_CONFIG = {
|
51
|
+
// Insert your config code
|
52
|
+
// toolbars: [
|
53
|
+
// ['Source','Undo','Redo','Cleardoc','SearchReplace','InsertImage','WordImage','Bold','ForeColor','JustifyLeft',
|
54
|
+
// 'JustifyCenter','JustifyRight','JustifyJustify','RemoveFormat','FormatMatch','AutoTypeSet','PastePlain',
|
55
|
+
// 'FontSize','Preview','Link','FullScreen', 'PageBreak', 'InsertTable','Attachment','InsertVideo']
|
56
|
+
// ],
|
57
|
+
serverUrl: '/ueditor',
|
58
|
+
imageManagerUrlPrefix: ''
|
59
|
+
};
|
60
|
+
jQuery.extend(window.UEDITOR_CONFIG, window.CUSTOM_CONFIG);
|
61
|
+
})();
|
62
|
+
```
|
63
|
+
|
64
|
+
you can write your custom config in
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
window.CUSTOM_CONFIG = {
|
68
|
+
//.........
|
69
|
+
};
|
70
|
+
```
|
71
|
+
|
72
|
+
## Views
|
73
|
+
|
74
|
+
```javascript
|
75
|
+
<script type="text/javascript">
|
76
|
+
var editor = new UE.ui.Editor();
|
77
|
+
editor.render("your_textarea_id");
|
78
|
+
</script>
|
79
|
+
```
|
80
|
+
|
81
|
+
## TODO
|
82
|
+
|
83
|
+
1. Add upload image and file.
|
84
|
+
2. Add form helpers.
|
85
|
+
|
86
|
+
|
87
|
+
## Contributing
|
88
|
+
|
89
|
+
1. Fork it
|
90
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
91
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
92
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
93
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'BaiduUeditorRails'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
|
18
|
+
load 'rails/tasks/engine.rake'
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
Bundler::GemHelper.install_tasks
|
23
|
+
|
24
|
+
require 'rake/testtask'
|
25
|
+
|
26
|
+
Rake::TestTask.new(:test) do |t|
|
27
|
+
t.libs << 'lib'
|
28
|
+
t.libs << 'test'
|
29
|
+
t.pattern = 'test/**/*_test.rb'
|
30
|
+
t.verbose = false
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
task default: :test
|
@@ -0,0 +1,16 @@
|
|
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
|
+
// 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 ueditor/preinit
|
14
|
+
//= require ueditor/ueditor.config
|
15
|
+
//= require ueditor/ueditor.all
|
16
|
+
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
module BaiduUeditorRails
|
3
|
+
class AssetsController < BaiduUeditorRails::BaseController
|
4
|
+
protect_from_forgery except: [:upload]
|
5
|
+
|
6
|
+
def index
|
7
|
+
json = {
|
8
|
+
"imageActionName": 'upload',
|
9
|
+
"imageFieldName": 'upfile',
|
10
|
+
"imageMaxSize": 2_048_000,
|
11
|
+
"imageAllowFiles": ['.png', '.jpg', '.jpeg', '.gif', '.bmp'],
|
12
|
+
"imageCompressEnable": true,
|
13
|
+
"imageCompressBorder": 1600,
|
14
|
+
"imageInsertAlign": 'none',
|
15
|
+
"imageUrlPrefix": '',
|
16
|
+
'catchRemoteImageEnable': false,
|
17
|
+
"imageManagerListSize": 10,
|
18
|
+
"imageManagerUrlPrefix": ''
|
19
|
+
}
|
20
|
+
case params[:uaction]
|
21
|
+
when 'config'
|
22
|
+
render plain: json.to_json
|
23
|
+
when 'upload'
|
24
|
+
upload
|
25
|
+
when 'list'
|
26
|
+
list
|
27
|
+
else
|
28
|
+
list
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def upload
|
33
|
+
file_name = params[:upfile].original_filename
|
34
|
+
@asset = Ueditor::Image.new(file: params[:upfile], name: file_name)
|
35
|
+
if @asset.save
|
36
|
+
render plain: { 'url' => @asset.file.service_url, 'title' => '1', 'state' => 'SUCCESS' }.to_json
|
37
|
+
else
|
38
|
+
render plain: { 'url' => @asset.file.service_url, 'title' => '1', 'state' => 'error' }.to_json
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def list
|
43
|
+
per_page = 15
|
44
|
+
start = params[:start]
|
45
|
+
|
46
|
+
@assets = Ueditor::Image.order('id desc').offset(start).limit(per_page)
|
47
|
+
str = []
|
48
|
+
@assets.each do |asset|
|
49
|
+
str.push("url": asset.file.service_url.to_s, "mtime": asset.created_at)
|
50
|
+
end
|
51
|
+
|
52
|
+
s = { 'state' => 'SUCCESS', 'list' => str, 'start' => start, 'total' => Ueditor::Image.count }
|
53
|
+
render json: s
|
54
|
+
end
|
55
|
+
|
56
|
+
# def file_upload
|
57
|
+
# # file_types = { 'application/zip' => '.zip', 'application/octet-stream' => '.rar',
|
58
|
+
# # 'text/plain' => '.txt', 'application/msword' => '.doc' }
|
59
|
+
# original = params[:Filedata].original_filename
|
60
|
+
# @file = Ueditor::AttachmentFile.new(file: params[:Filedata], name: original)
|
61
|
+
# filename = ''
|
62
|
+
# state = '失败'
|
63
|
+
# file_type = ''
|
64
|
+
# # binding.pry
|
65
|
+
# if @file.save
|
66
|
+
# state = 'SUCCESS'
|
67
|
+
# file_url = @file.service_url
|
68
|
+
# file_type = ".#{@file.asset_url.split('.').last}"
|
69
|
+
# # echo '{"state":"' . $state . '","url":"' . $fileName . '","fileType":"'
|
70
|
+
# # . $current_type . '","original":"'.$clientFile["name"] .'"}';
|
71
|
+
# else
|
72
|
+
# state = '上传失败'
|
73
|
+
# end
|
74
|
+
# render json: { state: state, url: file_url, fileType: file_type, original: original }
|
75
|
+
# end
|
76
|
+
end
|
77
|
+
end
|
data/config/routes.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
module BaiduUeditorRails
|
2
|
+
autoload :Utils, 'baidu_ueditor_rails/utils'
|
3
|
+
|
4
|
+
DEFAULT_CURRENT_USER = lambda do
|
5
|
+
request.env['warden'].try(:user) || respond_to?(:current_user) && current_user
|
6
|
+
end
|
7
|
+
|
8
|
+
# Ckeditor files destination path
|
9
|
+
mattr_accessor :relative_path
|
10
|
+
@@relative_path = 'ueditor'
|
11
|
+
|
12
|
+
mattr_accessor :assets_languages
|
13
|
+
mattr_accessor :assets_plugins
|
14
|
+
@@assets_languages = nil
|
15
|
+
@@assets_plugins = nil
|
16
|
+
|
17
|
+
# Ueditor assets path
|
18
|
+
mattr_accessor :asset_path
|
19
|
+
@@asset_path = nil
|
20
|
+
|
21
|
+
def self.setup
|
22
|
+
yield self
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.root_path
|
26
|
+
@root_path ||= Pathname.new(File.dirname(File.expand_path('../', __FILE__)))
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.base_path
|
30
|
+
@base_path ||= (asset_path || File.join([Rails.application.config.assets.prefix, '/ueditor/']))
|
31
|
+
end
|
32
|
+
|
33
|
+
# All css and js files from ckeditor folder
|
34
|
+
def self.assets
|
35
|
+
ass = Utils.select_assets('ueditor', 'vendor/assets/javascripts')
|
36
|
+
@assets ||= ass
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.assets=(value)
|
40
|
+
@assets = value.nil? ? nil : Array(value)
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.current_user_method(&block)
|
44
|
+
@current_user = block if block_given?
|
45
|
+
@current_user || DEFAULT_CURRENT_USER
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
require "baidu_ueditor_rails/engine"
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module BaiduUeditorRails
|
2
|
+
class Engine < ::Rails::Engine
|
3
|
+
isolate_namespace BaiduUeditorRails
|
4
|
+
initializer 'ckeditor.assets_precompile', group: :all do |app|
|
5
|
+
app.config.assets.precompile += BaiduUeditorRails.assets
|
6
|
+
end
|
7
|
+
|
8
|
+
rake_tasks do
|
9
|
+
load BaiduUeditorRails.root_path.join('lib/tasks/baidu_ueditor_rails_tasks.rake')
|
10
|
+
|
11
|
+
if Rake::Task.task_defined?('assets:precompile')
|
12
|
+
Rake::Task['assets:precompile'].enhance do
|
13
|
+
Rake::Task['ueditor:nondigest'].invoke
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module BaiduUeditorRails
|
2
|
+
module Utils
|
3
|
+
def self.select_assets(path, relative_path)
|
4
|
+
relative_folder = BaiduUeditorRails.root_path.join(relative_path)
|
5
|
+
folder = relative_folder.join(path)
|
6
|
+
extensions = '*.{js,css,png,gif,jpg,html}'
|
7
|
+
languages = []
|
8
|
+
|
9
|
+
# Files at root
|
10
|
+
files = Dir[folder.join(extensions)]
|
11
|
+
|
12
|
+
# Filter plugins
|
13
|
+
if BaiduUeditorRails.assets_plugins.nil?
|
14
|
+
files += Dir[folder.join('third-party', '**', extensions)]
|
15
|
+
else
|
16
|
+
BaiduUeditorRails.assets_plugins.each do |plugin|
|
17
|
+
files += Dir[folder.join('third-party', plugin, '**', extensions)]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# Other folders
|
22
|
+
Dir[folder.join('*/')].each do |subfolder|
|
23
|
+
path = Pathname.new(subfolder)
|
24
|
+
next if ['third-party'].include?(path.basename.to_s)
|
25
|
+
files += Dir[path.join('**', extensions)]
|
26
|
+
end
|
27
|
+
|
28
|
+
files.inject([]) do |items, name|
|
29
|
+
file = Pathname.new(name)
|
30
|
+
base = file.basename('.*').to_s
|
31
|
+
|
32
|
+
if !name.include?('/i18n/') || languages.include?(base) || languages.empty?
|
33
|
+
items << file.relative_path_from(relative_folder).to_s
|
34
|
+
end
|
35
|
+
|
36
|
+
items
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
module BaiduUeditorRails
|
4
|
+
module Generators
|
5
|
+
class InstallGenerator < ::Rails::Generators::Base
|
6
|
+
include Rails::Generators::Migration
|
7
|
+
|
8
|
+
source_root File.expand_path("../templates", __FILE__)
|
9
|
+
desc "This generator installs baidu ueditor custom config"
|
10
|
+
|
11
|
+
def add_custom_config
|
12
|
+
if File.exist?("app/assets/javascripts/ueditor_custom_config.js")
|
13
|
+
js = File.read("app/assets/javascripts/ueditor_custom_config.js")
|
14
|
+
insert_into_file "app/assets/javascripts/ueditor_custom_config.js", js, :after => "ueditor custom config\n"
|
15
|
+
else
|
16
|
+
copy_file "ueditor_custom_config.js", "app/assets/javascripts/ueditor_custom_config.js"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def add_init_config
|
21
|
+
copy_file "ueditor.rb", "config/initializers/ueditor.rb"
|
22
|
+
end
|
23
|
+
|
24
|
+
def add_migrate_file
|
25
|
+
migration_template 'migration.rb', 'db/migrate/create_ueditor_assets.rb', migration_version: migration_version
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.next_migration_number(dirname) #:nodoc:
|
29
|
+
Time.now.utc.strftime('%Y%m%d%H%M%S')
|
30
|
+
end
|
31
|
+
|
32
|
+
def rails5?
|
33
|
+
Rails.version.start_with? '5'
|
34
|
+
end
|
35
|
+
|
36
|
+
def migration_version
|
37
|
+
"[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]" if rails5?
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|