Class: GoodJob::FrontendsController

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

Overview

rubocop:disable Rails/ApplicationController

Constant Summary collapse

STATIC_ASSETS =
{
  css: {
    bootstrap: asset_path("vendor", "bootstrap", "bootstrap.min.css"),
    style: asset_path("style.css"),
  },
  js: {
    bootstrap: asset_path("vendor", "bootstrap", "bootstrap.bundle.min.js"),
    chartjs: asset_path("vendor", "chartjs", "chart.min.js"),
    es_module_shims: asset_path("vendor", "es_module_shims.js"),
    turbo: asset_path("vendor", "turbo.js"),
  },
  svg: {
    icons: asset_path("icons.svg"),
  },
}.freeze
MODULE_OVERRIDES =
{
  application: asset_path("application.js"),
  stimulus: asset_path("vendor", "stimulus.js"),
  turbo: asset_path("vendor", "turbo.js"),
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.asset_path(*path) ⇒ Object



8
9
10
# File 'app/controllers/good_job/frontends_controller.rb', line 8

def self.asset_path(*path)
  Engine.root.join("app/frontend/good_job", *path)
end

.js_modulesObject



34
35
36
37
38
39
# File 'app/controllers/good_job/frontends_controller.rb', line 34

def self.js_modules
  @_js_modules ||= asset_path("modules").children.select(&:file?).each_with_object({}) do |file, modules|
    key = File.basename(file.basename.to_s, ".js").to_sym
    modules[key] = file
  end.merge(MODULE_OVERRIDES)
end

Instance Method Details

#moduleObject

Raises:

  • (ActionController::RoutingError)


49
50
51
52
53
# File 'app/controllers/good_job/frontends_controller.rb', line 49

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

  render file: self.class.js_modules[params[:id]&.to_sym] || raise(ActionController::RoutingError, 'Not Found')
end

#staticObject



45
46
47
# File 'app/controllers/good_job/frontends_controller.rb', line 45

def static
  render file: STATIC_ASSETS.dig(params[:format]&.to_sym, params[:id]&.to_sym) || raise(ActionController::RoutingError, 'Not Found')
end