From 2dad673ef159c83617a78f66014a9ce9b1c79908 Mon Sep 17 00:00:00 2001
From: Yuri Sidorov <403994+newstler@users.noreply.github.com>
Date: Tue, 11 Aug 2026 18:40:03 +0200
Subject: [PATCH 1/9] Add book:generate rake task for print-ready 'Why Ruby?'
PDF
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
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.
---
Gemfile.lock | 4 +-
.../concerns/testimonial/ai_validatable.rb | 8 +-
lib/tasks/book.rake | 507 ++++++++++++++++++
3 files changed, 516 insertions(+), 3 deletions(-)
create mode 100644 lib/tasks/book.rake
diff --git a/Gemfile.lock b/Gemfile.lock
index 298bbd1..8fe8e68 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -115,7 +115,7 @@ GEM
bindex (0.8.1)
bootsnap (1.23.0)
msgpack (~> 1.2)
- brakeman (8.0.4)
+ brakeman (8.0.5)
racc
builder (3.3.0)
capybara (3.40.0)
@@ -658,7 +658,7 @@ CHECKSUMS
bigdecimal (4.1.1) sha256=1c09efab961da45203c8316b0cdaec0ff391dfadb952dd459584b63ebf8054ca
bindex (0.8.1) sha256=7b1ecc9dc539ed8bccfc8cb4d2732046227b09d6f37582ff12e50a5047ceb17e
bootsnap (1.23.0) sha256=c1254f458d58558b58be0f8eb8f6eec2821456785b7cdd1e16248e2020d3f214
- brakeman (8.0.4) sha256=7bf921fa9638544835df9aa7b3e720a9a72c0267f34f92135955edd80d4dcf6f
+ brakeman (8.0.5) sha256=03735f9690d3fd4b32d66aacbf0a6d15a84266bdd06b32c05c8ecc8f6021d2be
builder (3.3.0) sha256=497918d2f9dca528fdca4b88d84e4ef4387256d984b8154e9d5d3fe5a9c8835f
capybara (3.40.0) sha256=42dba720578ea1ca65fd7a41d163dd368502c191804558f6e0f71b391054aeef
concurrent-ruby (1.3.6) sha256=6b56837e1e7e5292f9864f34b69c5a2cbc75c0cf5338f1ce9903d10fa762d5ab
diff --git a/app/models/concerns/testimonial/ai_validatable.rb b/app/models/concerns/testimonial/ai_validatable.rb
index 9556db0..014a32e 100644
--- a/app/models/concerns/testimonial/ai_validatable.rb
+++ b/app/models/concerns/testimonial/ai_validatable.rb
@@ -63,7 +63,13 @@ def build_validation_prompt(existing_testimonials)
- Hate speech, slurs, personal attacks, or targeted insults toward individuals or groups are NEVER allowed.
- Casual expletives used positively (e.g., "Damn, Ruby is amazing!" or "Fuck, I love this language!") are ALLOWED.
- The key distinction: profanity expressing enthusiasm = OK. Profanity attacking or demeaning people/groups = NOT OK.
- - The quote MUST express genuine love or appreciation for Ruby. This is an advocacy site — negative, dismissive, sarcastic, or trolling sentiments about Ruby are NOT allowed.
+ - The quote MUST express genuine love or appreciation for Ruby (or Ruby's ecosystem, community, tooling, or the developer experience it enables). This is an advocacy site — negative, dismissive, sarcastic, or trolling sentiments about Ruby are NOT allowed.
+ - The quote MUST be a first-person testimonial ABOUT Ruby. It is NOT a place for:
+ * user bios, résumés, or "about me" text (e.g., "Rails developer from South Korea, RFID specialist")
+ * lists of the user's projects, employers, job titles, contact info, links, or credentials
+ * generic descriptions of what Ruby is used for, with no personal sentiment attached
+ * off-topic content (other languages, unrelated announcements, self-promotion)
+ If the quote reads like a profile blurb, CV bullet, or product pitch rather than "here is why I love Ruby", reject it with reject_reason "quote".
VALIDATION RULES:
1. First check the user's QUOTE against the content policy. If it violates (including being negative about Ruby), reject immediately with reject_reason "quote".
diff --git a/lib/tasks/book.rake b/lib/tasks/book.rake
new file mode 100644
index 0000000..a4e9564
--- /dev/null
+++ b/lib/tasks/book.rake
@@ -0,0 +1,507 @@
+# frozen_string_literal: true
+
+require "base64"
+
+namespace :book do
+ # Featured testimonials appear first, in this order. Everything else follows in default order.
+ FEATURED_USERNAMES = %w[matz dhh pragdave AmandaPerino].freeze
+
+ # Usernames whose testimonials should be excluded from the book output.
+ # Kept here (rather than unpublished in the DB) so authors can still edit/resubmit on the site.
+ EXCLUDED_USERNAMES = %w[rubyon].freeze
+
+ desc "Generate 'Why Ruby?' book as a single HTML file, then render to PDF via headless Chrome"
+ task generate: :environment do
+ testimonials = ordered_testimonials_for_book
+
+ if testimonials.empty?
+ puts "No published testimonials found. Nothing to generate."
+ exit 0
+ end
+
+ html = build_book_html(testimonials)
+ html_path = Rails.root.join("tmp", "why_ruby_book.html")
+ File.write(html_path, html)
+
+ puts "Generated book with #{testimonials.size} testimonials"
+ puts "HTML: #{html_path}"
+
+ pdf_path = Rails.root.join("tmp", "why_ruby_book.pdf")
+ render_book_pdf(html_path, pdf_path)
+ end
+
+ private
+
+ def ordered_testimonials_for_book
+ all = Testimonial.published.ordered.includes(:user).to_a
+ all.reject! { |t| EXCLUDED_USERNAMES.include?(t.user.username) }
+ featured_by_username = all.each_with_object({}) do |t, acc|
+ acc[t.user.username] = t if FEATURED_USERNAMES.include?(t.user.username)
+ end
+ featured = FEATURED_USERNAMES.map { |u| featured_by_username[u] }.compact
+ rest = all - featured
+ featured + rest
+ end
+
+ def render_book_pdf(html_path, pdf_path)
+ chrome = detect_chrome_binary
+ unless chrome
+ puts "Chrome/Chromium not found — skipping PDF step."
+ puts "Install Chrome, or open the HTML in your browser and use File → Print → Save as PDF."
+ return
+ end
+
+ ok = system(
+ chrome,
+ "--headless=new",
+ "--disable-gpu",
+ "--no-sandbox",
+ "--no-pdf-header-footer",
+ "--print-to-pdf-no-header",
+ "--print-to-pdf=#{pdf_path}",
+ "file://#{html_path}"
+ )
+
+ if ok && File.exist?(pdf_path)
+ puts "PDF: #{pdf_path}"
+ else
+ puts "PDF generation failed. Try opening the HTML in Chrome and printing manually."
+ end
+ end
+
+ def detect_chrome_binary
+ [
+ "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
+ "/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary",
+ "/Applications/Chromium.app/Contents/MacOS/Chromium",
+ "/opt/homebrew/bin/chromium",
+ "/usr/bin/google-chrome",
+ "/usr/bin/chromium",
+ "/usr/bin/chromium-browser"
+ ].find { |path| File.executable?(path) }
+ end
+
+ def build_book_html(testimonials)
+ <<~HTML
+
+
+
+
+
+ Why Ruby?
+
+
+
+
+
+
+ #{title_page}
+ #{colophon_page}
+ #{testimonials.map { |t| testimonial_page(t) }.join("\n")}
+ #{back_page}
+
+
+ HTML
+ end
+
+ def book_css
+ <<~CSS
+ @page {
+ size: 176mm 246mm;
+ margin: 0;
+ }
+
+ *, *::before, *::after {
+ box-sizing: border-box;
+ margin: 0;
+ padding: 0;
+ }
+
+ html, body {
+ margin: 0;
+ padding: 0;
+ background: #fff;
+ -webkit-print-color-adjust: exact;
+ print-color-adjust: exact;
+ }
+
+ body {
+ font-family: "Inter", system-ui, -apple-system, sans-serif;
+ color: #111827;
+ line-height: 1.5;
+ }
+
+ .page {
+ width: 176mm;
+ height: 246mm;
+ padding: 20mm 18mm;
+ position: relative;
+ overflow: hidden;
+ page-break-after: always;
+ display: flex;
+ flex-direction: column;
+ }
+
+ .page:last-child {
+ page-break-after: auto;
+ }
+
+ /* ── Title page ── */
+
+ .title-page {
+ justify-content: center;
+ align-items: center;
+ text-align: center;
+ }
+
+ .title-page__logo {
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ justify-content: center;
+ gap: 8mm;
+ font-weight: 900;
+ font-size: 84pt;
+ color: #dc2626;
+ line-height: 1;
+ letter-spacing: -0.02em;
+ }
+
+ .title-page__logo-icon {
+ width: 44mm;
+ height: 44mm;
+ object-fit: contain;
+ }
+
+ /* ── Colophon page ── */
+
+ .colophon-page {
+ justify-content: flex-end;
+ align-items: center;
+ text-align: center;
+ }
+
+ .colophon-page__text {
+ font-size: 8.5pt;
+ color: #9ca3af;
+ letter-spacing: 0.04em;
+ padding-bottom: 4mm;
+ }
+
+ /* ── Back page ── */
+
+ .back-page {
+ justify-content: center;
+ align-items: center;
+ text-align: center;
+ }
+
+ .back-page__heart {
+ font-size: 14pt;
+ color: #6b7280;
+ line-height: 1.8;
+ }
+
+ .back-page__url {
+ font-size: 9pt;
+ color: #9ca3af;
+ letter-spacing: 0.08em;
+ margin-top: 8mm;
+ }
+
+ /* ── Testimonial page (1:1 home-carousel layout, centered on page) ── */
+
+ .testimonial-page {
+ justify-content: center;
+ align-items: stretch;
+ }
+
+ .testimonial-inner {
+ display: flex;
+ flex-direction: column;
+ }
+
+ .testimonial__heading {
+ font-family: Georgia, "Times New Roman", serif;
+ font-style: italic;
+ font-size: 46pt;
+ color: #dc2626;
+ line-height: 1.05;
+ letter-spacing: -0.02em;
+ margin-bottom: 6mm;
+ }
+
+ .testimonial__subheading {
+ font-size: 18pt;
+ font-weight: 700;
+ color: #111827;
+ line-height: 1.3;
+ margin-bottom: 3mm;
+ }
+
+ .testimonial__body {
+ font-size: 11pt;
+ color: #6b7280;
+ line-height: 1.7;
+ margin-top: 5mm;
+ margin-bottom: 12mm;
+ }
+
+ /* Red bordered quote box + red opening " overhanging top-left + downward tail. */
+ .quote-block {
+ position: relative;
+ padding-top: 3mm;
+ }
+
+ .quote-block__mark {
+ position: absolute;
+ top: -6mm;
+ left: -3mm;
+ font-family: Georgia, "Times New Roman", serif;
+ font-size: 60pt;
+ color: #dc2626;
+ line-height: 1;
+ user-select: none;
+ z-index: 2;
+ }
+
+ .quote-block__box {
+ background: #fff;
+ border: 1.5pt solid #fecaca;
+ border-radius: 3mm;
+ padding: 8mm;
+ position: relative;
+ }
+
+ .quote-block__text {
+ font-style: italic;
+ font-size: 12pt;
+ color: #4b5563;
+ line-height: 1.6;
+ }
+
+ /* Speech-bubble tail: outer red triangle + inner white triangle, pointing down toward avatar. */
+ .quote-block__box::before,
+ .quote-block__box::after {
+ content: "";
+ position: absolute;
+ width: 0;
+ height: 0;
+ }
+
+ /* Outer red tail apex is shifted 1 mm further left than the inner white,
+ so the red tail-point pokes out to the left of the white — feels more
+ "leaning toward" the avatar rather than perfectly stacked. */
+ .quote-block__box::before {
+ bottom: -5mm;
+ left: 10.2mm;
+ border-left: 4mm solid transparent;
+ border-right: 4mm solid transparent;
+ border-top: 5mm solid #fecaca;
+ }
+
+ .quote-block__box::after {
+ bottom: -4mm;
+ left: 9.5mm;
+ border-left: 5mm solid transparent;
+ border-right: 5mm solid transparent;
+ border-top: 6mm solid #fff;
+ }
+
+ /* User tile — avatar left, info right (matches _user_tile.html.erb on iPad). */
+ .user-tile {
+ display: flex;
+ align-items: center;
+ gap: 5mm;
+ margin-top: 8mm;
+ }
+
+ .user-tile__avatar-wrap {
+ width: 30mm;
+ height: 32mm;
+ position: relative;
+ flex-shrink: 0;
+ }
+
+ .user-tile__info {
+ flex: 1;
+ min-width: 0;
+ }
+
+ .user-tile__name {
+ font-size: 16pt;
+ font-weight: 700;
+ color: #111827;
+ line-height: 1.15;
+ }
+
+ .user-tile__bio {
+ font-size: 9pt;
+ color: #6b7280;
+ line-height: 1.4;
+ margin-top: 2mm;
+ }
+
+ .user-tile__meta {
+ font-size: 8pt;
+ color: #9ca3af;
+ line-height: 1.4;
+ display: flex;
+ flex-wrap: wrap;
+ gap: 3mm;
+ margin-top: 1.5mm;
+ }
+
+ .user-tile__meta-item {
+ display: inline-flex;
+ align-items: center;
+ gap: 1mm;
+ }
+
+ .user-tile__meta-icon {
+ width: 2.8mm;
+ height: 2.8mm;
+ color: #d1d5db;
+ fill: currentColor;
+ flex-shrink: 0;
+ }
+ CSS
+ end
+
+ def title_page
+ <<~HTML
+
+
+
Why
+
+
Ruby?
+
+
+ HTML
+ end
+
+ def colophon_page
+ <<~HTML
+
+
whyruby.info • #{Date.current.year}
+
+ HTML
+ end
+
+ def back_page
+ <<~HTML
+
+
Made with ❤️ by the Ruby community
+
rubycommunity.org
+
+ HTML
+ end
+
+ def testimonial_page(testimonial)
+ user = testimonial.user
+ subheading_html = format_subheading(testimonial.subheading)
+
+ <<~HTML
+
+
+ #{"
#{escape(testimonial.heading)}
" if testimonial.heading.present?}
+ #{"
#{subheading_html}
" if testimonial.subheading.present?}
+ #{"
#{escape(testimonial.body_text)}
" if testimonial.body_text.present?}
+ #{quote_block(testimonial)}
+ #{user_tile(user)}
+
+
+ HTML
+ end
+
+ def quote_block(testimonial)
+ return "" if testimonial.quote.blank?
+
+ <<~HTML
+
+
“
+
+
#{escape(testimonial.quote)}
+
+
+ HTML
+ end
+
+ def user_tile(user)
+ @gem_clip_counter = (@gem_clip_counter || 0) + 1
+ uid = @gem_clip_counter
+ avatar_url = escape(user.avatar_url.to_s)
+ gem_path = "M56.6.55h86.84c6.79,0,13.13,3.39,16.9,9.04l36.26,54.34c5.26,7.89,4.37,18.37-2.15,25.25l-79.68,84.14c-8.01,8.46-21.49,8.46-29.51,0L5.59,89.18c-6.52-6.88-7.41-17.36-2.15-25.25L39.7,9.59C43.47,3.94,49.81.55,56.6.55Z"
+
+ meta_items = []
+
+ if user.company.present?
+ meta_items << <<~HTML.strip
+
+
+
+
+ #{escape(user.company)}
+
+ HTML
+ end
+
+ if user.location.present?
+ meta_items << <<~HTML.strip
+
+
+
+
+ #{escape(user.location)}
+
+ HTML
+ end
+
+ <<~HTML
+
+
+
+
+
+
+
+
+ #{" " if avatar_url.present?}
+ #{"" if avatar_url.blank?}
+
+
+
+
+
+
#{escape(user.display_name)}
+ #{"
#{escape(user.bio)}
" if user.bio.present?}
+ #{meta_items.any? ? "
#{meta_items.join}
" : ""}
+
+
+ HTML
+ end
+
+ def format_subheading(subheading)
+ return "" if subheading.blank?
+
+ subheading
+ .split(".")
+ .map(&:strip)
+ .reject(&:blank?)
+ .map { |sentence| "#{escape(sentence)}." }
+ .join(" ")
+ end
+
+ def escape(text)
+ ERB::Util.html_escape(text.to_s)
+ end
+
+ def heart_data_uri
+ @heart_data_uri ||= begin
+ path = Rails.root.join("app", "assets", "images", "heart.webp")
+ "data:image/webp;base64,#{Base64.strict_encode64(File.binread(path))}"
+ end
+ end
+end
From 07b4b3ba51d6c7f67a9229f0e0d58f3047154111 Mon Sep 17 00:00:00 2001
From: Yuri Sidorov <403994+newstler@users.noreply.github.com>
Date: Tue, 11 Aug 2026 18:40:33 +0200
Subject: [PATCH 2/9] =?UTF-8?q?Bump=20Ruby=204.0.1=20=E2=86=92=204.0.3,=20?=
=?UTF-8?q?install=20rails=5Ferror=5Fdashboard=20tables?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- .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.
---
.ruby-version | 2 +-
db/schema.rb | 184 ++++++++++++++++++++++++++++++++-
lib/tasks/production_data.rake | 4 +-
3 files changed, 186 insertions(+), 4 deletions(-)
diff --git a/.ruby-version b/.ruby-version
index 1454f6e..c4e41f9 100644
--- a/.ruby-version
+++ b/.ruby-version
@@ -1 +1 @@
-4.0.1
+4.0.3
diff --git a/db/schema.rb b/db/schema.rb
index 5532af8..06508f2 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema[8.2].define(version: 2026_04_08_170000) do
+ActiveRecord::Schema[8.2].define(version: 2026_04_10_161960) do
create_table "_litestream_lock", id: false, force: :cascade do |t|
t.integer "id"
end
@@ -277,6 +277,182 @@
t.index ["provider", "key"], name: "index_provider_credentials_on_provider_and_key", unique: true
end
+ create_table "rails_error_dashboard_applications", force: :cascade do |t|
+ t.datetime "created_at"
+ t.text "description"
+ t.string "name", limit: 255, null: false
+ t.datetime "updated_at"
+ t.index ["name"], name: "index_rails_error_dashboard_applications_on_name", unique: true
+ end
+
+ create_table "rails_error_dashboard_cascade_patterns", force: :cascade do |t|
+ t.float "avg_delay_seconds"
+ t.float "cascade_probability"
+ t.bigint "child_error_id", null: false
+ t.datetime "created_at", null: false
+ t.integer "frequency", default: 1, null: false
+ t.datetime "last_detected_at"
+ t.bigint "parent_error_id", null: false
+ t.datetime "updated_at", null: false
+ t.index ["cascade_probability"], name: "index_cascade_patterns_on_probability"
+ t.index ["child_error_id"], name: "index_cascade_patterns_on_child"
+ t.index ["parent_error_id", "child_error_id"], name: "index_cascade_patterns_on_parent_and_child", unique: true
+ t.index ["parent_error_id"], name: "index_cascade_patterns_on_parent"
+ end
+
+ create_table "rails_error_dashboard_diagnostic_dumps", force: :cascade do |t|
+ t.integer "application_id", null: false
+ t.datetime "captured_at", null: false
+ t.datetime "created_at", null: false
+ t.text "dump_data", null: false
+ t.string "note"
+ t.datetime "updated_at", null: false
+ t.index ["application_id"], name: "index_rails_error_dashboard_diagnostic_dumps_on_application_id"
+ t.index ["captured_at"], name: "index_diagnostic_dumps_on_captured_at"
+ end
+
+ create_table "rails_error_dashboard_error_baselines", force: :cascade do |t|
+ t.string "baseline_type", null: false
+ t.integer "count", default: 0, null: false
+ t.datetime "created_at", null: false
+ t.string "error_type", null: false
+ t.float "mean"
+ t.float "percentile_95"
+ t.float "percentile_99"
+ t.datetime "period_end", null: false
+ t.datetime "period_start", null: false
+ t.string "platform", null: false
+ t.integer "sample_size", default: 0, null: false
+ t.float "std_dev"
+ t.datetime "updated_at", null: false
+ t.index ["error_type", "platform", "baseline_type", "period_start"], name: "index_error_baselines_on_type_platform_baseline_period"
+ t.index ["error_type", "platform"], name: "index_error_baselines_on_error_type_and_platform"
+ t.index ["period_end"], name: "index_error_baselines_on_period_end"
+ end
+
+ create_table "rails_error_dashboard_error_comments", force: :cascade do |t|
+ t.string "author_name", null: false
+ t.text "body", null: false
+ t.datetime "created_at", null: false
+ t.bigint "error_log_id", null: false
+ t.datetime "updated_at", null: false
+ t.index ["error_log_id", "created_at"], name: "index_error_comments_on_error_and_time"
+ t.index ["error_log_id"], name: "index_rails_error_dashboard_error_comments_on_error_log_id"
+ end
+
+ create_table "rails_error_dashboard_error_logs", force: :cascade do |t|
+ t.string "action_name"
+ t.string "app_version"
+ t.bigint "application_id", null: false
+ t.datetime "assigned_at"
+ t.string "assigned_to"
+ t.text "backtrace"
+ t.string "backtrace_signature"
+ t.text "breadcrumbs"
+ t.string "content_type", limit: 100
+ t.string "controller_name"
+ t.datetime "created_at", null: false
+ t.text "environment_info"
+ t.string "error_hash"
+ t.string "error_type", null: false
+ t.text "exception_cause"
+ t.integer "external_issue_number"
+ t.string "external_issue_provider", limit: 20
+ t.string "external_issue_url"
+ t.datetime "first_seen_at"
+ t.string "git_sha"
+ t.string "hostname", limit: 255
+ t.string "http_method", limit: 10
+ t.text "instance_variables"
+ t.string "ip_address"
+ t.datetime "last_seen_at"
+ t.text "local_variables"
+ t.text "message", null: false
+ t.boolean "muted", default: false, null: false
+ t.datetime "muted_at"
+ t.string "muted_by"
+ t.string "muted_reason"
+ t.datetime "occurred_at", null: false
+ t.integer "occurrence_count", default: 1, null: false
+ t.string "platform"
+ t.integer "priority_level", default: 0
+ t.integer "priority_score"
+ t.datetime "reopened_at"
+ t.integer "request_duration_ms"
+ t.text "request_params"
+ t.text "request_url"
+ t.text "resolution_comment"
+ t.string "resolution_reference"
+ t.boolean "resolved", default: false, null: false
+ t.datetime "resolved_at"
+ t.string "resolved_by_name"
+ t.float "similarity_score"
+ t.datetime "snoozed_until"
+ t.string "status", default: "new"
+ t.text "system_health"
+ t.datetime "updated_at", null: false
+ t.text "user_agent"
+ t.integer "user_id"
+ t.index ["app_version", "resolved", "occurred_at"], name: "index_error_logs_on_version_resolution_time"
+ t.index ["app_version"], name: "index_rails_error_dashboard_error_logs_on_app_version"
+ t.index ["application_id", "occurred_at"], name: "index_error_logs_on_app_occurred"
+ t.index ["application_id", "resolved"], name: "index_error_logs_on_app_resolved"
+ t.index ["application_id"], name: "index_rails_error_dashboard_error_logs_on_application_id"
+ t.index ["assigned_to", "status", "occurred_at"], name: "index_error_logs_on_assignment_workflow"
+ t.index ["backtrace_signature"], name: "index_rails_error_dashboard_error_logs_on_backtrace_signature"
+ t.index ["controller_name", "action_name", "error_hash"], name: "index_error_logs_on_controller_action_hash"
+ t.index ["error_hash", "resolved", "occurred_at"], name: "index_error_logs_on_hash_resolved_occurred"
+ t.index ["error_hash"], name: "index_rails_error_dashboard_error_logs_on_error_hash"
+ t.index ["error_type", "occurred_at"], name: "index_error_logs_on_error_type_and_occurred_at"
+ t.index ["error_type"], name: "index_rails_error_dashboard_error_logs_on_error_type"
+ t.index ["first_seen_at"], name: "index_rails_error_dashboard_error_logs_on_first_seen_at"
+ t.index ["git_sha"], name: "index_rails_error_dashboard_error_logs_on_git_sha"
+ t.index ["last_seen_at"], name: "index_rails_error_dashboard_error_logs_on_last_seen_at"
+ t.index ["muted"], name: "index_rails_error_dashboard_error_logs_on_muted"
+ t.index ["occurred_at"], name: "index_rails_error_dashboard_error_logs_on_occurred_at"
+ t.index ["occurrence_count"], name: "index_rails_error_dashboard_error_logs_on_occurrence_count"
+ t.index ["platform", "occurred_at"], name: "index_error_logs_on_platform_and_occurred_at"
+ t.index ["platform", "status", "occurred_at"], name: "index_error_logs_on_platform_status_time"
+ t.index ["platform"], name: "index_rails_error_dashboard_error_logs_on_platform"
+ t.index ["priority_level", "resolved", "occurred_at"], name: "index_error_logs_on_priority_resolution"
+ t.index ["priority_score"], name: "index_rails_error_dashboard_error_logs_on_priority_score"
+ t.index ["resolved", "occurred_at"], name: "index_error_logs_on_resolved_and_occurred_at"
+ t.index ["resolved"], name: "index_rails_error_dashboard_error_logs_on_resolved"
+ t.index ["similarity_score"], name: "index_rails_error_dashboard_error_logs_on_similarity_score"
+ t.index ["user_id"], name: "index_rails_error_dashboard_error_logs_on_user_id"
+ end
+
+ create_table "rails_error_dashboard_error_occurrences", force: :cascade do |t|
+ t.datetime "created_at", null: false
+ t.bigint "error_log_id", null: false
+ t.datetime "occurred_at", null: false
+ t.string "request_id"
+ t.string "session_id"
+ t.datetime "updated_at", null: false
+ t.integer "user_id"
+ t.index ["error_log_id"], name: "index_error_occurrences_on_error_log"
+ t.index ["occurred_at", "error_log_id"], name: "index_error_occurrences_on_time_and_error"
+ t.index ["request_id"], name: "index_error_occurrences_on_request"
+ t.index ["user_id"], name: "index_error_occurrences_on_user"
+ end
+
+ create_table "rails_error_dashboard_swallowed_exceptions", force: :cascade do |t|
+ t.bigint "application_id"
+ t.datetime "created_at", null: false
+ t.string "exception_class", limit: 250, null: false
+ t.datetime "last_seen_at"
+ t.datetime "period_hour", null: false
+ t.integer "raise_count", default: 0, null: false
+ t.string "raise_location", limit: 250, null: false
+ t.integer "rescue_count", default: 0, null: false
+ t.string "rescue_location", limit: 250
+ t.datetime "updated_at", null: false
+ t.index ["application_id", "period_hour"], name: "index_swallowed_exceptions_on_app_and_hour"
+ t.index ["exception_class", "period_hour"], name: "index_swallowed_exceptions_on_class_and_hour"
+ t.index ["exception_class", "raise_location", "rescue_location", "period_hour", "application_id"], name: "index_swallowed_exceptions_upsert_key", unique: true
+ t.index ["period_hour"], name: "index_swallowed_exceptions_on_period_hour"
+ end
+
create_table "reports", id: :string, default: -> { "uuid7()" }, force: :cascade do |t|
t.datetime "created_at", null: false
t.text "description"
@@ -460,6 +636,12 @@
add_foreign_key "posts_tags", "posts"
add_foreign_key "posts_tags", "tags"
add_foreign_key "projects", "users"
+ add_foreign_key "rails_error_dashboard_cascade_patterns", "rails_error_dashboard_error_logs", column: "child_error_id"
+ add_foreign_key "rails_error_dashboard_cascade_patterns", "rails_error_dashboard_error_logs", column: "parent_error_id"
+ add_foreign_key "rails_error_dashboard_diagnostic_dumps", "rails_error_dashboard_applications", column: "application_id"
+ add_foreign_key "rails_error_dashboard_error_comments", "rails_error_dashboard_error_logs", column: "error_log_id"
+ add_foreign_key "rails_error_dashboard_error_logs", "rails_error_dashboard_applications", column: "application_id"
+ add_foreign_key "rails_error_dashboard_error_occurrences", "rails_error_dashboard_error_logs", column: "error_log_id"
add_foreign_key "reports", "posts"
add_foreign_key "reports", "users"
add_foreign_key "star_snapshots", "projects"
diff --git a/lib/tasks/production_data.rake b/lib/tasks/production_data.rake
index 4bfbf7c..648cde0 100644
--- a/lib/tasks/production_data.rake
+++ b/lib/tasks/production_data.rake
@@ -26,8 +26,8 @@ class ProductionPullConfig
attr_reader :server_ip, :volume_name, :ssh_user, :dev_db_path, :storage_root
def initialize
- deploy = YAML.safe_load_file(Rails.root.join("config/deploy.yml"), permitted_classes: [ Symbol ])
- db_config = YAML.safe_load(ERB.new(File.read(Rails.root.join("config/database.yml"))).result, permitted_classes: [ Symbol ])
+ deploy = YAML.safe_load_file(Rails.root.join("config/deploy.yml"), permitted_classes: [ Symbol ], aliases: true)
+ db_config = YAML.safe_load(ERB.new(File.read(Rails.root.join("config/database.yml"))).result, permitted_classes: [ Symbol ], aliases: true)
@server_ip = extract_server_ip(deploy)
@volume_name = extract_volume_name(deploy)
From a45bdcf60ac77464ba3a1ab8a5f4c52fa41e1cf1 Mon Sep 17 00:00:00 2001
From: Yuri Sidorov <403994+newstler@users.noreply.github.com>
Date: Thu, 27 Aug 2026 18:03:59 +0200
Subject: [PATCH 3/9] Post-process book PDF to PDF/X-1a with outlined text and
CMYK
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
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.
---
Gemfile.lock | 4 +-
lib/tasks/book.rake | 209 +++++++++++++++++++++++++++++++++++++++++---
2 files changed, 198 insertions(+), 15 deletions(-)
diff --git a/Gemfile.lock b/Gemfile.lock
index 8fe8e68..942f4d5 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -115,7 +115,7 @@ GEM
bindex (0.8.1)
bootsnap (1.23.0)
msgpack (~> 1.2)
- brakeman (8.0.5)
+ brakeman (8.0.6)
racc
builder (3.3.0)
capybara (3.40.0)
@@ -658,7 +658,7 @@ CHECKSUMS
bigdecimal (4.1.1) sha256=1c09efab961da45203c8316b0cdaec0ff391dfadb952dd459584b63ebf8054ca
bindex (0.8.1) sha256=7b1ecc9dc539ed8bccfc8cb4d2732046227b09d6f37582ff12e50a5047ceb17e
bootsnap (1.23.0) sha256=c1254f458d58558b58be0f8eb8f6eec2821456785b7cdd1e16248e2020d3f214
- brakeman (8.0.5) sha256=03735f9690d3fd4b32d66aacbf0a6d15a84266bdd06b32c05c8ecc8f6021d2be
+ brakeman (8.0.6) sha256=759cc69341115e6c2dcd47b6fd8649a0b9bd540e3585ac8a0a94e31c66fee386
builder (3.3.0) sha256=497918d2f9dca528fdca4b88d84e4ef4387256d984b8154e9d5d3fe5a9c8835f
capybara (3.40.0) sha256=42dba720578ea1ca65fd7a41d163dd368502c191804558f6e0f71b391054aeef
concurrent-ruby (1.3.6) sha256=6b56837e1e7e5292f9864f34b69c5a2cbc75c0cf5338f1ce9903d10fa762d5ab
diff --git a/lib/tasks/book.rake b/lib/tasks/book.rake
index a4e9564..3d4682c 100644
--- a/lib/tasks/book.rake
+++ b/lib/tasks/book.rake
@@ -10,7 +10,24 @@ namespace :book do
# Kept here (rather than unpublished in the DB) so authors can still edit/resubmit on the site.
EXCLUDED_USERNAMES = %w[rubyon].freeze
- desc "Generate 'Why Ruby?' book as a single HTML file, then render to PDF via headless Chrome"
+ # Print specs (European printshop, per whyruby.info book contract).
+ TRIM_WIDTH_MM = 170
+ TRIM_HEIGHT_MM = 240
+ BLEED_MM = 3
+ PAGE_WIDTH_MM = TRIM_WIDTH_MM + BLEED_MM * 2 # 176
+ PAGE_HEIGHT_MM = TRIM_HEIGHT_MM + BLEED_MM * 2 # 246
+
+ # We look for a Fogra39-family ICC profile (the European coated standard)
+ # inside vendor/icc/. The ECI profiles aren't redistributable, so users must
+ # drop the file in themselves; we fall back to Ghostscript's default CMYK.
+ PREFERRED_ICC_NAMES = %w[
+ ISOcoated_v2_eci.icc
+ ISOcoated_v2_300_eci.icc
+ Coated_Fogra39L_VIGC_300.icc
+ FOGRA39.icc
+ ].freeze
+
+ desc "Generate 'Why Ruby?' as HTML + print-ready PDF (176×246mm, CMYK, text-to-curves, PDF/X-1a)"
task generate: :environment do
testimonials = ordered_testimonials_for_book
@@ -23,11 +40,25 @@ namespace :book do
html_path = Rails.root.join("tmp", "why_ruby_book.html")
File.write(html_path, html)
- puts "Generated book with #{testimonials.size} testimonials"
+ puts "Generated book with #{testimonials.size} testimonials (#{book_page_count(testimonials)} pages, even-padded)"
puts "HTML: #{html_path}"
- pdf_path = Rails.root.join("tmp", "why_ruby_book.pdf")
- render_book_pdf(html_path, pdf_path)
+ raw_pdf_path = Rails.root.join("tmp", "why_ruby_book_raw.pdf")
+ final_pdf_path = Rails.root.join("tmp", "why_ruby_book.pdf")
+
+ unless render_chrome_pdf(html_path, raw_pdf_path)
+ puts "Chrome PDF step failed — skipping post-processing."
+ next
+ end
+
+ if postprocess_pdf_for_print(raw_pdf_path, final_pdf_path)
+ File.delete(raw_pdf_path) if File.exist?(raw_pdf_path)
+ puts "PDF: #{final_pdf_path}"
+ puts " → CMYK · text outlined to curves · PDF/X-1a · 176×246mm (170×240 trim + 3mm bleed)"
+ else
+ File.rename(raw_pdf_path, final_pdf_path) if File.exist?(raw_pdf_path)
+ puts "PDF: #{final_pdf_path} (raw Chrome output — post-processing skipped/failed)"
+ end
end
private
@@ -43,12 +74,12 @@ namespace :book do
featured + rest
end
- def render_book_pdf(html_path, pdf_path)
+ def render_chrome_pdf(html_path, pdf_path)
chrome = detect_chrome_binary
unless chrome
- puts "Chrome/Chromium not found — skipping PDF step."
+ puts "Chrome/Chromium not found — cannot generate PDF."
puts "Install Chrome, or open the HTML in your browser and use File → Print → Save as PDF."
- return
+ return false
end
ok = system(
@@ -62,11 +93,75 @@ namespace :book do
"file://#{html_path}"
)
- if ok && File.exist?(pdf_path)
- puts "PDF: #{pdf_path}"
+ ok && File.exist?(pdf_path)
+ end
+
+ # Post-process Chrome's PDF into a print-ready PDF/X-1a:
+ # • All glyphs outlined to curves (-dNoOutputFonts) — kills Affinity's
+ # "broken font" import problem since there are no fonts in the file
+ # to break in the first place.
+ # • RGB → CMYK conversion with a Fogra39-family output intent when the
+ # ECI ICC profile is available under vendor/icc/, otherwise Ghostscript's
+ # default CMYK profile (US-SWOP-ish; visually close for proofing).
+ # • /prepress preset keeps images at 300 DPI and honors overprint.
+ def postprocess_pdf_for_print(input_path, output_path)
+ gs = detect_ghostscript
+ unless gs
+ puts "Ghostscript not found — skipping print-ready post-processing."
+ puts "Install with: brew install ghostscript (macOS) or apt install ghostscript (Debian/Ubuntu)"
+ return false
+ end
+
+ icc_path, icc_source = resolve_output_icc_profile
+ unless icc_path
+ puts "No CMYK ICC profile available — skipping post-processing."
+ return false
+ end
+ pdfx_def_path = write_pdfx_def(icc_path)
+
+ puts "Post-processing PDF via Ghostscript"
+ if icc_source == :fogra
+ puts " Output intent: #{File.basename(icc_path)}"
else
- puts "PDF generation failed. Try opening the HTML in Chrome and printing manually."
+ puts " Output intent: Ghostscript default CMYK (drop a Fogra39 profile at"
+ puts " vendor/icc/ISOcoated_v2_eci.icc from https://www.eci.org for a"
+ puts " fully spec-compliant PDF/X-1a; download is free)."
+ end
+
+ # Ghostscript 9.28+ SAFER mode needs an explicit allowlist for anything
+ # outside the working dir — the ICC profile especially, since it typically
+ # lives under /opt/homebrew or /usr/share.
+ ok = system(
+ gs,
+ "-dNOPAUSE", "-dBATCH", "-dSAFER", "-dQUIET",
+ "--permit-file-read=#{icc_path}",
+ "--permit-file-read=#{pdfx_def_path}",
+ "--permit-file-read=#{input_path}",
+ "--permit-file-write=#{output_path}",
+ "-sDEVICE=pdfwrite",
+ "-dCompatibilityLevel=1.6",
+ "-dPDFX=1",
+ "-dNoOutputFonts",
+ "-sProcessColorModel=DeviceCMYK",
+ "-sColorConversionStrategy=CMYK",
+ "-dPDFSETTINGS=/prepress",
+ "-dEmbedAllFonts=true",
+ "-dSubsetFonts=true",
+ "-dDetectDuplicateImages=true",
+ "-sOutputICCProfile=#{icc_path}",
+ "-sOutputFile=#{output_path}",
+ pdfx_def_path.to_s,
+ input_path.to_s
+ )
+
+ File.delete(pdfx_def_path) if File.exist?(pdfx_def_path)
+
+ unless ok && File.exist?(output_path)
+ puts " Ghostscript post-processing failed — see errors above."
+ return false
end
+
+ true
end
def detect_chrome_binary
@@ -81,7 +176,90 @@ namespace :book do
].find { |path| File.executable?(path) }
end
+ def detect_ghostscript
+ return ENV["GS_BIN"] if ENV["GS_BIN"] && File.executable?(ENV["GS_BIN"])
+
+ %w[
+ /opt/homebrew/bin/gs
+ /usr/local/bin/gs
+ /usr/bin/gs
+ ].find { |path| File.executable?(path) }
+ end
+
+ def resolve_output_icc_profile
+ vendor_icc = Rails.root.join("vendor", "icc")
+ preferred = PREFERRED_ICC_NAMES.map { |name| vendor_icc.join(name) }.find { |p| File.exist?(p) }
+ return [ preferred.to_s, :fogra ] if preferred
+
+ default_cmyk = Dir.glob([
+ "/opt/homebrew/share/ghostscript/*/iccprofiles/default_cmyk.icc",
+ "/usr/local/share/ghostscript/*/iccprofiles/default_cmyk.icc",
+ "/usr/share/ghostscript/*/iccprofiles/default_cmyk.icc"
+ ]).first
+
+ default_cmyk ? [ default_cmyk, :default ] : [ nil, :missing ]
+ end
+
+ # Adapted from Ghostscript's stock PDFX_def.ps, hard-coded for PDF/X-1a with
+ # a Fogra39-family CMYK output intent (safe default even when we fall back to
+ # gs's own default_cmyk.icc — the printshop will resolve against their own
+ # calibration either way).
+ def write_pdfx_def(icc_path)
+ escaped_icc = icc_path.to_s.gsub("(", '\\(').gsub(")", '\\)')
+
+ body = <<~PS
+ %!
+ % Generated PDF/X-1a header for the 'Why Ruby?' book.
+
+ systemdict /ColorConversionStrategy known {
+ systemdict /ColorConversionStrategy get cvn dup /Gray ne exch /CMYK ne and
+ } {
+ true
+ } ifelse
+ { /ColorConversionStrategy cvx /rangecheck signalerror
+ } if
+
+ [ /GTS_PDFXVersion (PDF/X-1a:2001)
+ /Title (Why Ruby?)
+ /Trapped /False
+ /DOCINFO pdfmark
+
+ /ICCProfile (#{escaped_icc}) def
+
+ [/_objdef {icc_PDFX} /type /stream /OBJ pdfmark
+ [{icc_PDFX} << /N 4 >> /PUT pdfmark
+ [{icc_PDFX} ICCProfile (r) file /PUT pdfmark
+
+ [/_objdef {OutputIntent_PDFX} /type /dict /OBJ pdfmark
+ [{OutputIntent_PDFX} <<
+ /Type /OutputIntent
+ /S /GTS_PDFX
+ /OutputCondition (Commercial offset printing, Europe)
+ /Info (Coated FOGRA39 \\(ISO 12647-2:2004\\))
+ /OutputConditionIdentifier (FOGRA39)
+ /RegistryName (http://www.color.org)
+ /DestOutputProfile {icc_PDFX}
+ >> /PUT pdfmark
+ [{Catalog} <> /PUT pdfmark
+ PS
+
+ path = Rails.root.join("tmp", "why_ruby_pdfx_def.ps")
+ File.write(path, body)
+ path
+ end
+
+ # Front matter is 2 pages (title + colophon), back matter is 1 page.
+ # Printshops need an even total, so we drop a blank leaf before the back
+ # cover if the count comes out odd.
+ def book_page_count(testimonials)
+ base = 2 + testimonials.size + 1
+ base.odd? ? base + 1 : base
+ end
+
def build_book_html(testimonials)
+ base_pages = 2 + testimonials.size + 1
+ padding_page = base_pages.odd? ? blank_page : ""
+
<<~HTML
@@ -100,12 +278,17 @@ namespace :book do
#{title_page}
#{colophon_page}
#{testimonials.map { |t| testimonial_page(t) }.join("\n")}
+ #{padding_page}
#{back_page}