Sha256: 45ef1cb720aa6d310ba7d6c1909c3cd992a4dc52c27090570cb6e8ea2112bc90

Contents?: true

Size: 1.44 KB

Versions: 15

Compression:

Stored size: 1.44 KB

Contents

module Jets::Router::Dsl
  module Mount
    # support these notations:
    #   mount Blorgh::Engine, at: "/blog"
    #   mount sprockets_env => "/assets"
    #   mount sprockets_env => "/assets", internal: true
    def mount(*args)
      options = args.extract_options!

      if args.empty?
        mount_option = options.find { |k,v| !k.is_a?(String) && !v.is_a?(Symbol) }
        mount_class, at = mount_option[0], mount_option[1]
      else
        mount_class = args.first
        at = options[:at]
      end

      at = "/#{at}" unless at.starts_with?("/")
      mount_class_at(mount_class, options.merge(at: at))
    end

    # The mounted class must be a Rack compatiable class
    def mount_class_at(klass, options={})
      if klass.is_a?(Class) && klass < Jets::Engine
        mount_engine(klass, options)
      else
        # Handles mount like Sprockets::Environment.new
        at = options.delete(:at)
        at = at[1..-1] if at.starts_with?('/') # be more forgiving if / accidentally included
        at_wildcard = at.blank? ? "*path" : "#{at}/*path"
        options.merge!(to: "jets/mount#call", mount_class: klass)

        any at, options
        any at_wildcard, options
      end
    end

    mattr_accessor :mounted_engines
    self.mounted_engines = {}
    def mount_engine(klass, options={})
      at = options.delete(:at)
      options.merge!(engine: klass, path: at)
      create_route(options)
      @@mounted_engines[at] = klass
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
jets-5.0.13 lib/jets/router/dsl/mount.rb
jets-5.0.12 lib/jets/router/dsl/mount.rb
jets-5.0.11 lib/jets/router/dsl/mount.rb
jets-5.0.10 lib/jets/router/dsl/mount.rb
jets-5.0.9 lib/jets/router/dsl/mount.rb
jets-5.0.8 lib/jets/router/dsl/mount.rb
jets-5.0.7 lib/jets/router/dsl/mount.rb
jets-5.0.6 lib/jets/router/dsl/mount.rb
jets-5.0.5 lib/jets/router/dsl/mount.rb
jets-5.0.4 lib/jets/router/dsl/mount.rb
jets-5.0.3 lib/jets/router/dsl/mount.rb
jets-5.0.2 lib/jets/router/dsl/mount.rb
jets-5.0.1 lib/jets/router/dsl/mount.rb
jets-5.0.0 lib/jets/router/dsl/mount.rb
jets-5.0.0.beta1 lib/jets/router/dsl/mount.rb