require 'rails' require 'sprockets/railtie' require 'jbuilder' require 'jquery-rails' require 'net/http/post/multipart' require 'json' module ::Scrivito class SdkEngine < Rails::Engine def self.to_prepare Scrivito::Configuration.to_prepare unless Rails.application.config.cache_classes Scrivito.models.clear_cache end end ActiveSupport::Reloader.to_prepare { SdkEngine.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| precedence_route = root.join('config', 'precedence_routes.rb').to_s app.routes_reloader.paths.unshift(precedence_route) end # Expose Scrivito SDK runtime to controller for logging. initializer "scrivito.log_runtime" do |app| Scrivito::LogSubscriber.attach_to :scrivito ActiveSupport.on_load(:action_controller) do include Scrivito::ControllerRuntime end end initializer "scrivito.routing_helpers" do ActiveSupport.on_load(:action_controller) do if Rails.env == 'test' ActionDispatch::TestRequest.__send__(:include, Scrivito::TestRequest) end include Scrivito::ControllerHelper end end initializer "scrivito.routing_extensions" do ActionDispatch::Routing::Mapper.__send__(:include, Scrivito::RoutingExtensions) end initializer 'scrivito.add_sdk_assets' do |app| # Specify which file should be precompiled for packaging app.config.assets.precompile += %w[ scrivito.js scrivito_ui_redirect.js scrivito_ui.css scrivito_ui.js scrivito_with_js_sdk.js ] app.config.assets.precompile += %w(*.png *.jpg *.jpeg *.gif) end initializer 'scrivito.add_middlewares' do |app| config.app_middleware.use Scrivito::EditingContextMiddleware config.app_middleware.use Scrivito::CacheMiddleware config.app_middleware.use Scrivito::WorkspaceSelectionMiddleware config.app_middleware.use Scrivito::DisableBrowserCacheForUiMiddleware end scrivito_path = root.join('app', 'cms').to_s config.autoload_paths += [scrivito_path, root.join('app', 'models').to_s] config.autoload_once_paths += [scrivito_path] end end