mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 23:50:36 -05:00
User guide in docs/guide, shown in the app under Help
- 16 Markdown pages covering every area for pilots, owners, mechanics and admins, readable on GitHub - /help renders them with a page list; links between pages work in both places; only listed pages can be opened - The electronic records instructions (AC 120-78B user instructions) are now the guide's records page, also used as the procedures appendix - Help link in the main menu Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
761f381679
commit
fe3fba1736
28 files changed
+599
-32
No files matched your search
@@ -0,0 +1,39 @@
|
||||
# The user guide: Markdown files in docs/guide (readable on GitHub too),
|
||||
# shown in the app under /help. Only the pages listed here can be opened.
|
||||
class HelpGuide
|
||||
DIR = Rails.root.join("docs/guide")
|
||||
ORDER = %w[README getting-started profile aircraft flights squawks oil-and-fuel components logbook records
|
||||
inspections ads documents major-records sharing administration].freeze
|
||||
OPTIONS = {
|
||||
parse: { smart: true },
|
||||
render: { hardbreaks: false, unsafe: false },
|
||||
extension: { strikethrough: true, tagfilter: true, table: true, autolink: true, header_ids: "" }
|
||||
}.freeze
|
||||
TAGS = %w[p br strong em del a ul ol li blockquote code pre h1 h2 h3 h4 hr table thead tbody tr th td].freeze
|
||||
ATTRIBUTES = %w[href id align].freeze
|
||||
|
||||
Page = Data.define(:slug, :title, :markdown)
|
||||
|
||||
def self.pages = ORDER.filter_map { find(_1) }
|
||||
|
||||
def self.find(slug)
|
||||
return unless ORDER.include?(slug.to_s)
|
||||
path = DIR.join("#{slug}.md")
|
||||
return unless path.file?
|
||||
markdown = path.read
|
||||
Page.new(slug: slug.to_s, title: markdown[/\A# (.+)$/, 1] || slug.to_s.titleize, markdown: markdown)
|
||||
end
|
||||
|
||||
# Sanitized HTML. Links to other guide pages ("records.md#mistakes") go
|
||||
# through `link` (slug, anchor) -> URL, or become plain text when nil.
|
||||
def self.html(page, link:, title: true)
|
||||
source = title ? page.markdown : page.markdown.sub(/\A# .+\n+/, "")
|
||||
html = Commonmarker.to_html(source, options: OPTIONS, plugins: { syntax_highlighter: nil })
|
||||
html = Rails::HTML5::SafeListSanitizer.new.sanitize(html, tags: TAGS, attributes: ATTRIBUTES)
|
||||
html.gsub(%r{<a href="([a-z-]+|README)\.md(?:#([a-z0-9-]+))?">(.*?)</a>}m) do
|
||||
slug, anchor, text = $1, $2, $3
|
||||
next text unless link && ORDER.include?(slug)
|
||||
%(<a href="#{ERB::Util.h(link.call(slug, anchor))}">#{text}</a>)
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user