feat: show a simple FAQ
This commit is contained in:
parent
66b4a1f8b8
commit
9af2c4f244
7 changed files with 94 additions and 0 deletions
27
app/controllers/faq_controller.rb
Normal file
27
app/controllers/faq_controller.rb
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class FAQController < ApplicationController
|
||||||
|
before_action :load_faq_data, only: :show
|
||||||
|
|
||||||
|
def show
|
||||||
|
@renderer = Redcarpet::Markdown.new(
|
||||||
|
Redcarpet::BareRenderer.new(class_names_map: { list: 'fr-ol-content--override' })
|
||||||
|
)
|
||||||
|
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
|
32
app/services/faqs_loader_service.rb
Normal file
32
app/services/faqs_loader_service.rb
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class FAQsLoaderService
|
||||||
|
PATH = Rails.root.join('doc', 'faqs').freeze
|
||||||
|
ORDER = ['usager', 'instructeur', 'administrateur'].freeze
|
||||||
|
|
||||||
|
def initialize
|
||||||
|
@faqs_by_path ||= Rails.cache.fetch("faqs_data", expires_in: 1.day) do
|
||||||
|
load_faqs
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def find(path)
|
||||||
|
file_path = @faqs_by_path.fetch(path).fetch(:file_path)
|
||||||
|
|
||||||
|
FrontMatterParser::Parser.parse_file(file_path)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def load_faqs
|
||||||
|
Dir.glob("#{PATH}/**/*.md").each_with_object({}) do |file_path, faqs_by_path|
|
||||||
|
parsed = FrontMatterParser::Parser.parse_file(file_path)
|
||||||
|
front_matter = parsed.front_matter.symbolize_keys
|
||||||
|
|
||||||
|
faq_data = front_matter.slice(:slug, :title, :category, :subcategory, :locale, :keywords).merge(file_path: file_path)
|
||||||
|
|
||||||
|
path = front_matter.fetch(:category) + '/' + front_matter.fetch(:slug)
|
||||||
|
faqs_by_path[path] = faq_data
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
6
app/views/faq/show.html.haml
Normal file
6
app/views/faq/show.html.haml
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
- content_for(:title, @metadata[:title])
|
||||||
|
|
||||||
|
.fr-container.fr-my-4w
|
||||||
|
.fr-grid-row
|
||||||
|
.fr-col-12.fr-col-md-8.fr-py-12v
|
||||||
|
= @renderer.render(@content).html_safe
|
|
@ -18,6 +18,8 @@ ActiveSupport::Inflector.inflections(:en) do |inflect|
|
||||||
inflect.acronym 'URL'
|
inflect.acronym 'URL'
|
||||||
inflect.acronym 'SVA'
|
inflect.acronym 'SVA'
|
||||||
inflect.acronym 'SVR'
|
inflect.acronym 'SVR'
|
||||||
|
inflect.acronym 'FAQ'
|
||||||
|
inflect.acronym 'FAQs'
|
||||||
inflect.irregular 'type_de_champ', 'types_de_champ'
|
inflect.irregular 'type_de_champ', 'types_de_champ'
|
||||||
inflect.irregular 'type_de_champ_private', 'types_de_champ_private'
|
inflect.irregular 'type_de_champ_private', 'types_de_champ_private'
|
||||||
inflect.irregular 'procedure_revision_type_de_champ', 'procedure_revision_types_de_champ'
|
inflect.irregular 'procedure_revision_type_de_champ', 'procedure_revision_types_de_champ'
|
||||||
|
|
9
config/locales/faqs.fr.yml
Normal file
9
config/locales/faqs.fr.yml
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
fr:
|
||||||
|
faq:
|
||||||
|
administrateur:
|
||||||
|
name: Administrateur (création d’un formulaire)
|
||||||
|
description: Informations pour les administrateurs sur la configuration de la plateforme ou la création de démarches.
|
||||||
|
subcategories:
|
||||||
|
create_procedure:
|
||||||
|
name: Je veux créer une démarche en ligne
|
||||||
|
description: Comment créer une nouvelle démarche ?
|
|
@ -715,6 +715,8 @@ Rails.application.routes.draw do
|
||||||
|
|
||||||
resources :release_notes, only: [:index]
|
resources :release_notes, only: [:index]
|
||||||
|
|
||||||
|
get '/faq/:category/:slug', to: 'faq#show', as: :faq
|
||||||
|
|
||||||
get '/404', to: 'errors#not_found'
|
get '/404', to: 'errors#not_found'
|
||||||
get '/422', to: 'errors#unprocessable_entity'
|
get '/422', to: 'errors#unprocessable_entity'
|
||||||
get '/500', to: 'errors#internal_server_error'
|
get '/500', to: 'errors#internal_server_error'
|
||||||
|
|
16
doc/faqs/administrateur/comment-creer-ma-demarche.fr.md
Normal file
16
doc/faqs/administrateur/comment-creer-ma-demarche.fr.md
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
---
|
||||||
|
category: "administrateur"
|
||||||
|
subcategory: "create_procedure"
|
||||||
|
slug: "comment-creer-ma-demarche"
|
||||||
|
locale: "fr"
|
||||||
|
keywords: "création démarche, tutoriel, guide bonnes pratiques, administrateur"
|
||||||
|
title: "Comment créer ma démarche ?"
|
||||||
|
---
|
||||||
|
|
||||||
|
# Comment créer ma démarche ?
|
||||||
|
|
||||||
|
Envie de vous lancer dans l’aventure ? Bravo ! Pour vous accompagner tout au long de la création de votre démarche, nous avons préparé un petit tutoriel spécialement pour vous :
|
||||||
|
|
||||||
|
[Tutoriel Administrateur](https://doc.demarches-simplifiees.fr/tutoriels/tutoriel-administrateur)
|
||||||
|
|
||||||
|
Pour compléter cette prise en main de l’outil, n’hésitez pas à consulter [notre guide de bonnes pratiques](https://456404736-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-L7_aKvpAJdAIEfxHudA%2Fuploads%2FGJm7S7LVjHPKVlMCE36e%2FGuide%20des%20bonnes%20pratiques%20démarches-simplifiees.pdf?alt=media&token=228e63c7-a168-4656-9cda-3f53a10645c2).
|
Loading…
Add table
Reference in a new issue