require "rails" require "action_view" require "active_model" require 'jquery-rails' require 'scrivito/configuration' module ::Scrivito class Engine < Rails::Engine config.to_prepare { Scrivito::Configuration.to_prepare } # make sure our exceptions cause an adequate error page and http status code config.action_dispatch.rescue_responses.merge!("Scrivito::ResourceNotFound" => :not_found) initializer "scrivito.add_cms_routing_paths", :after => :add_routing_paths do |app| cms_route = File.expand_path("cms_routes.rb", paths['config'].to_a.first) app.routes_reloader.paths.push(cms_route) end # Expose Scrivito SDK runtime to controller for logging. initializer "scrivito.log_runtime" do |app| runtime = begin Scrivito::ControllerRuntime rescue NameError nil end if runtime Scrivito::LogSubscriber.attach_to :scrivito ActiveSupport.on_load(:action_controller) do include runtime end end end initializer "scrivito.configure_database", :before => :load_config_initializers do |app| Scrivito::Configuration.configure_cms_database end initializer "scrivito.routing_helpers" do if Rails.env == 'test' ActionDispatch::TestRequest.__send__(:include, Scrivito::CmsTestRequest) end ActionController::Base.__send__(:include, CmsRoutingHelper) ActionView::Base.__send__(:include, CmsRoutingHelper) end initializer "scrivito.add_assets" do |app| # Specify which file should be precompiled for packaging app.config.assets.precompile += %w( scrivito_editing.js scrivito_editing.css scrivito.css ) app.config.assets.precompile += %w(*.png *.jpg *.jpeg *.gif) end config.autoload_paths += paths['lib'].to_a config.autoload_once_paths += paths['lib'].to_a config.app_middleware.use "Scrivito::EditingContextMiddleware" config.app_middleware.use "Scrivito::CacheMiddleware" config.app_middleware.use "Scrivito::WorkspaceSelectionMiddleware" end end