ckeditor 3.6.0.pre → 3.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. data/Gemfile +21 -10
  2. data/README.rdoc +3 -2
  3. data/lib/ckeditor/orm/mongoid.rb +94 -0
  4. data/lib/ckeditor/version.rb +1 -1
  5. data/lib/generators/ckeditor/install_generator.rb +18 -15
  6. data/lib/generators/ckeditor/models_generator.rb +13 -13
  7. data/lib/generators/ckeditor/templates/ckeditor.rb +7 -6
  8. data/lib/generators/ckeditor/templates/models/active_record/{asset.rb → ckeditor/asset.rb} +0 -0
  9. data/lib/generators/ckeditor/templates/models/active_record/{attachment_file.rb → ckeditor/attachment_file.rb} +0 -0
  10. data/lib/generators/ckeditor/templates/models/active_record/{picture.rb → ckeditor/picture.rb} +0 -0
  11. data/lib/generators/ckeditor/templates/models/mongoid/ckeditor/asset.rb +7 -0
  12. data/lib/generators/ckeditor/templates/models/mongoid/ckeditor/attachment_file.rb +15 -0
  13. data/lib/generators/ckeditor/templates/models/mongoid/ckeditor/picture.rb +13 -0
  14. data/test/dummy/app/models/post.rb +16 -2
  15. data/test/dummy/config/application.rb +3 -3
  16. data/test/dummy/config/boot.rb +6 -7
  17. data/test/dummy/config/database.yml +6 -26
  18. data/test/dummy/config/initializers/ckeditor.rb +6 -6
  19. data/test/dummy/config/mongoid.yml +2 -0
  20. data/test/dummy/db/test.sqlite3 +0 -0
  21. data/test/dummy/log/test.log +1495 -0
  22. data/test/generators/install_generator_test.rb +11 -4
  23. data/test/generators/models_generator_test.rb +12 -2
  24. data/test/orm/active_record.rb +1 -0
  25. data/test/orm/mongoid.rb +6 -0
  26. data/test/test_helper.rb +5 -2
  27. data/test/tmp/app/models/ckeditor/asset.rb +3 -3
  28. data/test/tmp/app/models/ckeditor/attachment_file.rb +11 -11
  29. data/test/tmp/app/models/ckeditor/picture.rb +11 -11
  30. metadata +23 -22
  31. data/test/dummy/app/models/ckeditor/asset.rb +0 -7
  32. data/test/dummy/app/models/ckeditor/attachment_file.rb +0 -15
  33. data/test/dummy/app/models/ckeditor/picture.rb +0 -13
  34. data/test/tmp/db/migrate/20110711170413_create_ckeditor_assets.rb +0 -26
data/Gemfile CHANGED
@@ -4,20 +4,31 @@ gemspec
4
4
 
5
5
  gem "rails", "3.0.9"
6
6
 
7
+ platforms :mri_18 do
8
+ group :test do
9
+ gem 'ruby-debug'
10
+ end
11
+ end
12
+
7
13
  platforms :ruby do
8
- gem "mysql2", '0.2.11'
9
-
14
+ gem "sqlite3"
15
+
16
+ group :development do
17
+ gem "unicorn", "~> 4.0.1"
18
+ end
19
+
10
20
  group :development, :test do
11
21
  gem "capybara", ">= 0.4.0"
12
- gem "redgreen", "~> 1.2.2"
22
+ gem "mynyml-redgreen", "~> 0.7.1", :require => 'redgreen'
23
+ end
24
+
25
+ group :active_record do
13
26
  gem "paperclip", "~> 2.3.12"
14
-
15
- # To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
16
- # gem 'ruby-debug'
17
- # gem 'ruby-debug19'
18
27
  end
19
-
20
- group :development do
21
- gem "mongrel"
28
+
29
+ group :mongoid do
30
+ gem "mongoid"
31
+ gem "bson_ext"
32
+ gem 'mongoid-paperclip', :require => 'mongoid_paperclip'
22
33
  end
23
34
  end
data/README.rdoc CHANGED
@@ -12,7 +12,7 @@ the results users have when publishing it. It brings to the web common editing f
12
12
  * Extra plugins: attachment and embed.
13
13
  * Assets pagination (under construction)
14
14
 
15
- == Install (not currently available, under construction)
15
+ == Install
16
16
 
17
17
  gem "ckeditor", "~> 3.6.0"
18
18
 
@@ -28,8 +28,8 @@ Now generate models for store uploading files:
28
28
 
29
29
  Available orms:
30
30
  * active_record
31
+ * mongoid (Thanks Dmitry Lihachev https://github.com/lda)
31
32
  * mongo_mapper (under construction)
32
- * mongoid (under construction)
33
33
 
34
34
  Autoload ckeditor models folder (application.rb):
35
35
 
@@ -159,5 +159,6 @@ By default, both these methods call "ckeditor_filebrowser_scope" method:
159
159
  == Tests
160
160
 
161
161
  rake test
162
+ rake test CKEDITOR_ORM=mongoid
162
163
 
163
164
  This project rocks and uses MIT-LICENSE.
@@ -0,0 +1,94 @@
1
+ require 'orm_adapter/adapters/mongoid'
2
+
3
+ module Ckeditor
4
+ module Orm
5
+ module Mongoid
6
+ module AssetBase
7
+ def self.included(base)
8
+ base.send(:include, InstanceMethods)
9
+ base.send(:include, ::Mongoid::Document)
10
+ base.send(:include, ::Mongoid::Timestamps)
11
+ base.send(:include, ::Mongoid::Paperclip)
12
+ base.send(:extend, ClassMethods)
13
+ end
14
+
15
+ module ClassMethods
16
+ def self.extended(base)
17
+ base.class_eval do
18
+ belongs_to :assetable, :polymorphic => true
19
+
20
+ before_validation :extract_content_type
21
+ before_create :read_dimensions, :parameterize_filename
22
+
23
+ delegate :url, :path, :styles, :size, :content_type, :to => :data
24
+ end
25
+ end
26
+ end
27
+
28
+ module InstanceMethods
29
+ def filename
30
+ data_file_name
31
+ end
32
+
33
+ def format_created_at
34
+ I18n.l(created_at, :format => "%d.%m.%Y")
35
+ end
36
+
37
+ def has_dimensions?
38
+ respond_to?(:width) && respond_to?(:height)
39
+ end
40
+
41
+ def image?
42
+ Ckeditor::IMAGE_TYPES.include?(data_content_type)
43
+ end
44
+
45
+ def geometry
46
+ @geometry ||= Paperclip::Geometry.from_file(data.to_file)
47
+ @geometry
48
+ end
49
+
50
+ def url_content
51
+ url
52
+ end
53
+
54
+ def url_thumb
55
+ url(:thumb)
56
+ end
57
+
58
+ def as_json(options = nil)
59
+ options = {
60
+ :methods => [:url_content, :url_thumb, :size, :filename, :format_created_at],
61
+ :root => "asset"
62
+ }.merge(options || {})
63
+
64
+ super options
65
+ end
66
+
67
+ protected
68
+
69
+ def parameterize_filename
70
+ unless data_file_name.blank?
71
+ filename = Ckeditor::Utils.parameterize_filename(data_file_name)
72
+ self.data.instance_write(:file_name, filename)
73
+ end
74
+ end
75
+
76
+ def read_dimensions
77
+ if image? && has_dimensions?
78
+ self.width = geometry.width
79
+ self.height = geometry.height
80
+ end
81
+ end
82
+
83
+ # Extract content_type from filename using mime/types gem
84
+ def extract_content_type
85
+ if data_content_type == "application/octet-stream" && !data_file_name.blank?
86
+ content_types = MIME::Types.type_for(data_file_name)
87
+ self.data_content_type = content_types.first.to_s unless content_types.empty?
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
@@ -1,6 +1,6 @@
1
1
  module Ckeditor
2
2
  module Version
3
- GEM = "3.6.0.pre".freeze
3
+ GEM = "3.6.0".freeze
4
4
  EDITOR = "3.6.1".freeze
5
5
  end
6
6
  end
@@ -6,54 +6,57 @@ module Ckeditor
6
6
  class InstallGenerator < Rails::Generators::Base
7
7
  class_option :version, :type => :string, :default => Ckeditor::Version::EDITOR,
8
8
  :desc => "Version of ckeditor which be install"
9
-
9
+
10
+ class_option :orm, :type => :string, :default => 'active_record',
11
+ :desc => "Backend processor for upload support"
12
+
10
13
  desc "Download and install ckeditor"
11
-
14
+
12
15
  def self.source_root
13
16
  @source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
14
- end
15
-
17
+ end
18
+
16
19
  # copy configuration
17
20
  def copy_initializer
18
21
  template "ckeditor.rb", "config/initializers/ckeditor.rb"
19
22
  end
20
-
23
+
21
24
  # copy ckeditor files
22
25
  def install_ckeditor
23
26
  say_status("fetching #{filename}", "", :green)
24
27
  get(download_url, "tmp/#{filename}")
25
-
28
+
26
29
  filepath = Rails.root.join("tmp/#{filename}")
27
-
30
+
28
31
  if File.exist?(filepath)
29
32
  Ckeditor::Utils.extract(filepath, Rails.root.join('public', 'javascripts'))
30
33
  directory "ckeditor", "public/javascripts/ckeditor"
31
34
  FileUtils.rm_rf(filepath)
32
35
  end
33
36
  end
34
-
37
+
35
38
  def download_javascripts
36
39
  js_dir = "public/javascripts/ckeditor/filebrowser/javascripts"
37
-
40
+
38
41
  say_status("fetching rails.js", "", :green)
39
42
  get "https://github.com/rails/jquery-ujs/raw/master/src/rails.js", "#{js_dir}/rails.js"
40
-
43
+
41
44
  say_status("fetching fileuploader.js", "", :green)
42
45
  get "https://raw.github.com/galetahub/file-uploader/master/client/fileuploader.js", "#{js_dir}/fileuploader.js"
43
-
46
+
44
47
  say_status("fetching jquery-1.6.1.min.js", "", :green)
45
48
  get "http://code.jquery.com/jquery-1.6.1.min.js", "#{js_dir}/jquery.js"
46
-
49
+
47
50
  say_status("fetching jquery.tmpl.min.js", "", :green)
48
51
  get "https://raw.github.com/jquery/jquery-tmpl/master/jquery.tmpl.min.js", "#{js_dir}/jquery.tmpl.js"
49
52
  end
50
-
53
+
51
54
  protected
52
-
55
+
53
56
  def download_url
54
57
  "http://download.cksource.com/CKEditor/CKEditor/CKEditor%20#{options[:version]}/#{filename}"
55
58
  end
56
-
59
+
57
60
  def filename
58
61
  "ckeditor_#{options[:version]}.tar.gz"
59
62
  end
@@ -5,13 +5,13 @@ module Ckeditor
5
5
  module Generators
6
6
  class ModelsGenerator < Rails::Generators::Base
7
7
  include Rails::Generators::Migration
8
-
8
+
9
9
  desc "Generates migration for Asset (Picture, AttachmentFile) models"
10
-
10
+
11
11
  # ORM configuration
12
12
  class_option :orm, :type => :string, :default => "active_record",
13
13
  :desc => "Backend processor for upload support"
14
-
14
+
15
15
  def self.source_root
16
16
  @source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'templates', 'models/'))
17
17
  end
@@ -19,30 +19,30 @@ module Ckeditor
19
19
  def self.next_migration_number(dirname)
20
20
  Time.now.strftime("%Y%m%d%H%M%S")
21
21
  end
22
-
22
+
23
23
  def create_models
24
- template "#{generator_dir}/asset.rb",
24
+ template "#{generator_dir}/ckeditor/asset.rb",
25
25
  File.join('app/models', ckeditor_dir, "asset.rb")
26
-
27
- template "#{generator_dir}/picture.rb",
26
+
27
+ template "#{generator_dir}/ckeditor/picture.rb",
28
28
  File.join('app/models', ckeditor_dir, "picture.rb")
29
-
30
- template "#{generator_dir}/attachment_file.rb",
29
+
30
+ template "#{generator_dir}/ckeditor/attachment_file.rb",
31
31
  File.join('app/models', ckeditor_dir, "attachment_file.rb")
32
32
  end
33
-
33
+
34
34
  def create_migration
35
35
  if options[:orm] == "active_record"
36
36
  migration_template "#{generator_dir}/migration.rb", File.join('db/migrate', "create_ckeditor_assets.rb")
37
37
  end
38
38
  end
39
-
39
+
40
40
  protected
41
-
41
+
42
42
  def ckeditor_dir
43
43
  'ckeditor'
44
44
  end
45
-
45
+
46
46
  def generator_dir
47
47
  options[:orm] || "active_record"
48
48
  end
@@ -5,13 +5,14 @@ if Object.const_defined?("Ckeditor")
5
5
  # Load and configure the ORM. Supports :active_record (default), :mongo_mapper and
6
6
  # :mongoid (bson_ext recommended) by default. Other ORMs may be
7
7
  # available as additional gems.
8
- require 'ckeditor/orm/active_record'
9
-
10
- # Allowed image file types for upload.
8
+ require "ckeditor/orm/<%= options[:orm] %>"
9
+
10
+
11
+ # Allowed image file types for upload.
11
12
  # Set to nil or [] (empty array) for all file types
12
- # config.image_file_types = ["jpg", "jpeg", "png", "gif", "tiff"]
13
-
14
- # Allowed attachment file types for upload.
13
+ # config.image_file_types = ["jpg", "jpeg", "png", "gif", "tiff"]
14
+
15
+ # Allowed attachment file types for upload.
15
16
  # Set to nil or [] (empty array) for all file types
16
17
  # config.attachment_file_types = ["doc", "docx", "rar", "zip", "xls", "swf"]
17
18
  end
@@ -0,0 +1,7 @@
1
+ require 'mime/types'
2
+
3
+ class Ckeditor::Asset
4
+ include Ckeditor::Orm::Mongoid::AssetBase
5
+
6
+ attr_accessible :data, :assetable_type, :assetable_id, :assetable
7
+ end
@@ -0,0 +1,15 @@
1
+ class Ckeditor::AttachmentFile < Ckeditor::Asset
2
+ has_mongoid_attached_file :data,
3
+ :url => "/ckeditor_assets/attachments/:id/:filename",
4
+ :path => ":rails_root/public/ckeditor_assets/attachments/:id/:filename"
5
+
6
+ validates_attachment_size :data, :less_than => 100.megabytes
7
+ validates_attachment_presence :data
8
+
9
+ def url_thumb
10
+ @url_thumb ||= begin
11
+ extname = File.extname(filename).gsub(/^\./, '')
12
+ "/javascripts/ckeditor/filebrowser/images/thumbs/#{extname}.gif"
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,13 @@
1
+ class Ckeditor::Picture < Ckeditor::Asset
2
+ has_mongoid_attached_file :data,
3
+ :url => "/ckeditor_assets/pictures/:id/:style_:basename.:extension",
4
+ :path => ":rails_root/public/ckeditor_assets/pictures/:id/:style_:basename.:extension",
5
+ :styles => { :content => '800>', :thumb => '118x100#' }
6
+
7
+ validates_attachment_size :data, :less_than => 2.megabytes
8
+ validates_attachment_presence :data
9
+
10
+ def url_content
11
+ url(:content)
12
+ end
13
+ end
@@ -1,3 +1,17 @@
1
- class Post < ActiveRecord::Base
2
- validates_presence_of :title, :info, :content
1
+ case CKEDITOR_ORM
2
+
3
+ when :active_record
4
+ class Post < ActiveRecord::Base
5
+ validates_presence_of :title, :info, :content
6
+ end
7
+
8
+ when :mongoid
9
+ class Post
10
+ include Mongoid::Document
11
+ field :title
12
+ field :info
13
+ field :content
14
+ validates_presence_of :title, :info, :content
15
+ end
16
+
3
17
  end
@@ -6,9 +6,9 @@ require "action_controller/railtie"
6
6
  require "action_view/railtie"
7
7
  require "action_mailer/railtie"
8
8
 
9
- Bundler.require
9
+ Bundler.require :default, CKEDITOR_ORM
10
+
10
11
  require "ckeditor"
11
- require "paperclip"
12
12
 
13
13
  module Dummy
14
14
  class Application < Rails::Application
@@ -17,7 +17,7 @@ module Dummy
17
17
  # -- all .rb files in that directory are automatically loaded.
18
18
 
19
19
  # Custom directories with classes and modules you want to be autoloadable.
20
- config.autoload_paths += %W(#{config.root}/app/models/ckeditor)
20
+ config.autoload_paths += %W(#{config.root}/../../lib/generators/ckeditor/templates/models/#{CKEDITOR_ORM})
21
21
 
22
22
  # Only load the plugins named here, in the order given (default is alphabetical).
23
23
  # :all can be used as a placeholder for all plugins not explicitly named.
@@ -1,10 +1,9 @@
1
- require 'rubygems'
2
- gemfile = File.expand_path('../../../../Gemfile', __FILE__)
3
-
4
- if File.exist?(gemfile)
5
- ENV['BUNDLE_GEMFILE'] = gemfile
1
+ begin
2
+ require File.expand_path("../../../../.bundle/environment", __FILE__)
3
+ rescue LoadError
4
+ require 'rubygems'
6
5
  require 'bundler'
7
- Bundler.setup
6
+ Bundler.setup :default, :test, CKEDITOR_ORM
8
7
  end
9
8
 
10
- $:.unshift File.expand_path('../../../../lib', __FILE__)
9
+ $:.unshift File.expand_path('../../../../lib', __FILE__)
@@ -1,34 +1,14 @@
1
- # And be sure to use new-style password hashing:
2
- # http://dev.mysql.com/doc/refman/5.0/en/old-client.html
3
1
  development:
4
- adapter: mysql2
5
- encoding: utf8
6
- reconnect: false
7
- database: ckeditor_dummy
8
- pool: 5
9
- username: root
10
- password:
11
- socket: /var/run/mysqld/mysqld.sock
2
+ adapter: sqlite3
3
+ database: db/development.sqlite3
12
4
 
13
5
  # Warning: The database defined as "test" will be erased and
14
6
  # re-generated from your development database when you run "rake".
15
7
  # Do not set this db to the same as development or production.
16
8
  test:
17
- adapter: mysql2
18
- encoding: utf8
19
- reconnect: false
20
- database: ckeditor_dummy_test
21
- pool: 5
22
- username: root
23
- password:
24
- socket: /var/run/mysqld/mysqld.sock
9
+ adapter: sqlite3
10
+ database: db/test.sqlite3
25
11
 
26
12
  production:
27
- adapter: mysql2
28
- encoding: utf8
29
- reconnect: true
30
- database: ckeditor_dummy
31
- pool: 5
32
- username: root
33
- password:
34
- socket: /var/run/mysqld/mysqld.sock
13
+ adapter: sqlite3
14
+ database: db/production.sqlite3