module Ckeditor

Constants

AUTHORIZATION_ADAPTERS
DEFAULT_AUTHORIZE
DEFAULT_CURRENT_USER
IMAGE_TYPES

Public Class Methods

assets() click to toggle source

All css and js files from ckeditor folder

# File lib/ckeditor.rb, line 123
def self.assets
  @assets ||= Ckeditor.cdn_enabled? ?
    ['ckeditor/config.js']
  :
    Utils.select_assets('ckeditor', 'vendor/assets/javascripts') << 'ckeditor/init.js'
end
assets=(value) click to toggle source
# File lib/ckeditor.rb, line 130
def self.assets=(value)
  @assets = value.nil? ? nil : Array(value)
end
assets_pipeline_enabled?() click to toggle source
# File lib/ckeditor.rb, line 239
def self.assets_pipeline_enabled?
  @@assets_pipeline_enabled = Utils.assets_pipeline_enabled? if @@assets_pipeline_enabled.nil?
  @@assets_pipeline_enabled
end
attachment_file_adapter() click to toggle source
# File lib/ckeditor.rb, line 184
def self.attachment_file_adapter
  attachment_file_model.to_adapter
end
attachment_file_model(&block) click to toggle source
# File lib/ckeditor.rb, line 165
def self.attachment_file_model(&block)
  if block_given?
    self.attachment_file_model = block
  else
    @@attachment_file_model_class ||= begin
      if @@attachment_file_model.respond_to? :call
        @@attachment_file_model.call
      else
        @@attachment_file_model || Ckeditor::AttachmentFile
      end
    end
  end
end
attachment_file_model=(value) click to toggle source
# File lib/ckeditor.rb, line 179
def self.attachment_file_model=(value)
  @@attachment_file_model_class = nil
  @@attachment_file_model = value
end
authorize_with(*args, &block) click to toggle source

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.

@example Custom

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

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

@example CanCanCan

Ckeditor.setup do |config|
  config.authorize_with :cancancan
end
# File lib/ckeditor.rb, line 208
def self.authorize_with(*args, &block)
  extension = args.shift

  if extension
    @authorize = lambda do
      @authorization_adapter = Ckeditor::AUTHORIZATION_ADAPTERS[extension].new(*([self] + args).compact)
    end
  elsif block_given?
    @authorize = block
  end

  @authorize || DEFAULT_AUTHORIZE
end
base_path() click to toggle source
# File lib/ckeditor.rb, line 118
def self.base_path
  @base_path ||= (asset_path || File.join([Rails.application.config.assets.prefix, '/ckeditor/']))
end
cdn_enabled?() click to toggle source
# File lib/ckeditor.rb, line 138
def self.cdn_enabled?
  !@@cdn_url.nil?
end
current_user_method(&block) click to toggle source

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.

@example Custom

Ckeditor.setup do |config|
  config.current_user_method do
    current_account
  end
end
# File lib/ckeditor.rb, line 234
def self.current_user_method(&block)
  @current_user = block if block_given?
  @current_user || DEFAULT_CURRENT_USER
end
picture_adapter() click to toggle source
# File lib/ckeditor.rb, line 161
def self.picture_adapter
  picture_model.to_adapter
end
picture_model(&block) click to toggle source
# File lib/ckeditor.rb, line 142
def self.picture_model(&block)
  if block_given?
    self.picture_model = block
  else
    @@picture_model_class ||= begin
      if @@picture_model.respond_to? :call
        @@picture_model.call
      else
        @@picture_model || Ckeditor::Picture
      end
    end
  end
end
picture_model=(value) click to toggle source
# File lib/ckeditor.rb, line 156
def self.picture_model=(value)
  @@picture_model_class = nil
  @@picture_model = value
end
root_path() click to toggle source
# File lib/ckeditor.rb, line 114
def self.root_path
  @root_path ||= Pathname.new(File.dirname(File.expand_path('../', __FILE__)))
end
run_on_precompile?() click to toggle source
# File lib/ckeditor.rb, line 134
def self.run_on_precompile?
  @@run_on_precompile
end
setup() { |self| ... } click to toggle source

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

@example

Ckeditor.setup do |config|
  config.default_per_page = 30
  config.attachment_file_types += ["xml"]
end
# File lib/ckeditor.rb, line 110
def self.setup
  yield self
end