<commit_before>require 'refinerycms-pages'
require 'rails'

module Refinery
  module Pages
    class Engine < ::Rails::Engine
      include Refinery::Engine

      isolate_namespace Refinery
      engine_name :pages

      config.to_prepare do |app|        
        Refinery::Page.translation_class.send(:is_seo_meta)
        Refinery::Page.translation_class.send(:attr_accessible, :browser_title, :meta_description, :meta_keywords, :locale)
      end

      after_inclusion do
        ::ApplicationController.send :include, Refinery::Pages::InstanceMethods
        Refinery::AdminController.send :include, Refinery::Pages::Admin::InstanceMethods
      end
      
      initializer "append marketable routes", :before => :set_routes_reloader do |app|
        if Refinery::Pages.use_marketable_urls?
          append_marketable_routes(app)
        end
      end

      initializer "register refinery_pages plugin", :after => :set_routes_reloader do |app|
        Refinery::Plugin.register do |plugin|
          plugin.pathname = root
          plugin.name = 'refinery_pages'
          plugin.directory = 'pages'
          plugin.version = %q{2.0.0}
          plugin.menu_match = /refinery\/page(_part)?s(_dialogs)?$/
          plugin.url = app.routes.url_helpers.refinery_admin_pages_path
          plugin.activity = {
            :class => Refinery::Page,
            :url_prefix => "edit",
            :title => "title",
            :created_image => "page_add.png",
            :updated_image => "page_edit.png"
          }
        end
      end
      
      initializer "add marketable route parts to reserved words" do |app|
        # $rake_assets_precompiling is a temporary hack to avoid initializing the database during
        # assets precompile for issue https://github.com/resolve/refinerycms/issues/1059
        if $rake_assets_precompiling && Refinery::Pages.use_marketable_urls?
          add_route_parts_as_reserved_words(app)
        end
      end

      config.after_initialize do
        Refinery.register_engine(Refinery::Pages)
      end

      protected

        def append_marketable_routes(app)
          app.routes.append do
            scope(:module => 'refinery') do
              get '*path', :to => 'pages#show'
            end
          end
        end

        # Add any parts of routes as reserved words.
        def add_route_parts_as_reserved_words(app)
          route_paths = app.routes.named_routes.routes.map { |name, route| route.path }
          Refinery::Page.friendly_id_config.reserved_words |= route_paths.map { |path|
            path.to_s.gsub(/^\//, '').to_s.split('(').first.to_s.split(':').first.to_s.split('/')
          }.flatten.reject { |w| w =~ /\_/ }.uniq<commit_msg>Fix incorrect logic in rake_assets_precompiling check<commit_after>require 'refinerycms-pages'
require 'rails'

module Refinery
  module Pages
    class Engine < ::Rails::Engine
      include Refinery::Engine

      isolate_namespace Refinery
      engine_name :pages

      config.to_prepare do |app|        
        Refinery::Page.translation_class.send(:is_seo_meta)
        Refinery::Page.translation_class.send(:attr_accessible, :browser_title, :meta_description, :meta_keywords, :locale)
      end

      after_inclusion do
        ::ApplicationController.send :include, Refinery::Pages::InstanceMethods
        Refinery::AdminController.send :include, Refinery::Pages::Admin::InstanceMethods
      end
      
      initializer "append marketable routes", :before => :set_routes_reloader do |app|
        if Refinery::Pages.use_marketable_urls?
          append_marketable_routes(app)
        end
      end

      initializer "register refinery_pages plugin", :after => :set_routes_reloader do |app|
        Refinery::Plugin.register do |plugin|
          plugin.pathname = root
          plugin.name = 'refinery_pages'
          plugin.directory = 'pages'
          plugin.version = %q{2.0.0}
          plugin.menu_match = /refinery\/page(_part)?s(_dialogs)?$/
          plugin.url = app.routes.url_helpers.refinery_admin_pages_path
          plugin.activity = {
            :class => Refinery::Page,
            :url_prefix => "edit",
            :title => "title",
            :created_image => "page_add.png",
            :updated_image => "page_edit.png"
          }
        end
      end
      
      initializer "add marketable route parts to reserved words" do |app|
        if Refinery::Pages.use_marketable_urls?
          # $rake_assets_precompiling is a temporary hack to avoid initializing the database during
          # assets precompile for issue https://github.com/resolve/refinerycms/issues/1059
          add_route_parts_as_reserved_words(app) unless $rake_assets_precompiling
        end
      end

      config.after_initialize do
        Refinery.register_engine(Refinery::Pages)
      end

      protected

        def append_marketable_routes(app)
          app.routes.append do
            scope(:module => 'refinery') do
              get '*path', :to => 'pages#show'
            end
          end
        end

        # Add any parts of routes as reserved words.
        def add_route_parts_as_reserved_words(app)
          route_paths = app.routes.named_routes.routes.map { |name, route| route.path }
          Refinery::Page.friendly_id_config.reserved_words |= route_paths.map { |path|
            path.to_s.gsub(/^\//, '').to_s.split('(').first.to_s.split(':').first.to_s.split('/')
          }.flatten.reject { |w| w =~ /\_/ }.uniq
{'fraction_non_alphanumeric': 0.10309653916211294, 'fraction_numerical': 0.0025500910746812386, 'mean_word_length': 2.457808564231738, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4534692', 'n_tokens_mistral': 1609, 'n_tokens_neox': 1588, 'n_words': 325}