2024-04-22 16:42:12 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class FAQController < ApplicationController
|
|
|
|
before_action :load_faq_data, only: :show
|
|
|
|
|
2024-04-22 16:44:27 +02:00
|
|
|
def index
|
|
|
|
@faqs = loader_service.all
|
|
|
|
end
|
|
|
|
|
2024-04-22 16:42:12 +02:00
|
|
|
def show
|
|
|
|
@renderer = Redcarpet::Markdown.new(
|
|
|
|
Redcarpet::BareRenderer.new(class_names_map: { list: 'fr-ol-content--override' })
|
|
|
|
)
|
2024-04-22 16:43:57 +02:00
|
|
|
|
|
|
|
@siblings = loader_service.faqs_for_category(@metadata[:category])
|
2024-04-22 16:42:12 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def loader_service
|
|
|
|
@loader_service ||= FAQsLoaderService.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def load_faq_data
|
|
|
|
path = "#{params[:category]}/#{params[:slug]}"
|
|
|
|
faq_data = loader_service.find(path)
|
|
|
|
|
|
|
|
@content = faq_data.content
|
|
|
|
@metadata = faq_data.front_matter.symbolize_keys
|
|
|
|
rescue KeyError
|
|
|
|
raise ActionController::RoutingError.new("FAQ not found: #{path}")
|
|
|
|
end
|
|
|
|
end
|