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: GoodJob::Engine.root.join("app", "frontend", "good_job", "vendor", "bootstrap", "bootstrap.min.css"),
    style: GoodJob::Engine.root.join("app", "frontend", "good_job", "style.css"),
  },
  js: {
    bootstrap: GoodJob::Engine.root.join("app", "frontend", "good_job", "vendor", "bootstrap", "bootstrap.bundle.min.js"),
    chartjs: GoodJob::Engine.root.join("app", "frontend", "good_job", "vendor", "chartjs", "chart.min.js"),
    es_module_shims: GoodJob::Engine.root.join("app", "frontend", "good_job", "vendor", "es_module_shims.js"),
    rails_ujs: GoodJob::Engine.root.join("app", "frontend", "good_job", "vendor", "rails_ujs.js"),
  },
  svg: {
    icons: GoodJob::Engine.root.join("app", "frontend", "good_job", "icons.svg"),
  },
}.freeze
MODULE_OVERRIDES =
{
  application: GoodJob::Engine.root.join("app", "frontend", "good_job", "application.js"),
  stimulus: GoodJob::Engine.root.join("app", "frontend", "good_job", "vendor", "stimulus.js"),
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.js_modulesObject



29
30
31
32
33
34
# File 'app/controllers/good_job/frontends_controller.rb', line 29

def self.js_modules
  @_js_modules ||= GoodJob::Engine.root.join("app", "frontend", "good_job", "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)


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

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



40
41
42
# File 'app/controllers/good_job/frontends_controller.rb', line 40

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