Class: Boar::Router

Inherits:
Object
  • Object
show all
Defined in:
lib/boar/router.rb

Class Method Summary collapse

Class Method Details

.mount_downloads(router, *args) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/boar/router.rb', line 40

def self.mount_downloads(router, *args)
  options = args.extract_options!
  config = Rails.application.config.boar

  root = get_option(options, :root, config.downloads_root)
  root += "/" if root.present? && root !~ /\/$/
  route_options = get_option(options, :route_options, {}).deep_symbolize_keys

  router.scope(module: :boar) do
    yield(router, options) if block_given?
    router.match("#{root}", {controller: options.fetch(:controller, "downloads"), action: :update, via: :put, boar_options: options}.merge(route_options))
    router.match("#{root}(*path)", route_controller(options, "downloads#main").merge({via: :get, constraints: {path: /.+/}, boar_options: options}).merge(route_options))
  end
end

.mount_pages(router, *args) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/boar/router.rb', line 21

def self.mount_pages(router, *args)
  options = args.extract_options!
  config = Rails.application.config.boar

  root = get_option(options, :root, config.pages_root)
  root += "/" if root.present? && root !~ /\/$/
  locale_param = get_option(options, :locale_param, config.locale_param).to_sym
  default_locale = get_option(options, :default_locale, config.default_locale).to_sym
  locale_regexp = get_option(options, :locale_regexp, config.locale_regexp)
  route_options = get_option(options, :route_options, {}).deep_symbolize_keys

  router.scope(module: :boar) do
    router.scope("(#{locale_param.inspect})", defaults: {locale_param => default_locale}, constraints: {locale_param => locale_regexp}) do
      yield(router, options) if block_given?
      router.match("#{root}(*path)", route_controller(options, "pages#main").merge({via: :get, boar_options: options}).merge(route_options))
    end
  end
end