ckeditor 3.6.3 → 3.7.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -1
- data/README.rdoc +14 -24
- data/app/assets/javascripts/ckeditor/application.js +5 -0
- data/app/assets/stylesheets/ckeditor/application.css +6 -0
- data/app/controllers/ckeditor/{base_controller.rb → application_controller.rb} +1 -2
- data/app/controllers/ckeditor/attachment_files_controller.rb +2 -2
- data/app/controllers/ckeditor/pictures_controller.rb +2 -2
- data/app/views/ckeditor/shared/_asset.html.erb +2 -2
- data/app/views/ckeditor/shared/_asset_tmpl.html.erb +1 -1
- data/app/views/layouts/{ckeditor.html.erb → ckeditor/application.html.erb} +4 -12
- data/config/locales/sv-SE.ckeditor.yml +8 -0
- data/config/locales/zh-CN.ckeditor.yml +8 -0
- data/config/routes.rb +3 -5
- data/lib/ckeditor.rb +2 -16
- data/lib/ckeditor/engine.rb +4 -1
- data/lib/ckeditor/hooks/formtastic.rb +9 -12
- data/lib/ckeditor/orm/active_record.rb +1 -1
- data/lib/ckeditor/utils.rb +14 -7
- data/lib/ckeditor/version.rb +1 -1
- data/lib/generators/ckeditor/install_generator.rb +48 -55
- data/lib/generators/ckeditor/templates/{models/active_record → active_record}/carrierwave/ckeditor/asset.rb +0 -0
- data/lib/generators/ckeditor/templates/{models/mongoid → active_record}/carrierwave/ckeditor/attachment_file.rb +1 -4
- data/lib/generators/ckeditor/templates/{models/active_record → active_record}/carrierwave/ckeditor/picture.rb +0 -0
- data/lib/generators/ckeditor/templates/{models/active_record → active_record}/carrierwave/migration.rb +0 -0
- data/lib/generators/ckeditor/templates/{models/active_record → active_record}/paperclip/ckeditor/asset.rb +0 -0
- data/lib/generators/ckeditor/templates/{models/active_record → active_record}/paperclip/ckeditor/attachment_file.rb +1 -4
- data/lib/generators/ckeditor/templates/{models/active_record → active_record}/paperclip/ckeditor/picture.rb +0 -0
- data/lib/generators/ckeditor/templates/{models/active_record → active_record}/paperclip/migration.rb +0 -0
- data/lib/generators/ckeditor/templates/{models/base → base}/carrierwave/uploaders/ckeditor_attachment_file_uploader.rb +0 -0
- data/lib/generators/ckeditor/templates/{models/base → base}/carrierwave/uploaders/ckeditor_picture_uploader.rb +0 -0
- data/lib/generators/ckeditor/templates/ckeditor.rb +0 -3
- data/lib/generators/ckeditor/templates/{models/mongoid → mongoid}/carrierwave/ckeditor/asset.rb +0 -0
- data/lib/generators/ckeditor/templates/{models/active_record → mongoid}/carrierwave/ckeditor/attachment_file.rb +1 -4
- data/lib/generators/ckeditor/templates/{models/mongoid → mongoid}/carrierwave/ckeditor/picture.rb +0 -0
- data/lib/generators/ckeditor/templates/{models/mongoid → mongoid}/paperclip/ckeditor/asset.rb +0 -0
- data/lib/generators/ckeditor/templates/{models/mongoid → mongoid}/paperclip/ckeditor/attachment_file.rb +1 -4
- data/lib/generators/ckeditor/templates/{models/mongoid → mongoid}/paperclip/ckeditor/picture.rb +0 -0
- data/test/ckeditor_test.rb +0 -14
- data/test/controllers/attachment_files_controller_test.rb +2 -0
- data/test/controllers/pictures_controller_test.rb +3 -0
- data/test/dummy/Rakefile +1 -1
- data/test/dummy/app/assets/javascripts/application.js +11 -0
- data/test/dummy/app/assets/stylesheets/application.css +7 -0
- data/test/dummy/{public → app/assets}/stylesheets/scaffold.css +0 -0
- data/test/dummy/app/views/layouts/application.html.erb +3 -3
- data/test/dummy/config/application.rb +11 -12
- data/test/dummy/config/boot.rb +7 -6
- data/test/dummy/config/database.yml +11 -0
- data/test/dummy/config/environments/development.rb +7 -3
- data/test/dummy/config/environments/production.rb +23 -12
- data/test/dummy/config/environments/test.rb +5 -1
- data/test/dummy/config/initializers/secret_token.rb +1 -1
- data/test/dummy/config/initializers/session_store.rb +1 -1
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +1 -1
- data/test/dummy/config/routes.rb +2 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/test.log +3681 -6331
- data/test/generators/install_generator_test.rb +58 -15
- data/test/integration/posts_test.rb +5 -5
- data/test/models/attachment_file_test.rb +3 -1
- data/test/models/picture_test.rb +1 -0
- data/test/models/utils_test.rb +19 -0
- data/test/support/controller_hooks.rb +27 -0
- data/test/support/routes.txt +4 -0
- data/test/test_helper.rb +0 -1
- data/test/tmp/app/models/ckeditor/attachment_file.rb +1 -4
- data/test/tmp/config/initializers/ckeditor.rb +18 -0
- data/test/tmp/config/routes.rb +6 -0
- metadata +185 -236
- data/lib/generators/ckeditor/models_generator.rb +0 -70
- data/lib/generators/ckeditor/templates/ckeditor/config.js +0 -65
- data/lib/generators/ckeditor/templates/ckeditor/filebrowser/images/gal_add.jpg +0 -0
- data/lib/generators/ckeditor/templates/ckeditor/filebrowser/images/gal_add.png +0 -0
- data/lib/generators/ckeditor/templates/ckeditor/filebrowser/images/gal_del.png +0 -0
- data/lib/generators/ckeditor/templates/ckeditor/filebrowser/images/gal_more.gif +0 -0
- data/lib/generators/ckeditor/templates/ckeditor/filebrowser/images/preloader.gif +0 -0
- data/lib/generators/ckeditor/templates/ckeditor/filebrowser/images/thumbs/ckfnothumb.gif +0 -0
- data/lib/generators/ckeditor/templates/ckeditor/filebrowser/images/thumbs/mp3.gif +0 -0
- data/lib/generators/ckeditor/templates/ckeditor/filebrowser/images/thumbs/pdf.gif +0 -0
- data/lib/generators/ckeditor/templates/ckeditor/filebrowser/images/thumbs/rar.gif +0 -0
- data/lib/generators/ckeditor/templates/ckeditor/filebrowser/images/thumbs/swf.gif +0 -0
- data/lib/generators/ckeditor/templates/ckeditor/filebrowser/images/thumbs/xls.gif +0 -0
- data/lib/generators/ckeditor/templates/ckeditor/filebrowser/javascripts/application.js +0 -223
- data/lib/generators/ckeditor/templates/ckeditor/filebrowser/stylesheets/uploader.css +0 -115
- data/lib/generators/ckeditor/templates/ckeditor/plugins/attachment/dialogs/attachment.js +0 -1
- data/lib/generators/ckeditor/templates/ckeditor/plugins/attachment/images/attachment.png +0 -0
- data/lib/generators/ckeditor/templates/ckeditor/plugins/attachment/lang/en.js +0 -10
- data/lib/generators/ckeditor/templates/ckeditor/plugins/attachment/lang/ru.js +0 -10
- data/lib/generators/ckeditor/templates/ckeditor/plugins/attachment/lang/uk.js +0 -10
- data/lib/generators/ckeditor/templates/ckeditor/plugins/attachment/plugin.js +0 -1
- data/lib/generators/ckeditor/templates/ckeditor/plugins/embed/dialogs/embed.js +0 -1
- data/lib/generators/ckeditor/templates/ckeditor/plugins/embed/images/embed.png +0 -0
- data/lib/generators/ckeditor/templates/ckeditor/plugins/embed/lang/en.js +0 -9
- data/lib/generators/ckeditor/templates/ckeditor/plugins/embed/lang/ru.js +0 -9
- data/lib/generators/ckeditor/templates/ckeditor/plugins/embed/lang/uk.js +0 -9
- data/lib/generators/ckeditor/templates/ckeditor/plugins/embed/plugin.js +0 -1
- data/test/dummy/db/schema.rb +0 -36
- data/test/dummy/public/javascripts/application.js +0 -2
- data/test/dummy/public/javascripts/controls.js +0 -965
- data/test/dummy/public/javascripts/dragdrop.js +0 -974
- data/test/dummy/public/javascripts/effects.js +0 -1123
- data/test/dummy/public/javascripts/prototype.js +0 -6001
- data/test/dummy/public/javascripts/rails.js +0 -191
- data/test/generators/models_generator_test.rb +0 -61
- data/test/routes_test.rb +0 -47
data/Gemfile
CHANGED
data/README.rdoc
CHANGED
@@ -5,7 +5,7 @@ the results users have when publishing it. It brings to the web common editing f
|
|
5
5
|
|
6
6
|
== Features
|
7
7
|
|
8
|
-
* Rails 3 integration
|
8
|
+
* Rails 3.1 integration
|
9
9
|
* Files browser
|
10
10
|
* HTML5 files uploader
|
11
11
|
* Hooks for formtastic and simple_form forms generators
|
@@ -14,23 +14,13 @@ the results users have when publishing it. It brings to the web common editing f
|
|
14
14
|
|
15
15
|
== Install
|
16
16
|
|
17
|
-
|
17
|
+
Rails 3.1:
|
18
18
|
|
19
|
-
|
19
|
+
gem "ckeditor", "3.7.0.rc1"
|
20
20
|
|
21
|
-
|
21
|
+
Rails <= 3.0:
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
rails generate ckeditor:install
|
26
|
-
|
27
|
-
You can pass version of ckeditor to download (http://ckeditor.com/download/releases):
|
28
|
-
|
29
|
-
rails generate ckeditor:install --version=3.5.4
|
30
|
-
|
31
|
-
=== Install destination
|
32
|
-
|
33
|
-
rails generate ckeditor:install --path=public/assets
|
23
|
+
gem "ckeditor", "3.6.3"
|
34
24
|
|
35
25
|
=== Now generate models for store uploading files
|
36
26
|
|
@@ -40,27 +30,27 @@ For active_record orm is used paperclip gem (it's by default).
|
|
40
30
|
|
41
31
|
gem "paperclip"
|
42
32
|
|
43
|
-
rails generate ckeditor:
|
33
|
+
rails generate ckeditor:install --orm=active_record --backend=paperclip
|
44
34
|
|
45
35
|
==== ActiveRecord + carrierwave
|
46
36
|
|
47
37
|
gem "carrierwave"
|
48
38
|
gem "mini_magick"
|
49
39
|
|
50
|
-
rails generate ckeditor:
|
40
|
+
rails generate ckeditor:install --orm=active_record --backend=carrierwave
|
51
41
|
|
52
42
|
==== Mongoid + paperclip
|
53
43
|
|
54
44
|
gem 'mongoid-paperclip', :require => 'mongoid_paperclip'
|
55
45
|
|
56
|
-
rails generate ckeditor:
|
46
|
+
rails generate ckeditor:install --orm=mongoid --backend=paperclip
|
57
47
|
|
58
48
|
==== Mongoid + carrierwave
|
59
49
|
|
60
50
|
gem "carrierwave-mongoid", :require => 'carrierwave/mongoid'
|
61
51
|
gem "mini_magick"
|
62
52
|
|
63
|
-
rails generate ckeditor:
|
53
|
+
rails generate ckeditor:install --orm=mongoid --backend=carrierwave
|
64
54
|
|
65
55
|
Available orms:
|
66
56
|
* active_record
|
@@ -74,14 +64,14 @@ Autoload ckeditor models folder (application.rb):
|
|
74
64
|
|
75
65
|
== Usage
|
76
66
|
|
77
|
-
Include ckeditor javascripts:
|
67
|
+
Include ckeditor javascripts rails 3.1:
|
78
68
|
|
79
|
-
|
69
|
+
//= require ckeditor/ckeditor
|
80
70
|
|
81
|
-
|
71
|
+
Rails <= 3.0:
|
72
|
+
|
73
|
+
<%= javascript_include_tag :ckeditor %>
|
82
74
|
|
83
|
-
<%= javascript_include_tag "/javascripts/ckeditor/ckeditor.js" %>
|
84
|
-
|
85
75
|
Form helpers:
|
86
76
|
|
87
77
|
cktext_area_tag("test_area", "Ckeditor is the best")
|
@@ -0,0 +1,5 @@
|
|
1
|
+
//= require ckeditor/filebrowser/javascripts/jquery.min.js
|
2
|
+
//= require ckeditor/filebrowser/javascripts/jquery.tmpl.min.js
|
3
|
+
//= require ckeditor/filebrowser/javascripts/fileuploader.js
|
4
|
+
//= require ckeditor/filebrowser/javascripts/rails.js
|
5
|
+
//= require ckeditor/filebrowser/javascripts/application.js
|
@@ -0,0 +1,6 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll automatically include all the stylesheets available in this directory
|
3
|
+
* and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
|
4
|
+
* the top of the compiled file, but it's generally better to create a new file per style scope.
|
5
|
+
*= require ckeditor/filebrowser/stylesheets/uploader.css
|
6
|
+
*/
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class Ckeditor::AttachmentFilesController < Ckeditor::
|
1
|
+
class Ckeditor::AttachmentFilesController < Ckeditor::ApplicationController
|
2
2
|
|
3
3
|
def index
|
4
4
|
@attachments = Ckeditor.attachment_file_model.find_all(ckeditor_attachment_files_scope)
|
@@ -12,7 +12,7 @@ class Ckeditor::AttachmentFilesController < Ckeditor::BaseController
|
|
12
12
|
|
13
13
|
def destroy
|
14
14
|
@attachment.destroy
|
15
|
-
respond_with(@attachment, :location =>
|
15
|
+
respond_with(@attachment, :location => attachment_files_path)
|
16
16
|
end
|
17
17
|
|
18
18
|
protected
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class Ckeditor::PicturesController < Ckeditor::
|
1
|
+
class Ckeditor::PicturesController < Ckeditor::ApplicationController
|
2
2
|
|
3
3
|
def index
|
4
4
|
@pictures = Ckeditor.picture_model.find_all(ckeditor_pictures_scope)
|
@@ -12,7 +12,7 @@ class Ckeditor::PicturesController < Ckeditor::BaseController
|
|
12
12
|
|
13
13
|
def destroy
|
14
14
|
@picture.destroy
|
15
|
-
respond_with(@picture, :location =>
|
15
|
+
respond_with(@picture, :location => pictures_path)
|
16
16
|
end
|
17
17
|
|
18
18
|
protected
|
@@ -1,5 +1,5 @@
|
|
1
1
|
<%= content_tag(:div, :id => dom_id(asset), :class => "gal-item", :"data-url" => asset.url_content) do %>
|
2
|
-
<%= link_to image_tag("
|
2
|
+
<%= link_to image_tag("/assets/ckeditor/filebrowser/images/gal_del.png",
|
3
3
|
:title => I18n.t('ckeditor.buttons.delete')),
|
4
4
|
polymorphic_path(asset, :format => :json),
|
5
5
|
:remote => true,
|
@@ -13,7 +13,7 @@
|
|
13
13
|
<div class="img-name"><%= asset.filename %></div>
|
14
14
|
<div class="time-size">
|
15
15
|
<div class="time"><%= asset.format_created_at %></div>
|
16
|
-
<div class="fileupload-size size"><%= number_to_human_size(asset.size) %></div>
|
16
|
+
<div class="fileupload-size size"><%= number_to_human_size(asset.size) if asset.size %></div>
|
17
17
|
</div>
|
18
18
|
</div>
|
19
19
|
</div>
|
@@ -1,6 +1,6 @@
|
|
1
1
|
<script id="fileupload_tmpl" type="text/x-jquery-tmpl">
|
2
2
|
<div id="asset_${id}" class="gal-item" data-url="${url_content}">
|
3
|
-
<%= link_to image_tag("
|
3
|
+
<%= link_to image_tag("/assets/ckeditor/filebrowser/images/gal_del.png",
|
4
4
|
:title => I18n.t('ckeditor.buttons.delete')),
|
5
5
|
"/ckeditor/${controller}/${id}.json",
|
6
6
|
:remote => true,
|
@@ -6,18 +6,10 @@
|
|
6
6
|
<%= csrf_meta_tag %>
|
7
7
|
<%= tag(:meta, :name => "ckeditor-path", :content => Ckeditor.relative_path) %>
|
8
8
|
<title><%= I18n.t('page_title', :scope => [:ckeditor]) %></title>
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
}
|
14
|
-
.gal-more a {
|
15
|
-
background: url(<%= Ckeditor.relative_path %>/ckeditor/filebrowser/images/gal_more.gif) no-repeat left center;
|
16
|
-
}
|
17
|
-
</style>
|
18
|
-
<% ["jquery.js", "jquery.tmpl.js", "fileuploader.js", "rails.js", "application.js"].each do |js| %>
|
19
|
-
<script src="<%= Ckeditor.relative_path %>/ckeditor/filebrowser/javascripts/<%= js %>" type="text/javascript"></script>
|
20
|
-
<% end %>
|
9
|
+
|
10
|
+
<%= stylesheet_link_tag "ckeditor/application" %>
|
11
|
+
<%= javascript_include_tag "ckeditor/application" %>
|
12
|
+
|
21
13
|
<script type="text/javascript">
|
22
14
|
var CKEditorFuncNum = $.QueryString["CKEditorFuncNum"];
|
23
15
|
var CKEditorName = $.QueryString["CKEditor"];
|
data/config/routes.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
resources :attachment_files
|
5
|
-
end
|
1
|
+
Ckeditor::Engine.routes.draw do
|
2
|
+
resources :pictures, :only => [:index, :create, :destroy]
|
3
|
+
resources :attachment_files, :only => [:index, :create, :destroy]
|
6
4
|
end
|
data/lib/ckeditor.rb
CHANGED
@@ -14,7 +14,6 @@ module Ckeditor
|
|
14
14
|
end
|
15
15
|
|
16
16
|
module Hooks
|
17
|
-
autoload :FormtasticBuilder, 'ckeditor/hooks/formtastic'
|
18
17
|
autoload :SimpleFormBuilder, 'ckeditor/hooks/simple_form'
|
19
18
|
end
|
20
19
|
|
@@ -34,8 +33,8 @@ module Ckeditor
|
|
34
33
|
@@attachment_file_types = ["doc", "docx", "xls", "odt", "ods", "pdf", "rar", "zip", "tar", "tar.gz", "swf"]
|
35
34
|
|
36
35
|
# Ckeditor files destination path
|
37
|
-
mattr_accessor :
|
38
|
-
@@
|
36
|
+
mattr_accessor :relative_path
|
37
|
+
@@relative_path = '/assets/ckeditor'
|
39
38
|
|
40
39
|
# Default way to setup Ckeditor. Run rails generate ckeditor to create
|
41
40
|
# a fresh initializer with all configuration values.
|
@@ -50,19 +49,6 @@ module Ckeditor
|
|
50
49
|
def self.attachment_file_model
|
51
50
|
Ckeditor::AttachmentFile.to_adapter
|
52
51
|
end
|
53
|
-
|
54
|
-
def self.relative_path
|
55
|
-
@@relative_path ||= File.join("/", Rails.root.join(path).relative_path_from(public_path).to_s)
|
56
|
-
end
|
57
|
-
|
58
|
-
def self.public_path
|
59
|
-
Rails.root.join('public')
|
60
|
-
end
|
61
|
-
|
62
|
-
def self.path=(value)
|
63
|
-
@@relative_path = nil
|
64
|
-
@@path = value
|
65
|
-
end
|
66
52
|
end
|
67
53
|
|
68
54
|
require 'ckeditor/engine'
|
data/lib/ckeditor/engine.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
require 'rails'
|
2
|
+
require 'ckeditor'
|
2
3
|
|
3
4
|
module Ckeditor
|
4
5
|
class Engine < ::Rails::Engine
|
6
|
+
isolate_namespace Ckeditor
|
7
|
+
|
5
8
|
config.action_view.javascript_expansions[:ckeditor] = "ckeditor/ckeditor"
|
6
9
|
|
7
10
|
initializer "ckeditor.helpers" do
|
@@ -18,7 +21,7 @@ module Ckeditor
|
|
18
21
|
|
19
22
|
initializer "ckeditor.hooks" do
|
20
23
|
if Object.const_defined?("Formtastic")
|
21
|
-
|
24
|
+
require "ckeditor/hooks/formtastic"
|
22
25
|
end
|
23
26
|
|
24
27
|
if Object.const_defined?("SimpleForm")
|
@@ -1,15 +1,12 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
basic_input_helper(:cktext_area, :text, method, options)
|
11
|
-
end
|
12
|
-
end
|
1
|
+
require "formtastic"
|
2
|
+
|
3
|
+
class CkeditorInput
|
4
|
+
include ::Formtastic::Inputs::Base
|
5
|
+
|
6
|
+
def to_html
|
7
|
+
input_wrapping do
|
8
|
+
label_html <<
|
9
|
+
builder.cktext_area(method, input_html_options)
|
13
10
|
end
|
14
11
|
end
|
15
12
|
end
|
data/lib/ckeditor/utils.rb
CHANGED
@@ -13,11 +13,6 @@ module Ckeditor
|
|
13
13
|
[basename.parameterize('_'), extension].join.downcase
|
14
14
|
end
|
15
15
|
|
16
|
-
def extract(filepath, output)
|
17
|
-
# TODO: need check system OS
|
18
|
-
system("tar --exclude=*.php --exclude=*.asp -C '#{output}' -xzf '#{filepath}' ckeditor/")
|
19
|
-
end
|
20
|
-
|
21
16
|
def js_replace(dom_id, options = {})
|
22
17
|
js_options = applay_options(options)
|
23
18
|
js = ["if (CKEDITOR.instances['#{dom_id}']) {CKEDITOR.remove(CKEDITOR.instances['#{dom_id}']);}"]
|
@@ -48,7 +43,7 @@ module Ckeditor
|
|
48
43
|
|
49
44
|
js_options = applay_options(options)
|
50
45
|
|
51
|
-
"$(document).ready(function(){ new qq.FileUploaderInput({ #{js_options} }); });"
|
46
|
+
"$(document).ready(function(){ new qq.FileUploaderInput({ #{js_options} }); });".html_safe
|
52
47
|
end
|
53
48
|
|
54
49
|
def applay_options(options)
|
@@ -66,11 +61,23 @@ module Ckeditor
|
|
66
61
|
else value
|
67
62
|
end
|
68
63
|
|
69
|
-
str << "#{key}: #{item}
|
64
|
+
str << %Q{"#{key}": #{item}}
|
70
65
|
end
|
71
66
|
|
72
67
|
str.sort.join(',')
|
73
68
|
end
|
69
|
+
|
70
|
+
def filethumb(filename)
|
71
|
+
extname = filename.blank? ? "unknown" : File.extname(filename).gsub(/^\./, '')
|
72
|
+
image = "#{extname}.gif"
|
73
|
+
source = File.expand_path("../../../vendor/assets/javascripts/ckeditor/filebrowser/images/thumbs", __FILE__)
|
74
|
+
|
75
|
+
unless File.exists?(File.join(source, image))
|
76
|
+
image = "unknown.gif"
|
77
|
+
end
|
78
|
+
|
79
|
+
File.join(Ckeditor.relative_path, "filebrowser/images/thumbs", image)
|
80
|
+
end
|
74
81
|
end
|
75
82
|
end
|
76
83
|
end
|
data/lib/ckeditor/version.rb
CHANGED
@@ -1,85 +1,78 @@
|
|
1
1
|
require 'rails/generators'
|
2
|
-
require '
|
2
|
+
require 'rails/generators/migration'
|
3
3
|
|
4
4
|
module Ckeditor
|
5
5
|
module Generators
|
6
6
|
class InstallGenerator < Rails::Generators::Base
|
7
|
-
|
8
|
-
:desc => "Version of ckeditor which be install (by default #{Ckeditor::Version::EDITOR})"
|
7
|
+
include Rails::Generators::Migration
|
9
8
|
|
10
|
-
|
11
|
-
|
9
|
+
desc "Generates migration for Asset (Picture, AttachmentFile) models"
|
10
|
+
|
11
|
+
# ORM configuration
|
12
|
+
class_option :orm, :type => :string, :default => "active_record",
|
13
|
+
:desc => "Backend processor for upload support"
|
14
|
+
|
15
|
+
class_option :backend, :type => :string, :default => 'paperclip',
|
16
|
+
:desc => "Paperclip (by default) or carrierwave"
|
12
17
|
|
13
|
-
class_option :path, :type => :string, :default => Ckeditor.path,
|
14
|
-
:desc => "Ckeditor install directory destination (by default #{Ckeditor.path})"
|
15
|
-
|
16
|
-
desc "Download and install ckeditor into destination folder"
|
17
|
-
|
18
18
|
def self.source_root
|
19
19
|
@source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
|
20
20
|
end
|
21
21
|
|
22
|
+
def self.next_migration_number(dirname)
|
23
|
+
Time.now.strftime("%Y%m%d%H%M%S")
|
24
|
+
end
|
25
|
+
|
22
26
|
# copy configuration
|
23
27
|
def copy_initializer
|
24
28
|
template "ckeditor.rb", "config/initializers/ckeditor.rb"
|
25
29
|
end
|
30
|
+
|
31
|
+
def mount_engine
|
32
|
+
route "mount Ckeditor::Engine => '/ckeditor'"
|
33
|
+
end
|
26
34
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
in_root do
|
32
|
-
filepath = "tmp/#{filename}"
|
33
|
-
get(download_url, filepath)
|
34
|
-
|
35
|
-
if File.exist?(filepath)
|
36
|
-
FileUtils.mkdir_p(install_dir)
|
37
|
-
Ckeditor::Utils.extract(filepath, install_dir)
|
38
|
-
FileUtils.rm_rf(filepath)
|
39
|
-
end
|
35
|
+
def create_models
|
36
|
+
[:asset, :picture, :attachment_file].each do |filename|
|
37
|
+
template "#{generator_dir}/ckeditor/#{filename}.rb",
|
38
|
+
File.join('app/models', ckeditor_dir, "#{filename}.rb")
|
40
39
|
end
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
directory "ckeditor/filebrowser", "#{install_dir}/ckeditor/filebrowser"
|
46
|
-
directory "ckeditor/plugins", "#{install_dir}/ckeditor/plugins"
|
47
|
-
copy_file "ckeditor/config.js", "#{install_dir}/ckeditor/config.js", :force => true
|
40
|
+
|
41
|
+
if backend == "carrierwave"
|
42
|
+
template "#{uploaders_dir}/uploaders/ckeditor_attachment_file_uploader.rb",
|
43
|
+
File.join("app/uploaders", "ckeditor_attachment_file_uploader.rb")
|
48
44
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
end
|
45
|
+
template "#{uploaders_dir}/uploaders/ckeditor_picture_uploader.rb",
|
46
|
+
File.join("app/uploaders", "ckeditor_picture_uploader.rb")
|
47
|
+
end
|
53
48
|
end
|
54
49
|
|
55
|
-
def
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
get "https://github.com/rails/jquery-ujs/raw/master/src/rails.js", "#{js_dir}/rails.js"
|
60
|
-
|
61
|
-
say_status("fetching fileuploader.js", "", :green)
|
62
|
-
get "https://raw.github.com/galetahub/file-uploader/master/client/fileuploader.js", "#{js_dir}/fileuploader.js"
|
63
|
-
|
64
|
-
say_status("fetching jquery-1.6.2.min.js", "", :green)
|
65
|
-
get "https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js", "#{js_dir}/jquery.js"
|
66
|
-
|
67
|
-
say_status("fetching jquery.tmpl.min.js", "", :green)
|
68
|
-
get "https://raw.github.com/jquery/jquery-tmpl/master/jquery.tmpl.min.js", "#{js_dir}/jquery.tmpl.js"
|
50
|
+
def create_migration
|
51
|
+
if ["active_record"].include?(orm)
|
52
|
+
migration_template "#{generator_dir}/migration.rb", File.join('db/migrate', "create_ckeditor_assets.rb")
|
53
|
+
end
|
69
54
|
end
|
70
|
-
|
55
|
+
|
71
56
|
protected
|
72
57
|
|
73
|
-
def
|
74
|
-
|
58
|
+
def ckeditor_dir
|
59
|
+
'ckeditor'
|
75
60
|
end
|
76
61
|
|
77
|
-
def
|
78
|
-
|
62
|
+
def generator_dir
|
63
|
+
@generator_dir ||= [orm, backend].join('/')
|
64
|
+
end
|
65
|
+
|
66
|
+
def uploaders_dir
|
67
|
+
@uploaders_dir ||= ['base', 'carrierwave'].join('/')
|
68
|
+
end
|
69
|
+
|
70
|
+
def orm
|
71
|
+
options[:orm] || "active_record"
|
79
72
|
end
|
80
73
|
|
81
|
-
def
|
82
|
-
options[:
|
74
|
+
def backend
|
75
|
+
options[:backend] || "paperclip"
|
83
76
|
end
|
84
77
|
end
|
85
78
|
end
|