Sha256: d46e44680a5d695b0e81e42885fec38bba59e9630453dfca9efa5a653cdaa0a7

Contents?: true

Size: 1.46 KB

Versions: 3

Compression:

Stored size: 1.46 KB

Contents

require 'browsercms'

module BcmsKcfinder
  class Engine < ::Rails::Engine
    isolate_namespace BcmsKcfinder
    include Cms::Module


    config.to_prepare do
      Cms::Section.send(:include, BcmsKcfinder::FinderExtension)
      Cms::Attachment.send(:include, BcmsKcfinder::Attachment::Linkable)
      Cms::Page.send(:include, BcmsKcfinder::Page::Linkable)
      Cms::ImageBlock.send(:include, BcmsKcfinder::Image::Linkable)

    end

    initializer 'bcms_kcfinder.enable' do |app|
       app.config.cms.ckeditor.configuration_file = "bcms_kcfinder/config"
    end
  end
end

# Decorate core CMS classes so they all response to same methods for generating JSON API.
module BcmsKcfinder
  module Page
    module Linkable
      def link_to_path
        path
      end

      def size_in_bytes
        0
      end
    end
  end
  module Image
    module Linkable
      def link_to_path
        path
      end

      def size_in_bytes
        file.size
      end
    end
  end
  module Attachment
    module Linkable
      def name
        self.data_file_name
      end

      def size_in_bytes
        data_file_size
      end

      def link_to_path
        url
      end

    end
  end
  module FinderExtension
    LINKABLE_TYPES = ["Cms::Page", "Cms::Attachment"]

    def linkable_children
      child_pages = self.node.children.collect do |section_node|
        section_node.node if LINKABLE_TYPES.include?(section_node.node_type)
      end
      child_pages.compact
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
bcms_kcfinder-1.0.2 lib/bcms_kcfinder/engine.rb
bcms_kcfinder-1.0.1 lib/bcms_kcfinder/engine.rb
bcms_kcfinder-1.0.0 lib/bcms_kcfinder/engine.rb