require 'refinerycms-base' require 'moxify/version' module Moxify class Engine < Rails::Engine initializer "static assets" do |app| app.middleware.insert_after ::ActionDispatch::Static, ::ActionDispatch::Static, "#{root}/public" end initializer "require dragonfly hook" do |app| require 'moxify/dragonfly_quality_hook' end config.after_initialize do ::Refinery::Plugin.register do |plugin| plugin.name ="moxification" plugin.version = Moxify::VERSION plugin.hide_from_menu = true plugin.always_allow_access = true end end # override refinery routes to use admin namespace initializer "moxify.override_routing", :after => :disable_dependency_loading do |app| # override routes collected_routes = [] Rails.application.routes.routes.each do |route| if route.path =~ /refinery/ and not route.path =~ /^\/refinery\(\/\*path\)/ # this is our catch all route route.instance_variable_set "@path", route.path.gsub(/refinery/, "admin") # make sure we generate new path_info for changed paths conditions = route.conditions conditions[:path_info] = ::Rack::Mount::Strexp.compile(route.path, route.requirements, ::ActionDispatch::Routing::SEPARATORS, true) # overwrite conditions with new path_info route.instance_variable_set "@conditions", conditions end # add every route to our collection collected_routes << route end # clear set _routes = Rails.application.routes _routes.clear! _routes.disable_clear_and_finalize = false # now put our collected routes in for route in collected_routes _routes.add_route(route.app, route.conditions, route.requirements, route.defaults, route.name) end # finalize _routes.finalize! end end end