Module: Ckeditor

Defined in:
lib/ckeditor.rb,
lib/ckeditor/http.rb,
lib/ckeditor/utils.rb,
lib/ckeditor/engine.rb,
lib/ckeditor/version.rb,
lib/ckeditor/orm/base.rb,
lib/ckeditor/text_area.rb,
lib/ckeditor/orm/mongoid.rb,
lib/ckeditor/hooks/cancan.rb,
lib/ckeditor/backend/dragonfly.rb,
lib/ckeditor/backend/paperclip.rb,
lib/ckeditor/orm/active_record.rb,
lib/ckeditor/backend/carrierwave.rb,
lib/ckeditor/helpers/controllers.rb,
lib/ckeditor/helpers/form_helper.rb,
lib/ckeditor/helpers/view_helper.rb,
lib/ckeditor/helpers/form_builder.rb,
lib/generators/ckeditor/install_generator.rb

Defined Under Namespace

Modules: ApplicationHelper, Backend, Generators, Helpers, Hooks, Http, Orm, Utils, Version Classes: ApplicationController, Asset, AttachmentFile, AttachmentFilesController, Engine, Picture, PicturesController, TextArea

Constant Summary collapse

IMAGE_TYPES =
['image/jpeg', 'image/png', 'image/gif', 'image/jpg', 'image/pjpeg', 'image/tiff', 'image/x-png']
DEFAULT_AUTHORIZE =
Proc.new {}
AUTHORIZATION_ADAPTERS =
{}
DEFAULT_CURRENT_USER =
Proc.new do
  request.env["warden"].try(:user) || respond_to?(:current_user) && current_user
end
@@image_file_types =
["jpg", "jpeg", "png", "gif", "tiff"]
@@attachment_file_types =
["doc", "docx", "xls", "odt", "ods", "pdf", "rar", "zip", "tar", "tar.gz", "swf"]
@@relative_path =
'/assets/ckeditor'
@@assets =
nil
@@parameterize_filenames =
true

Class Method Summary collapse

Class Method Details

.assetsObject

All css and js files from ckeditor folder



77
78
79
# File 'lib/ckeditor.rb', line 77

def self.assets
  @@assets ||= Utils.select_assets("ckeditor", "vendor/assets/javascripts") << "ckeditor/init.js"
end

.attachment_file_modelObject



85
86
87
# File 'lib/ckeditor.rb', line 85

def self.attachment_file_model
  Ckeditor::AttachmentFile.to_adapter
end

.authorize_with(*args, &block) ⇒ Object

Setup authorization to be run as a before filter This is run inside the controller instance so you can setup any authorization you need to.

By default, there is no authorization.

To use an authorization adapter, pass the name of the adapter. For example, to use with CanCan, pass it like this.

Examples:

Custom

Ckeditor.setup do |config|
  config.authorize_with do
    redirect_to root_path unless warden.user.is_admin?
  end
end

CanCan

Ckeditor.setup do |config|
  config.authorize_with :cancan
end


109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/ckeditor.rb', line 109

def self.authorize_with(*args, &block)
  extension = args.shift
  
  if extension
    @authorize = Proc.new {
      @authorization_adapter = Ckeditor::AUTHORIZATION_ADAPTERS[extension].new(*([self] + args).compact)
    }
  else
    @authorize = block if block
  end

  @authorize || DEFAULT_AUTHORIZE
end

.current_user_method(&block) ⇒ Object

Setup a different method to determine the current user or admin logged in. This is run inside the controller instance and made available as a helper.

By default, request.env.user or current_user will be used.

Examples:

Custom

Ckeditor.setup do |config|
  config.current_user_method do
    
  end
end


135
136
137
138
# File 'lib/ckeditor.rb', line 135

def self.current_user_method(&block)
  @current_user = block if block
  @current_user || DEFAULT_CURRENT_USER
end

.picture_modelObject



81
82
83
# File 'lib/ckeditor.rb', line 81

def self.picture_model
  Ckeditor::Picture.to_adapter
end

.root_pathObject



72
73
74
# File 'lib/ckeditor.rb', line 72

def self.root_path
  @root_path ||= Pathname.new(File.dirname(File.expand_path('../', __FILE__)))
end

.setup {|_self| ... } ⇒ Object

Default way to setup Ckeditor. Run rails generate ckeditor to create a fresh initializer with all configuration values.

Examples:

Ckeditor.setup do |config|
  config.parameterize_filenames = false
  config.attachment_file_types += ["xml"]
end

Yields:

  • (_self)

Yield Parameters:

  • _self (Ckeditor)

    the object that the method was called on



68
69
70
# File 'lib/ckeditor.rb', line 68

def self.setup
  yield self
end