Sha256: 87f172da00795a3e1208526fee082339e79f29546ca6473de60d2a133ff500b4

Contents?: true

Size: 1.26 KB

Versions: 11

Compression:

Stored size: 1.26 KB

Contents

module Para
  module Component
    module BaseDecorator
      include Rails.application.routes.mounted_helpers
      include ActionDispatch::Routing::PolymorphicRoutes

      def path(namespace: nil, **options)
        find_path([:admin, self, namespace].compact, options)
      end

      def relation_path(controller_or_resource, options = {})
        if controller_or_resource.is_a?(Hash)
          options = controller_or_resource
          controller_or_resource = nil
        end

        components = [:admin, self, controller_or_resource].compact

        find_path(components, options)
      end

      def page_container_class
        'col-xs-12'
      end

      private

      # Try to find a polymorphic path for the given arguments
      #
      # If no route exist, we try all the existing engines too
      # This is quite dirty but for now should work as desired
      # The only problem is if we have engines that declare the same routes
      #
      def find_path(path, options)
        safe_polymorphic_path(path, options).tap do |result|
          raise result if result.is_a?(Exception)
        end
      end

      def safe_polymorphic_path(path, options)
        polymorphic_path(path, options)
      rescue => exception
        exception
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
para-0.8.0 app/decorators/para/component/base_decorator.rb
para-0.7.4.p1 app/decorators/para/component/base_decorator.rb
para-0.7.4 app/decorators/para/component/base_decorator.rb
para-0.7.3.p6 app/decorators/para/component/base_decorator.rb
para-0.7.3.p5 app/decorators/para/component/base_decorator.rb
para-0.7.3.p4 app/decorators/para/component/base_decorator.rb
para-0.7.3.p3 app/decorators/para/component/base_decorator.rb
para-0.7.3.p2 app/decorators/para/component/base_decorator.rb
para-0.7.3.p1 app/decorators/para/component/base_decorator.rb
para-0.7.3 app/decorators/para/component/base_decorator.rb
para-0.7.2 app/decorators/para/component/base_decorator.rb