require "rich"

if Object.const_defined?("Rich")
  Rich.setup do |config|
    # == Backend configuration
    # Rich uses Paperclip (https://github.com/thoughtbot/paperclip) by default.
    # You will need to add it to your Gemfile, however.
    # config.backend = :paperclip
    #
    # Optionally, you can use CarrierWave (https://github.com/carrierwaveuploader/carrierwave).
    # You will need to add it to your Gemfile.
    # config.backend = :carrierwave

    # == CKEditor configuration
    #
    # Rich ships with what I hope are sensible defaults.
    # You may want to override these.
    #
    # For example, the elements available in the formats
    # dropdown are defined like this:
    config.editor[:format_tags] = "h1;h2;h3;h4;h5;h6;p;pre"
    #
    # By default, Rich visualizes what type of element
    # you are editing. To disable this:
    #   config.editor[:startupOutlineBlocks] = false


    # == Image styles
    #
    # Rich uses paperclip for image processing. You can
    # define the styles you would like to use here. You
    # can use the standard syntax allowed by paperclip.
    # See: https://github.com/thoughtbot/paperclip/wiki/Thumbnail-Generation
    #
    # When you change these after uploading some files,
    # remember to re-generate your styles by running:
    #   rake rich:refresh_assets
    config.image_styles = {
      mini: '60x60>',
      thumb: '120x120>',
      small: '240x240>',
      medium: '480x480>',
      large: '960x960>',
      full: '1480x1480>',
      huge: '1920x1920>',
    }

    # == Convert options
    #
    # You can pass additional commands to ImageMagick to set image quality,
    # apply a blur, and other fancy tricks.
    config.convert_options = {
      all: %{
        -unsharp 3x1+0.5
        -quality 85
        -strip
        -auto-orient
        -colorspace sRGB
      }
    }

    # == Allowed styles (in file manager)
    #
    # Of the styles specified above, which should be user
    # selectable in the file manager?
    #
    # Example:
    #   config.allowed_styles = [ :large, :thumb ]
    #
    # Default:
    # config.allowed_styles = :all

    # == Default Style
    #
    # The style to insert by default. In addition to the
    # styles defined above you can also use :original to get
    # the unprocessed file. Make sure this style exists.
    config.default_style = :medium

    # == Upload non-image files
    #
    # Setting this option to true will add a second Rich filebrowser icon to
    # the editor toolbar. In this filebrowser you can upload non-image files.
    # Inserting these files into your editor will result in a direct (A) link.
    #
    # Default:
    config.allow_document_uploads = true

    # == Set allowed filetypes for non-image files
    #
    # If you want, you can restrict the types of documents that users can upload.
    # Default behavior is to allow any kind of file to be uploaded. You can set
    # the accepted types by providing an array of mimetypes to check against.
    # Note that for this to have any effect, you first need to enable document
    # uploads using the setting above.
    #
    # Default, allow any file to be uploaded:
    # config.allowed_document_types = :all
    #
    # Example, only allow PDF uploads:
    config.allowed_document_types = %w[
      text/plain
      application/pdf
      application/msword
      application/vnd.openxmlformats-officedocument.wordprocessingml.document
      image/jpeg
      image/png
      image/gif
    ]

    # == Asset insertion
    #
    # Set this to true to keep the filebrowser open after inserting an asset.
    # Also configurable per-use from within the filebrowser.
    #
    # Default:
    # config.insert_many = false

    # == User Authentication
    #
    # When defined, Rich will automatically call this method
    # in a before filter to ensure that the user is logged in.
    #
    # If you do not change this value from the default, anyone
    # will be able to see your images, and upload files.
    #
    # Example for Devise with an AdminUser model:
    config.authentication_method = :authenticate_admin_user!
    #
    # Default (NOT recommended in production environments):
    # config.authentication_method = :none

    # == Pagination
    #
    # By default, file picker loads up assets in blocks of 34.
    #
    # Default:
    # config.paginates_per = 34
  end

  Rich.insert
end