redactor2_rails 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +4 -0
- data/Gemfile +12 -0
- data/LICENSE.txt +21 -0
- data/README.md +207 -0
- data/Rakefile +2 -0
- data/app/controller/redactor2_rails/files_controller.rb +28 -0
- data/app/controller/redactor2_rails/images_controller.rb +28 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/config/routes.rb +4 -0
- data/lib/generators/redactor2/config_generator.rb +18 -0
- data/lib/generators/redactor2/install_generator.rb +75 -0
- data/lib/generators/redactor2/templates/active_record/carrierwave/devise_migration.rb +28 -0
- data/lib/generators/redactor2/templates/active_record/carrierwave/migration.rb +25 -0
- data/lib/generators/redactor2/templates/active_record/carrierwave/redactor2/asset.rb +6 -0
- data/lib/generators/redactor2/templates/active_record/carrierwave/redactor2/file.rb +7 -0
- data/lib/generators/redactor2/templates/active_record/carrierwave/redactor2/image.rb +7 -0
- data/lib/generators/redactor2/templates/base/carrierwave/uploaders/redactor2_rails_file_uploader.rb +15 -0
- data/lib/generators/redactor2/templates/base/carrierwave/uploaders/redactor2_rails_image_uploader.rb +54 -0
- data/lib/generators/redactor2/templates/config.js +14 -0
- data/lib/generators/redactor2/templates/mongoid/carrierwave/redactor/asset.rb +9 -0
- data/lib/generators/redactor2/templates/mongoid/carrierwave/redactor/file.rb +7 -0
- data/lib/generators/redactor2/templates/mongoid/carrierwave/redactor/picture.rb +7 -0
- data/lib/redactor2_rails.rb +40 -0
- data/lib/redactor2_rails/backend/carrierwave.rb +64 -0
- data/lib/redactor2_rails/devise.rb +11 -0
- data/lib/redactor2_rails/engine.rb +9 -0
- data/lib/redactor2_rails/http.rb +89 -0
- data/lib/redactor2_rails/orm/active_record.rb +31 -0
- data/lib/redactor2_rails/orm/base.rb +38 -0
- data/lib/redactor2_rails/orm/mongoid.rb +37 -0
- data/lib/redactor2_rails/version.rb +3 -0
- data/redactor2_rails.gemspec +28 -0
- data/vendor/assets/javascripts/redactor2_rails/config.js +14 -0
- data/vendor/assets/javascripts/redactor2_rails/index.js +2 -0
- data/vendor/assets/javascripts/redactor2_rails/langs/ar.js +50 -0
- data/vendor/assets/javascripts/redactor2_rails/langs/de.js +50 -0
- data/vendor/assets/javascripts/redactor2_rails/langs/en.js +50 -0
- data/vendor/assets/javascripts/redactor2_rails/langs/es.js +50 -0
- data/vendor/assets/javascripts/redactor2_rails/langs/fa.js +50 -0
- data/vendor/assets/javascripts/redactor2_rails/langs/fi.js +50 -0
- data/vendor/assets/javascripts/redactor2_rails/langs/fr.js +50 -0
- data/vendor/assets/javascripts/redactor2_rails/langs/hu.js +50 -0
- data/vendor/assets/javascripts/redactor2_rails/langs/it.js +50 -0
- data/vendor/assets/javascripts/redactor2_rails/langs/ja.js +50 -0
- data/vendor/assets/javascripts/redactor2_rails/langs/ko.js +50 -0
- data/vendor/assets/javascripts/redactor2_rails/langs/nl.js +50 -0
- data/vendor/assets/javascripts/redactor2_rails/langs/pl.js +50 -0
- data/vendor/assets/javascripts/redactor2_rails/langs/pt_br.js +50 -0
- data/vendor/assets/javascripts/redactor2_rails/langs/ru.js +50 -0
- data/vendor/assets/javascripts/redactor2_rails/langs/sv.js +50 -0
- data/vendor/assets/javascripts/redactor2_rails/langs/tr.js +50 -0
- data/vendor/assets/javascripts/redactor2_rails/langs/zh_cn.js +52 -0
- data/vendor/assets/javascripts/redactor2_rails/langs/zh_tw.js +50 -0
- data/vendor/assets/javascripts/redactor2_rails/plugins.js +4 -0
- data/vendor/assets/javascripts/redactor2_rails/plugins/clips.js +60 -0
- data/vendor/assets/javascripts/redactor2_rails/plugins/fullscreen.js +159 -0
- data/vendor/assets/javascripts/redactor2_rails/plugins/source.js +195 -0
- data/vendor/assets/javascripts/redactor2_rails/plugins/textdirection.js +36 -0
- data/vendor/assets/javascripts/redactor2_rails/redactor.js +9989 -0
- data/vendor/assets/javascripts/redactor2_rails/redactor.min.js +13 -0
- data/vendor/assets/stylesheets/redactor2_rails/css/redactor.css +931 -0
- data/vendor/assets/stylesheets/redactor2_rails/index.css +1 -0
- data/vendor/assets/stylesheets/redactor2_rails/plugins.css +1 -0
- data/vendor/assets/stylesheets/redactor2_rails/plugins/clips.css +10 -0
- metadata +183 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ef4640dd375e7602b6a40cddc7e8a81a519bc870
|
4
|
+
data.tar.gz: bb50d1f5a411cbc3e3c363d136f18f76aac9cd0e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fbf6e2dc5d1a213a7b81f7084d198fab70e9bfcea63dbc15084e93c932428c55fa6e977547e72f22580649c62874b2c3b3db48fa7196c2059edf4dadd8542bdf
|
7
|
+
data.tar.gz: 37a5f23deae830e924b09fabcc4f8a5e145acb3dc7c379f6253879d26fdf5dbd5783875ee2f01dbd2f7dcf75a54d94e324a61d39644aa54583febf979ab7859d
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Oleg Sulyanov
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,207 @@
|
|
1
|
+
# Imperavi Redactor for Rails 3.x - 4 Asset Pipeline
|
2
|
+
|
3
|
+
redactor2_rails integrates Imperavi Redactor for Rails Asset Pipeline (Rails 4, 3.x versions are supported)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'redactor2_rails'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install redactor2_rails
|
18
|
+
|
19
|
+
### Generate models for store uploading files
|
20
|
+
|
21
|
+
#### ActiveRecord + carrierwave
|
22
|
+
Add this lines to your application's Gemfile:
|
23
|
+
|
24
|
+
gem "carrierwave"
|
25
|
+
gem "mini_magick"
|
26
|
+
|
27
|
+
And then execute:
|
28
|
+
|
29
|
+
$ rails generate redactor2:install
|
30
|
+
|
31
|
+
or
|
32
|
+
|
33
|
+
$ rails generate redactor2:install --devise
|
34
|
+
|
35
|
+
# --devise option generate user_id attribute for asset(Imeg, File) models.
|
36
|
+
# For more details show Devise gem.
|
37
|
+
# Now, Pictures and Documents uploading available only for signed in users
|
38
|
+
# All uploaded files will stored with current user_id
|
39
|
+
# User will choose only own uploaded Images and Files
|
40
|
+
|
41
|
+
$ rake db:migrate
|
42
|
+
|
43
|
+
#### Mongoid + carrierwave
|
44
|
+
Add this lines to your application's Gemfile:
|
45
|
+
|
46
|
+
gem "carrierwave"
|
47
|
+
gem "carrierwave-mongoid", :require => "carrierwave/mongoid"
|
48
|
+
gem "mini_magick"
|
49
|
+
|
50
|
+
$ rails generate redactor2:install
|
51
|
+
|
52
|
+
### Include the Redactor assets
|
53
|
+
|
54
|
+
Add to your `application.js`:
|
55
|
+
|
56
|
+
//= require redactor2_rails
|
57
|
+
|
58
|
+
Add to your `application.css`:
|
59
|
+
|
60
|
+
*= require redactor2_rails
|
61
|
+
|
62
|
+
### Initialize Redactor
|
63
|
+
|
64
|
+
For each textarea that you want to use with Redactor,
|
65
|
+
add the "redactor" class and ensure it has a unique ID:
|
66
|
+
|
67
|
+
<%= text_area_tag :editor, "", :class => "redactor", :rows => 40, :cols => 120 %>
|
68
|
+
|
69
|
+
### Custom Your redactor
|
70
|
+
|
71
|
+
If you need change some config in redactor, you can
|
72
|
+
|
73
|
+
$ rails generate redactor2:config
|
74
|
+
|
75
|
+
Then generate `app\assets\redactor2_rails\config.js`.
|
76
|
+
|
77
|
+
See the [Redactor Documentation](http://imperavi.com/redactor/docs/settings/) for a full list of configuration options.
|
78
|
+
|
79
|
+
|
80
|
+
If You Want To setup a new language in Redactor you should do two things:
|
81
|
+
|
82
|
+
In you file `app\assets\redactor2_rails\config.js` set option
|
83
|
+
|
84
|
+
"lang":'ru'
|
85
|
+
|
86
|
+
and
|
87
|
+
|
88
|
+
Add to your `application.js`:
|
89
|
+
|
90
|
+
//= require redactor2_rails/langs/ru
|
91
|
+
|
92
|
+
#### Setting a max image size with carrierwave
|
93
|
+
|
94
|
+
If you want to set a maximum image size used when a user uploads an image via carrierwave, open the uploader file and add add the following:
|
95
|
+
|
96
|
+
# app/uploaders/redactor2_rails_picture_uploader.rb:33
|
97
|
+
|
98
|
+
process :resize_to_limit => [500, -1]
|
99
|
+
|
100
|
+
The above example will set the image to have a maximum width of 500px.
|
101
|
+
|
102
|
+
### Using plugins
|
103
|
+
|
104
|
+
This gem comes bundled with several Redactor plugins:
|
105
|
+
|
106
|
+
- Fullscreen
|
107
|
+
- Clips
|
108
|
+
- Text direction
|
109
|
+
|
110
|
+
Full details of these can be found at [Redactor Plugins](http://imperavi.com/redactor/plugins/)
|
111
|
+
|
112
|
+
To include all the plugins just add to your `application.js`:
|
113
|
+
|
114
|
+
//= require redactor2_rails/plugins
|
115
|
+
|
116
|
+
and add to your `application.css`:
|
117
|
+
|
118
|
+
*= redactor2_rails/plugins
|
119
|
+
|
120
|
+
If you would prefer to pick and choose which plugins to include you can
|
121
|
+
add for example:
|
122
|
+
|
123
|
+
//= require redactor2_rails/plugins/clips
|
124
|
+
|
125
|
+
After including the desired plugins they can be configured in the redactor config file as normal.
|
126
|
+
|
127
|
+
To add it into the editor just add 'plugins' attributes to config.js file and specify which ones do you want to use:
|
128
|
+
|
129
|
+
$('.redactor').redactor(
|
130
|
+
{ "plugins": ['fullscreen',
|
131
|
+
'textdirection',
|
132
|
+
'clips']
|
133
|
+
});
|
134
|
+
|
135
|
+
### Defining a Devise User Model
|
136
|
+
|
137
|
+
By default redactor2_rails uses the `User` model.
|
138
|
+
|
139
|
+
You may use a different model by:
|
140
|
+
|
141
|
+
1. Run a migration to update the user_id column in the
|
142
|
+
2. Overriding the user class in an initializer.
|
143
|
+
3. Overriding the authentication helpers in your controller.
|
144
|
+
|
145
|
+
Create a new Migration: `rails g rename_user_id_to_new_user_id`
|
146
|
+
|
147
|
+
# db/migrate/...rename_user_id_to_new_user_id.rb
|
148
|
+
|
149
|
+
class RenameUserIdToNewUserId < ActiveRecord::Migration
|
150
|
+
def up
|
151
|
+
rename_column :redactor2_assets, :user_id, :admin_user_id
|
152
|
+
end
|
153
|
+
|
154
|
+
def down
|
155
|
+
rename_column :redactor2_assets, :admin_user_id, :user_id
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
# config/initializers/redactor2.rb
|
160
|
+
# Overrides the user class
|
161
|
+
|
162
|
+
module RedactorRails
|
163
|
+
def self.devise_user
|
164
|
+
%s(admin_user) # name of your user class
|
165
|
+
end
|
166
|
+
|
167
|
+
# You may override this to support legacy schema.
|
168
|
+
# def self.devise_user_key
|
169
|
+
# "#{self.devise_user.to_s}_id".to_sym
|
170
|
+
# end
|
171
|
+
end
|
172
|
+
|
173
|
+
# app/controllers/application_controller.rb
|
174
|
+
|
175
|
+
class ApplicationController < ActionController::Base
|
176
|
+
...
|
177
|
+
|
178
|
+
def redactor2_authenticate_user!
|
179
|
+
authenticate_admin_user! # devise before_filter
|
180
|
+
end
|
181
|
+
|
182
|
+
def redactor2_current_user
|
183
|
+
current_admin_user # devise user helper
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
## Statement
|
188
|
+
|
189
|
+
`redactor2_rails` base on [SammyLin/redactor-rails](https://github.com/SammyLin/redactor-rails) project.
|
190
|
+
|
191
|
+
|
192
|
+
## Contributing
|
193
|
+
|
194
|
+
1. Fork it
|
195
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
196
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
197
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
198
|
+
5. Create new Pull Request
|
199
|
+
|
200
|
+
## License
|
201
|
+
|
202
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
203
|
+
|
204
|
+
You may use `Redactor` for non-commercial websites for free, however, we do not guarantee any technical support.
|
205
|
+
|
206
|
+
Redactor has [3 different licenses](http://imperavi.com/redactor/download/) for commercial use.
|
207
|
+
For details please see [License Agreement](http://imperavi.com/redactor/license/).
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
class Redactor2Rails::FilesController < ApplicationController
|
2
|
+
before_filter :redactor2_authenticate_user!
|
3
|
+
|
4
|
+
def create
|
5
|
+
@file = Redactor2Rails.file_model.new
|
6
|
+
|
7
|
+
file = params[:file]
|
8
|
+
@file.data = Redactor2Rails::Http.normalize_param(file, request)
|
9
|
+
if @file.has_attribute?(:"#{Redactor2Rails.devise_user_key}")
|
10
|
+
@file.send("#{Redactor2Rails.devise_user}=", redactor_current_user)
|
11
|
+
@file.assetable = redactor_current_user
|
12
|
+
end
|
13
|
+
|
14
|
+
if @file.save
|
15
|
+
render json: { url: @file.url, name: @file.filename }
|
16
|
+
else
|
17
|
+
render json: { error: @file.errors }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def redactor2_authenticate_user!
|
24
|
+
if Redactor2Rails.file_model.new.has_attribute?(Redactor2Rails.devise_user)
|
25
|
+
super
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class Redactor2Rails::ImagesController < ApplicationController
|
2
|
+
before_filter :redactor2_authenticate_user!
|
3
|
+
|
4
|
+
def create
|
5
|
+
@image = Redactor2Rails.image_model.new
|
6
|
+
|
7
|
+
file = params[:file]
|
8
|
+
@image.data = Redactor2Rails::Http.normalize_param(file, request)
|
9
|
+
if @image.has_attribute?(:"#{Redactor2Rails.devise_user_key}")
|
10
|
+
@image.send("#{Redactor2Rails.devise_user}=", redactor_current_user)
|
11
|
+
@image.assetable = redactor_current_user
|
12
|
+
end
|
13
|
+
|
14
|
+
if @image.save
|
15
|
+
render json: { id: @image.id, url: @image.url(:content) }
|
16
|
+
else
|
17
|
+
render json: { error: @image.errors }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def redactor2_authenticate_user!
|
24
|
+
if Redactor2Rails.image_model.new.has_attribute?(Redactor2Rails.devise_user)
|
25
|
+
super
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "redactor2_rails"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/config/routes.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
module Redactor2
|
4
|
+
module Generators
|
5
|
+
class ConfigGenerator < ::Rails::Generators::Base
|
6
|
+
desc 'Generates redactor2_rails config'
|
7
|
+
|
8
|
+
def self.source_root
|
9
|
+
@source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
def create_config
|
14
|
+
template 'config.js', File.join('app/assets/javascripts/redactor2_rails', 'config.js')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/migration'
|
3
|
+
module Redactor2
|
4
|
+
module Generators
|
5
|
+
class InstallGenerator < ::Rails::Generators::Base
|
6
|
+
include ::Rails::Generators::Migration
|
7
|
+
desc 'Generates redactor2_rails models, uploaders and migration'
|
8
|
+
|
9
|
+
class_option :orm, :type => :string, :default => 'active_record',
|
10
|
+
:desc => 'ORM (active_record/mongoid)'
|
11
|
+
|
12
|
+
class_option :upload_processor, :type => :string, :default => 'carrierwave',
|
13
|
+
:desc => 'Image processor (carrierwave)'
|
14
|
+
|
15
|
+
def self.source_root
|
16
|
+
@source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.next_migration_number(dirname)
|
20
|
+
Time.now.strftime('%Y%m%d%H%M%S')
|
21
|
+
end
|
22
|
+
|
23
|
+
def mount_engine
|
24
|
+
route "mount Redactor2Rails::Engine => '/redactor2_rails'"
|
25
|
+
end
|
26
|
+
|
27
|
+
def create_models
|
28
|
+
[:asset, :image, :file].each do |filename|
|
29
|
+
template "#{generator_dir}/redactor2/#{filename}.rb",
|
30
|
+
File.join('app/models', redactor2_dir, "#{filename}.rb")
|
31
|
+
end
|
32
|
+
|
33
|
+
if upload_processor.to_s == 'carrierwave'
|
34
|
+
[:image, :file].each do |filename|
|
35
|
+
template "#{uploaders_dir}/uploaders/redactor2_rails_#{filename}_uploader.rb",
|
36
|
+
File.join("app/uploaders", "redactor2_rails_#{filename}_uploader.rb")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def create_migrations
|
42
|
+
if orm.to_s == "active_record"
|
43
|
+
if ARGV.include?('--devise')
|
44
|
+
migration_template "#{generator_dir}/devise_migration.rb", File.join('db/migrate', 'create_redactor2_assets.rb')
|
45
|
+
else
|
46
|
+
migration_template "#{generator_dir}/migration.rb", File.join('db/migrate', 'create_redactor2_assets.rb')
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
protected
|
52
|
+
|
53
|
+
def redactor2_dir
|
54
|
+
'redactor2_rails'
|
55
|
+
end
|
56
|
+
|
57
|
+
def generator_dir
|
58
|
+
@generator_dir ||= [orm, upload_processor].join('/')
|
59
|
+
end
|
60
|
+
|
61
|
+
def uploaders_dir
|
62
|
+
@uploaders_dir ||= ['base', 'carrierwave'].join('/')
|
63
|
+
end
|
64
|
+
|
65
|
+
def orm
|
66
|
+
options[:orm] || 'active_record'
|
67
|
+
end
|
68
|
+
|
69
|
+
def upload_processor
|
70
|
+
options[:upload_processor] || 'carrierwave'
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|