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
|
2024-03-12 16:49:49 +01:00
|
|
|
|
@renderer = Redcarpet::Markdown.new(Redcarpet::TrustedRenderer.new(view_context), autolink: true)
|
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
|
2024-04-16 12:24:39 +02:00
|
|
|
|
@loader_service ||= begin
|
|
|
|
|
substitutions = {
|
|
|
|
|
application_base_url: Current.application_base_url,
|
|
|
|
|
application_name: Current.application_name,
|
|
|
|
|
contact_email: Current.contact_email
|
2024-05-17 15:53:59 +02:00
|
|
|
|
}.merge(dynamic_substitutions)
|
2024-04-16 12:24:39 +02:00
|
|
|
|
|
|
|
|
|
FAQsLoaderService.new(substitutions)
|
|
|
|
|
end
|
2024-04-22 16:42:12 +02:00
|
|
|
|
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
|
2024-05-17 15:53:59 +02:00
|
|
|
|
|
|
|
|
|
# Hash of dynamic values used for substitutions.
|
|
|
|
|
# The values are fetched from or calculated into the Rails cache.
|
|
|
|
|
def dynamic_substitutions
|
|
|
|
|
{
|
|
|
|
|
# Example:
|
|
|
|
|
# procedures_count: Rails.cache.fetch("faq/procedures_count", expires_in: 1.day) { helpers.number_with_delimiter(Procedure.publiee.count, delimiter: ' ') },
|
|
|
|
|
}
|
|
|
|
|
end
|
2024-04-22 16:42:12 +02:00
|
|
|
|
end
|