Class: Pgbus::FrontendsController

Inherits:
ActionController::Base
  • Object
show all
Defined in:
app/controllers/pgbus/frontends_controller.rb

Constant Summary collapse

FRONTEND_ROOT =
Engine.root.join("app", "frontend", "pgbus")
STATIC_ASSETS =
{
  css: {
    style: FRONTEND_ROOT.join("style.css")
  },
  js: {
    apexcharts: FRONTEND_ROOT.join("vendor", "apexcharts.js")
  }
}.freeze
MODULE_OVERRIDES =
{
  application: FRONTEND_ROOT.join("application.js"),
  turbo: FRONTEND_ROOT.join("vendor", "turbo.js")
}.freeze
CURRENT_VERSION =
Pgbus::VERSION.tr(".", "-").freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.js_modulesObject



24
25
26
27
28
# File 'app/controllers/pgbus/frontends_controller.rb', line 24

def self.js_modules
  @js_modules ||= FRONTEND_ROOT.join("modules").children.select(&:file?)
                               .to_h { |f| [File.basename(f.basename.to_s, ".js").to_sym, f] }
                               .merge(MODULE_OVERRIDES)
end

Instance Method Details

#moduleObject

Raises:

  • (ActionController::RoutingError)


46
47
48
49
50
51
52
53
54
# File 'app/controllers/pgbus/frontends_controller.rb', line 46

def module
  validate_version!
  raise ActionController::RoutingError, "Not Found" if params[:format] != "js"

  file = self.class.js_modules[params[:id]&.to_sym]
  raise ActionController::RoutingError, "Not Found" unless file&.exist?

  render file: file
end

#staticObject

Raises:

  • (ActionController::RoutingError)


38
39
40
41
42
43
44
# File 'app/controllers/pgbus/frontends_controller.rb', line 38

def static
  validate_version!
  file = STATIC_ASSETS.dig(params[:format]&.to_sym, params[:id]&.to_sym)
  raise ActionController::RoutingError, "Not Found" unless file&.exist?

  render file: file
end