Module: Jets::Router::Dsl::Mount
- Included in:
- Jets::Router::Dsl
- Defined in:
- lib/jets/router/dsl/mount.rb
Instance Method Summary collapse
-
#mount(*args) ⇒ Object
support these notations: mount Blorgh::Engine, at: “/blog” mount sprockets_env => “/assets” mount sprockets_env => “/assets”, internal: true.
-
#mount_class_at(klass, options = {}) ⇒ Object
The mounted class must be a Rack compatiable class.
- #mount_engine(klass, options = {}) ⇒ Object
Instance Method Details
#mount(*args) ⇒ Object
support these notations:
mount Blorgh::Engine, at: "/blog"
mount sprockets_env => "/assets"
mount sprockets_env => "/assets", internal: true
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/jets/router/dsl/mount.rb', line 7 def mount(*args) = args. if args.empty? mount_option = .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 = [:at] end at = "/#{at}" unless at.starts_with?("/") mount_class_at(mount_class, .merge(at: at)) end |
#mount_class_at(klass, options = {}) ⇒ Object
The mounted class must be a Rack compatiable class
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/jets/router/dsl/mount.rb', line 23 def mount_class_at(klass, ={}) if klass.is_a?(Class) && klass < Jets::Engine mount_engine(klass, ) else # Handles mount like Sprockets::Environment.new at = .delete(:at) at = at[1..-1] if at.starts_with?('/') # be more forgiving if / accidentally included at_wildcard = at.blank? ? "*path" : "#{at}/*path" .merge!(to: "jets/mount#call", mount_class: klass) any at, any at_wildcard, end end |
#mount_engine(klass, options = {}) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/jets/router/dsl/mount.rb', line 40 def mount_engine(klass, ={}) at = .delete(:at) .merge!(engine: klass, path: at) create_route() @@mounted_engines[at] = klass end |