Skip to content

Add book:generate rake task for print-ready 'Why Ruby?' PDF - #145

Merged
newstler merged 9 commits into
mainfrom
book-generate
Sep 23, 2026
Merged

newstler merged 9 commits into
mainfrom
book-generate

Conversation

@newstler

Copy link
Copy Markdown
Owner

Summary

  • New rake task book:generate — renders all published testimonials into a 176×246 mm hardcover-format single-file HTML at tmp/why_ruby_book.html, then prints it to tmp/why_ruby_book.pdf via headless Chrome (auto-detected on macOS/Linux, no Node/Puppeteer). Layout is a 1:1 port of the home carousel: red bordered quote box with a downward speech-bubble tail centered on the avatar below, gem-shaped avatars, iPad-portrait content flow. Cover shows Why / [heart icon] / Ruby? stacked vertically; back page credits rubycommunity.org. Featured order: Matz → DHH → Dave Thomas → Amanda Perino, then default; rubyon is excluded at generation time (kept in DB so the author can still edit and resubmit on the site).
  • Tightens the AI testimonial validator (Testimonial::AiValidatable) to reject profile blurbs, résumés, project lists, and off-topic pitches — the pattern that let rubyon's user-bio slip through as a "testimonial".
  • Housekeeping (separate commit): .ruby-version 4.0.1 → 4.0.3; db/schema.rb gains the rails_error_dashboard_* install tables; production_data.rake passes aliases: true to YAML.safe_load* (required by the newer Psych default). Gemfile.lock bump for brakeman 8.0.4 → 8.0.5 (pre-commit hook requires latest).

Test plan

  • bundle exec rake book:generate succeeds and produces both tmp/why_ruby_book.html and tmp/why_ruby_book.pdf.
  • Open the PDF: cover shows stacked Why / ❤️ / Ruby?; pages 3–6 are Matz → DHH → Dave Thomas → Amanda Perino in that order.
  • On testimonial pages the speech-bubble tail apex sits on the same vertical axis as the avatar center (visible on Matz's page).
  • No testimonial from rubyon appears anywhere in the book.
  • Every author has a visible name (users without a name fall back to username).
  • Back page reads rubycommunity.org.
  • Submit a bio-style "testimonial" on the site — AI validator rejects with reject_reason: "quote" and feedback that asks for a real testimonial.

Generates a 176×246mm hardcover-format HTML/PDF from all published
testimonials, laid out 1:1 with the home carousel: red bordered
quote box with a downward speech-bubble tail centered on the avatar
below, gem-shaped avatars, iPad-portrait content flow. Cover shows
"Why / [heart icon] / Ruby?" stacked vertically; back page credits
rubycommunity.org. Renders via headless Chrome (auto-detected on
macOS/Linux) — no Node/Puppeteer dependency. Featured order:
Matz → DHH → Dave Thomas → Amanda Perino, then default. Excludes
'rubyon' at generation time.

Also tightens the AI testimonial validator to reject profile blurbs,
résumés, project lists, and off-topic pitches (the pattern that let
rubyon's user-bio slip through as a "testimonial").

Gemfile.lock bump: brakeman 8.0.4 → 8.0.5 to satisfy pre-commit hook.
- .ruby-version: 4.0.1 → 4.0.3
- db/schema.rb: adds rails_error_dashboard_* tables from the gem's
  install migrations (applications, cascade_patterns, and related).
- lib/tasks/production_data.rake: pass `aliases: true` to
  YAML.safe_load* — required now that Psych flags YAML aliases by
  default; needed to load config/deploy.yml and config/database.yml.
Chrome's PDF ships embedded font subsets that Affinity Publisher
can't reconstruct on import — glyphs come in as broken shapes. Fix
this at generation time by outlining all text to curves via
Ghostscript's -dNoOutputFonts (no fonts in the file = no font
problems downstream), and while we're there, satisfy the rest of
the printshop spec:

  • RGB → CMYK via Fogra39-family output intent when the ECI
    ICC profile is under vendor/icc/, else gs's default_cmyk.icc
  • PDF/X-1a:2001 subtype with proper OutputIntent
  • /prepress preset keeps images at 300 DPI
  • Even page count (blank leaf inserted before the back cover
    when the total comes out odd)
  • Near-black body/subhead colors switched to #000 so they land
    on K100 after CMYK conversion (grays and the red heading are
    intentional and stay 4-color)

Bleeds and trim (170×240 + 3mm → 176×246 mm) were already right in
the CSS. Falls back to the raw Chrome PDF with a warning when
Ghostscript isn't installed.

Also bumps brakeman 8.0.5 → 8.0.6 to satisfy the pre-commit hook.
Fogra51 is ECI's current recommended default (models optical-brightener
paper stocks accurately, per ISO 12647-2:2013). Fogra39 stays as a
fallback for shops that still calibrate against ISO Coated v2.

Also derive the PDF/X-1a OutputConditionIdentifier and Info strings
from the actual embedded profile so metadata stays consistent (an
embedded Fogra51 profile no longer gets tagged as FOGRA39).

Drops both ECI profiles into vendor/icc/ so the pipeline is reproducible
without a manual download. Both are redistributable under their
respective ECI licenses.
The default order sorted non-featured entries in reverse creation
order, which made the back half of the book skew towards whichever
month people signed up. Shuffle them so readers get a mix instead.
Featured testimonials (Matz → DHH → Dave Thomas → Amanda Perino)
still lead the sequence in their fixed order.
GitHub's GraphQL API returns "" (not nil) for users without a bio,
so `profile_data[:bio] || user.bio` was overwriting existing bios
with empty strings. Use `.presence` to fall back on blank values
in both the OAuth and batch GraphQL sync paths.
The same model_id exists once per provider (gpt-4.1-nano is present as
both azure and openai), so `Model.find_by(model_id:)` returned whichever
row came first. When that was the unconfigured azure row, every call
raised RubyLLM::ConfigurationError at request time — silently breaking
post summaries and testimonial generation in development.

Add `Model.resolve`, which prefers a provider that is actually configured
and falls back to the plain lookup, and use it at the AI call sites.
Three published testimonials were advertising rather than saying why
their author loves Ruby: two carried links and a call to action, one was
a profile bio. The book generator had grown a hardcoded EXCLUDED_USERNAMES
entry to paper over the third.

Add Testimonial::Screenable, a deterministic check that runs as a
validation before any AI call, rejecting links, bare domains, emails,
@Handles and pitch phrasing with feedback the author sees on the form.
Checked against all 225 existing quotes it flags exactly those three and
nothing else. Behind it, the LLM validator prompt gains explicit rules
and few-shot examples in both directions, so a short but genuine quote
still gets published.

Stop truncating quotes. `maxlength: 320` on the textarea meant a longer
paste was silently cut in the browser and the server never saw the
missing words, so no validation error could fire — four stored quotes sit
at exactly 320 characters, three of them ending mid-sentence. The 140-320
range now lives only in the model, where going over is a visible error
with the text intact. System writes are exempt so a faithful translation
is never trimmed or padded to fit, and the book steps quote type down at
360/460/560 characters rather than overflowing the page.

Add Testimonial::AiTranslatable so a quote written in another language is
translated to English before the heading and body are generated from it.
The author's own words are kept in quote_original alongside quote_language;
nothing is overwritten.

Also stop the generator naming the author in the third person — eleven
bodies had drifted into "Michael's journey" and "developers like Joe"
while the other 110 stayed impersonal.

New rake tasks for running this against a live database:

  testimonials:screen                     list published quotes that trip the screen
  testimonials:reject[username,reason]    unpublish and tell the author why
  testimonials:publish[username]          undo
  testimonials:translate[username]        backfill translations, keeping originals
  testimonials:regenerate[username]       rewrite AI fields from the current quote
  testimonials:rewrite[username,quote]    replace a quote and regenerate
CARTO now requires an API key for raster basemaps. Keyless tiles still
return HTTP 200, but come back with an "API KEY REQUIRED" watermark
rendered into the PNG, which is what shows on the community map today.

Store the key as a setting rather than a credential so it can be rotated
from /madmin/settings without a deploy, and append it to the tile URL as
?key= (CARTO ignores ?api_key= silently, watermark and all).

The map degrades to the current watermarked behaviour when no key is set,
so this is safe to deploy before the key is entered.

Claude-Session: https://claude.ai/code/session_01WEn1AgMSTixg1FMwtavvpV
@newstler
newstler merged commit 5bf09c8 into main Sep 23, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant