<commit_before>
module Rich
  module Cms
    module Engine
      
      class RichCmsError < StandardError
      end
      
      extend self
      
      attr_reader :authentication, :editable_content
  
      def init
        @authentication   = AuthenticationSpecs.new
        @editable_content = {}
        
        %w(controllers).each do |dir|
          path = File.join File.dirname(__FILE__), "..", "..", "app", dir
          $LOAD_PATH << path
          ActiveSupport::Dependencies.load_paths << path
          ActiveSupport::Dependencies.load_once_paths.delete path
        end
        
        ::Jzip::Engine.add_template_location({File.join(File.dirname(__FILE__), "..", "..", "assets", "jzip") => File.join(RAILS_ROOT, "public", "javascripts")})
        ::Sass::Plugin.add_template_location( File.join(File.dirname(__FILE__), "..", "..", "assets", "sass"),   File.join(RAILS_ROOT, "public", "stylesheets") )
        
        copy_assets
      end
    
      def copy_assets
        return if RAILS_ENV == "test"
        
        source_dir = File.join File.dirname(__FILE__), "..", "..", "assets", "images", "."
        target_dir = File.join RAILS_ROOT, "public", "images", "rich", "cms"
        
        FileUtils.rm_r    target_dir if File.exists? target_dir
        FileUtils.mkdir_p target_dir
        FileUtils.cp_r    source_dir, target_dir
      end
      
      def current_controller=(current_controller)
        @current_controller  = current_controller
        @can_render_metadata = nil
      end
      
      def authenticate(logic, specs)
        @authentication = AuthenticationSpecs.new(logic, specs)
      end
      
      def register(*args)
        (editables = args.first.is_a?(Hash) ? args.first : Hash[*args]).each do |selector, specs|
          if @editable_content.keys.include?(selector)
            raise RichCmsError, "Already registered editable content identified with #{selector.inspect}"
          else
            @editable_content[selector] = Cms::Content::Group.build(selector, specs)
          end
        end
      end
      
      def to_content_tag(selector, identifiers, options = {})
        editable_content[selector].fetch(identifiers).to_tag options
      end
      
      def editable_content_javascript_hash
        "{#{@editable_content.collect{|k, v| v.to_javascript_hash}.join ", "}}"
      end
      
      def can_render_metadata?
        if @can_render_metadata.nil?
          @can_render_metadata = case authentication.logic
                                 when :authlogic
                                   @current_controller.try :current_rich_cms_admin
                                 when nil
                                   true
                                 end
        else
          @can_render_metadata
        end
      end
      
    private
    
      AuthenticationSpecs = Struct.new(:logic, :specs)
      
    end
  end
end

Rich::Cms::Engine.init<commit_msg>Fix deprecation warnings for loading paths.<commit_after>
module Rich
  module Cms
    module Engine

      class RichCmsError < StandardError
      end

      extend self

      attr_reader :authentication, :editable_content

      def init
        @authentication   = AuthenticationSpecs.new
        @editable_content = {}

        %w(controllers).each do |dir|
          path = File.join File.dirname(__FILE__), "..", "..", "app", dir
          $LOAD_PATH << path
          ActiveSupport::Dependencies.autoload_paths << path
          ActiveSupport::Dependencies.autoload_once_paths.delete path
        end

        ::Jzip::Engine.add_template_location({File.join(File.dirname(__FILE__), "..", "..", "assets", "jzip") => File.join(RAILS_ROOT, "public", "javascripts")})
        ::Sass::Plugin.add_template_location( File.join(File.dirname(__FILE__), "..", "..", "assets", "sass"),   File.join(RAILS_ROOT, "public", "stylesheets") )

        copy_assets
      end

      def copy_assets
        return if RAILS_ENV == "test"

        source_dir = File.join File.dirname(__FILE__), "..", "..", "assets", "images", "."
        target_dir = File.join RAILS_ROOT, "public", "images", "rich", "cms"

        FileUtils.rm_r    target_dir if File.exists? target_dir
        FileUtils.mkdir_p target_dir
        FileUtils.cp_r    source_dir, target_dir
      end

      def current_controller=(current_controller)
        @current_controller  = current_controller
        @can_render_metadata = nil
      end

      def authenticate(logic, specs)
        @authentication = AuthenticationSpecs.new(logic, specs)
      end

      def register(*args)
        (editables = args.first.is_a?(Hash) ? args.first : Hash[*args]).each do |selector, specs|
          if @editable_content.keys.include?(selector)
            raise RichCmsError, "Already registered editable content identified with #{selector.inspect}"
          else
            @editable_content[selector] = Cms::Content::Group.build(selector, specs)
          end
        end
      end

      def to_content_tag(selector, identifiers, options = {})
        editable_content[selector].fetch(identifiers).to_tag options
      end

      def editable_content_javascript_hash
        "{#{@editable_content.collect{|k, v| v.to_javascript_hash}.join ", "}}"
      end

      def can_render_metadata?
        if @can_render_metadata.nil?
          @can_render_metadata = case authentication.logic
                                 when :authlogic
                                   @current_controller.try :current_rich_cms_admin
                                 when nil
                                   true
                                 end
        else
          @can_render_metadata
        end
      end

    private

      AuthenticationSpecs = Struct.new(:logic, :specs)

    end
  end
end

Rich::Cms::Engine.init
{'fraction_non_alphanumeric': 0.10299174690508942, 'fraction_numerical': 0.0, 'mean_word_length': 2.0503408495018354, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '774247', 'n_tokens_mistral': 1679, 'n_tokens_neox': 1604, 'n_words': 326}