From 230a569b778886cb9e7fc96f37a3b035050de93d Mon Sep 17 00:00:00 2001 From: Rick Barrette Date: Fri, 6 Nov 2026 21:18:23 -0500 Subject: [PATCH] Markdown notes and a phone-friendly layout - Notes render GitHub-flavored Markdown (commonmarker, sanitized), with a Write/Preview editor; overview shows a plain-text excerpt - Phone header collapses into a menu; aircraft sections use a dropdown - Tables stack into labelled cards under 640px (opt out with .table-keep) - Fix horizontal overflow on overview and logbook; bigger touch targets; 16px inputs to stop iOS zoom Co-Authored-By: Claude Opus 5.5 --- Gemfile | 1 + Gemfile.lock | 17 +++++ app/assets/tailwind/application.css | 63 +++++++++++++++++++ app/controllers/notes_controller.rb | 5 ++ app/helpers/markdown_helper.rb | 29 +++++++++ app/javascript/application.js | 18 ++++++ .../controllers/markdown_editor_controller.js | 47 ++++++++++++++ app/views/aircraft/show.html.erb | 2 +- app/views/layouts/application.html.erb | 25 +++++++- app/views/logbook_entries/index.html.erb | 4 +- app/views/notes/_form.html.erb | 15 ++++- app/views/notes/index.html.erb | 4 +- app/views/oil_analyses/index.html.erb | 2 +- app/views/shared/_aircraft_header.html.erb | 21 ++++++- app/views/shared/show.html.erb | 2 +- config/routes.rb | 4 +- test/helpers/markdown_helper_test.rb | 22 +++++++ test/integration/notes_markdown_test.rb | 39 ++++++++++++ test/integration/phone_layout_test.rb | 26 ++++++++ 19 files changed, 331 insertions(+), 15 deletions(-) create mode 100644 app/helpers/markdown_helper.rb create mode 100644 app/javascript/controllers/markdown_editor_controller.js create mode 100644 test/helpers/markdown_helper_test.rb create mode 100644 test/integration/notes_markdown_test.rb create mode 100644 test/integration/phone_layout_test.rb diff --git a/Gemfile b/Gemfile index 148e16b..e1b7c07 100644 --- a/Gemfile +++ b/Gemfile @@ -77,3 +77,4 @@ gem "webmock", "~> 3.34", group: :test gem "pdf-reader", "~> 2.16" gem "rubyzip", ">= 2.4", "< 3" # aircraft archives (.sam.zip) gem "anthropic", "~> 2.6" # AI logbook transcription (Claude) +gem "commonmarker", "~> 2.10" # Markdown in notes diff --git a/Gemfile.lock b/Gemfile.lock index ee8bf3d..a6f5366 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -112,6 +112,14 @@ GEM nokogiri (~> 1.10, >= 1.10.4) rubyzip (>= 2.4, < 4) chartkick (5.2.1) + commonmarker (2.10.1-aarch64-linux) + commonmarker (2.10.1-aarch64-linux-musl) + commonmarker (2.10.1-arm-linux-gnu) + commonmarker (2.10.1-arm-linux-musl) + commonmarker (2.10.1-arm64-darwin) + commonmarker (2.10.1-x86_64-darwin) + commonmarker (2.10.1-x86_64-linux) + commonmarker (2.10.1-x86_64-linux-musl) concurrent-ruby (1.3.8) connection_pool (3.0.2) crack (1.0.1) @@ -430,6 +438,7 @@ DEPENDENCIES capybara caxlsx (~> 4.5) chartkick (~> 5.2) + commonmarker (~> 2.10) csv (~> 3.3) debug importmap-rails @@ -486,6 +495,14 @@ CHECKSUMS capybara (3.40.0) sha256=42dba720578ea1ca65fd7a41d163dd368502c191804558f6e0f71b391054aeef caxlsx (4.5.0) sha256=e3d98d859f148df05d5462086b5079b523f29c1766b569535f1d68629ce743ff chartkick (5.2.1) sha256=2848d7de87189f30f28d077eb0bbdebc8a1f0f6f81de1ded95008fe564369949 + commonmarker (2.10.1-aarch64-linux) sha256=3ab9e7027d2350364bdc541680cc28e21011b2950abf7d08ac29093fa691bdc3 + commonmarker (2.10.1-aarch64-linux-musl) sha256=98e6d1a03ba708438d804702e3c25f3423bff21a1e9975280eb265d889677dfc + commonmarker (2.10.1-arm-linux-gnu) sha256=dc1ce6cfe5547d2814351ef306d5d1dd05f9c08ad405c76baa94748326c83b7f + commonmarker (2.10.1-arm-linux-musl) sha256=97d40662414df1e6babcd78d7fbeb0bc7a2ee6fc0d0d592f12539ef535c00c90 + commonmarker (2.10.1-arm64-darwin) sha256=f8d9842699c0b2e52d5447ed9cc426bd2803ddaa0460b0a1e1cab9371926c012 + commonmarker (2.10.1-x86_64-darwin) sha256=22ac1e26059ebf970d6029c9810d5062869b3742c1e827088f38bdb34b75812e + commonmarker (2.10.1-x86_64-linux) sha256=4b2c4b9084baca131146c92dde02bcb40ef3d2768a6772648c1970bb51842734 + commonmarker (2.10.1-x86_64-linux-musl) sha256=afa9e0dc1fef554b7779d815a574d1cb602a9ff9b548dd8be80d66ac69f83866 concurrent-ruby (1.3.8) sha256=b2f1be836e968ccc78ccfce277ea79c72a88633f22306782c16ff23fb415d1e1 connection_pool (3.0.2) sha256=33fff5ba71a12d2aa26cb72b1db8bba2a1a01823559fb01d29eb74c286e62e0a crack (1.0.1) sha256=ff4a10390cd31d66440b7524eb1841874db86201d5b70032028553130b6d4c7e diff --git a/app/assets/tailwind/application.css b/app/assets/tailwind/application.css index cc01bfc..9c3c20f 100644 --- a/app/assets/tailwind/application.css +++ b/app/assets/tailwind/application.css @@ -107,3 +107,66 @@ --color-blue-100: color-mix(in oklab, oklch(62.3% 0.214 259.815) 22%, transparent); --color-blue-700: oklch(80.9% 0.105 251.813); } + +/* Rendered Markdown (notes). Colors use the palette, so dark mode follows. */ +@layer components { + .markdown { overflow-wrap: anywhere; } + .markdown > * + * { margin-top: 0.5em; } + .markdown h1, .markdown h2, .markdown h3, .markdown h4 { font-weight: 600; color: var(--color-slate-900); line-height: 1.3; } + .markdown h1 { font-size: 1.15rem; } + .markdown h2 { font-size: 1.05rem; } + .markdown h3, .markdown h4 { font-size: 1rem; } + .markdown a { color: var(--color-sky-700); text-decoration: underline; text-underline-offset: 2px; } + .markdown ul { list-style: disc; padding-left: 1.25rem; } + .markdown ol { list-style: decimal; padding-left: 1.25rem; } + .markdown li + li { margin-top: 0.15em; } + .markdown li:has(> input[type="checkbox"]) { list-style: none; margin-left: -1.25rem; } + .markdown input[type="checkbox"] { margin-right: 0.4em; vertical-align: -1px; } + .markdown blockquote { border-left: 3px solid var(--color-slate-300); padding-left: 0.75rem; color: var(--color-slate-600); } + .markdown code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.85em; background: var(--color-slate-100); border-radius: 0.25rem; padding: 0.1em 0.3em; } + .markdown pre { background: var(--color-slate-100); border-radius: 0.375rem; padding: 0.6rem 0.75rem; overflow-x: auto; } + .markdown pre code { background: none; padding: 0; } + .markdown hr { border-color: var(--color-slate-200); } + .markdown table { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; font-size: 0.85em; } + .markdown th, .markdown td { border: 1px solid var(--color-slate-200); padding: 0.25rem 0.5rem; text-align: left; } + .markdown th { background: var(--color-slate-50); font-weight: 600; } +} + +/* ---- Phones ---------------------------------------------------------- */ +@layer base { + /* Grid columns may shrink below their content (a wide table scrolls inside + its card instead of widening the page). */ + .grid > * { min-width: 0; } +} + +/* Phones: each table row becomes a card; cells carry their column's name + (data-label, copied from the header by application.js). Tables that read + across columns (e.g. oil results by sample date) opt out with .table-keep. */ +@media (max-width: 639px) { + .table:not(.table-keep) { display: block; min-width: 0; } + .table:not(.table-keep) thead { display: none; } + .table:not(.table-keep) tbody, .table:not(.table-keep) tfoot { display: block; } + .table:not(.table-keep) tr { display: block; padding: 0.625rem 1rem; border-bottom: 1px solid var(--color-slate-100); } + .table:not(.table-keep) td { display: block; padding: 0.125rem 0 !important; border: 0; text-align: left !important; white-space: normal !important; max-width: none !important; } + .table:not(.table-keep) td:empty { display: none; } + .table:not(.table-keep) td[data-label]:not([data-label=""])::before { + content: attr(data-label) " "; + margin-right: 0.35rem; font-size: 0.7rem; font-weight: 600; letter-spacing: 0.03em; text-transform: uppercase; + color: var(--color-slate-500); + } + /* The first column names the row: show it as the card's title. */ + .table:not(.table-keep) td:first-child { font-weight: 500; } + .table:not(.table-keep) td:first-child::before { content: none !important; } + /* Buttons-only cells (Edit / Resolve…) sit at the end of the card. */ + .table:not(.table-keep) td[data-label=""]:not(:first-child) { padding-top: 0.375rem !important; } + .overflow-x-auto:has(> .table:not(.table-keep)) { overflow-x: visible; } + + /* 16px text stops iOS zooming into fields on focus. */ + .input, select.input, textarea.input { font-size: 16px; } +} + +/* Touch screens: small buttons and tabs get a finger-sized target. */ +@media (pointer: coarse) { + .btn-sm { padding: 0.4rem 0.75rem; font-size: 0.8125rem; } + .btn-primary, .btn-secondary, .btn-danger { min-height: 2.5rem; } +} diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb index 07e37d0..a02fa4b 100644 --- a/app/controllers/notes_controller.rb +++ b/app/controllers/notes_controller.rb @@ -7,6 +7,11 @@ class NotesController < ApplicationController @notes = @aircraft.notes.recent_first.includes(:user) end + # Rendered Markdown for the editor's Preview tab. + def preview + render html: helpers.markdown(params[:text].to_s.first(50_000)).presence || helpers.tag.p("Nothing to preview.", class: "hint") + end + def new @note = @aircraft.notes.new end diff --git a/app/helpers/markdown_helper.rb b/app/helpers/markdown_helper.rb new file mode 100644 index 0000000..b758b84 --- /dev/null +++ b/app/helpers/markdown_helper.rb @@ -0,0 +1,29 @@ +# GitHub-flavored Markdown for notes. Raw HTML in the source is dropped and the +# output is sanitized again, so notes (some shown on public share links) can't +# inject markup. Single line breaks are kept, so plain-text notes written +# before Markdown support look the same as before. +module MarkdownHelper + OPTIONS = { + parse: { smart: true }, + render: { hardbreaks: true, unsafe: false, escape: false }, + extension: { strikethrough: true, tagfilter: true, table: true, autolink: true, tasklist: true, header_ids: nil, footnotes: false } + }.freeze + TAGS = %w[p br strong em del a ul ol li blockquote code pre h1 h2 h3 h4 h5 h6 hr table thead tbody tr th td input span].freeze + ATTRIBUTES = %w[href title type checked disabled align class].freeze + + def markdown(text) + return "".html_safe if text.blank? + html = Commonmarker.to_html(text.to_s, options: OPTIONS, plugins: { syntax_highlighter: nil }) + html = sanitize(html, tags: TAGS, attributes: ATTRIBUTES) + # Links open in a new tab (notes often link to manuals and vendors). + html = html.gsub(/ { + tab.setAttribute("aria-selected", active) + tab.classList.toggle("bg-slate-200", active) + tab.classList.toggle("text-slate-900", active) + tab.classList.toggle("text-slate-500", !active) + }) + } +} diff --git a/app/views/aircraft/show.html.erb b/app/views/aircraft/show.html.erb index 1269752..a5815e5 100644 --- a/app/views/aircraft/show.html.erb +++ b/app/views/aircraft/show.html.erb @@ -90,7 +90,7 @@
    <% @notes.each do |note| %>
  • -
    <%= note.text.truncate(200) %>
    +
    <%= markdown_excerpt note.text %>
    <%= note.user&.display_name %> · <%= time_ago_in_words(note.created_at) %> ago <%= "· public" if note.public? %>
  • <% end %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 9122ad4..5909614 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -22,11 +22,30 @@
    - <%= link_to root_path, class: "flex items-center gap-2 font-semibold tracking-tight" do %> - ✈ Simple Aircraft Manager + <%= link_to root_path, class: "flex items-center gap-2 font-semibold tracking-tight whitespace-nowrap" do %> + ✈ SAM <% end %> <% if current_user %> -