From 98e0981332ed55d792a24901da49b5b36211022d Mon Sep 17 00:00:00 2001 From: Dani Bengl Date: Wed, 20 May 2026 11:03:24 +0200 Subject: [PATCH 1/6] Configure link rewriting --- bin/mdbook-rewrite-links | 40 ++++++++++++++++++++++++++++++++++++++++ book.toml | 5 ++++- 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100755 bin/mdbook-rewrite-links diff --git a/bin/mdbook-rewrite-links b/bin/mdbook-rewrite-links new file mode 100755 index 00000000..8777bc0b --- /dev/null +++ b/bin/mdbook-rewrite-links @@ -0,0 +1,40 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# mdbook preprocessor: rewrite relative links to templates/* (non-.md) into +# absolute GitHub blob URLs so the published book points to GitHub instead of +# offering a raw-file download. Source markdown keeps relative paths so local +# editing and raw-GitHub viewing still work. + +require "json" + +GITHUB_BLOB = "https://github.com/renuo/application-setup-guide/blob/main" + +# Matches ](path) where path points into templates/ and does NOT end in .md. +# Handles both ../templates/... and templates/... forms. +LINK_RE = %r{\]\((\.\.?/)?(templates/[^)\s]+?)\)} + +def rewrite(markdown) + markdown.gsub(LINK_RE) do + path = Regexp.last_match(2) + next Regexp.last_match(0) if path.end_with?(".md") + "](#{GITHUB_BLOB}/#{path})" + end +end + +def walk(section) + if section.is_a?(Hash) && section["Chapter"] + chapter = section["Chapter"] + chapter["content"] = rewrite(chapter["content"]) if chapter["content"] + chapter["sub_items"]&.each { |item| walk(item) } + end +end + +if ARGV[0] == "supports" + exit 0 +end + +_context, book = JSON.parse($stdin.read) +items = book["items"] || book["sections"] || [] +items.each { |section| walk(section) } +puts JSON.generate(book) diff --git a/book.toml b/book.toml index d712cdae..33bd0720 100644 --- a/book.toml +++ b/book.toml @@ -1,12 +1,15 @@ [book] authors = ["devs@Renuo"] language = "en" -src = "" +src = "." title = "Renuo - Application Setup Guide" [build] create-missing = false use-default-preprocessors = false +[preprocessor.rewrite-links] +command = "bin/mdbook-rewrite-links" + [output.html.search] limit-results = 10 From 83e992c4c454d3bbebbd19f9d1918ad4915962aa Mon Sep 17 00:00:00 2001 From: Dani Bengl Date: Wed, 20 May 2026 11:09:01 +0200 Subject: [PATCH 2/6] Add home controller --- templates/app/controllers/home_controller.rb | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 templates/app/controllers/home_controller.rb diff --git a/templates/app/controllers/home_controller.rb b/templates/app/controllers/home_controller.rb new file mode 100644 index 00000000..c8beefde --- /dev/null +++ b/templates/app/controllers/home_controller.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +class HomeController < ApplicationController + def check + val = ActiveRecord::Base.connection.execute('select 1+2 as val').first['val'] + render plain: "1+2=#{val}" + end +end From e099a8c9b7e185d0fc93f28efc677a89647f6db6 Mon Sep 17 00:00:00 2001 From: Dani Bengl Date: Wed, 20 May 2026 11:18:23 +0200 Subject: [PATCH 3/6] Cucumber suggestion --- ruby_on_rails/cucumber.md | 4 ++-- templates/app/controllers/home_controller.rb | 8 -------- templates/features/home_check.feature | 4 ++-- templates/features/step_definitions/home_check_steps.rb | 4 ++-- 4 files changed, 6 insertions(+), 14 deletions(-) delete mode 100644 templates/app/controllers/home_controller.rb diff --git a/ruby_on_rails/cucumber.md b/ruby_on_rails/cucumber.md index 1beba008..3991daeb 100644 --- a/ruby_on_rails/cucumber.md +++ b/ruby_on_rails/cucumber.md @@ -41,8 +41,8 @@ If you add Cucumber to an existing project, test a real page instead of using th Add the following files: -* [`app/controllers/home_controller.rb`](../templates/app/controllers/home_controller.rb) (If you haven't done so -already) in the [RSpec](rspec.md) section. +* [`app/controllers/rails/health_controller.rb`](../templates/app/controllers/rails/health_controller.rb) (If you +haven't done so already) in the [RSpec](rspec.md) section. * [`features/home_check.feature`](../templates/features/home_check.feature) * [`features/step_definitions/home_check_steps.rb`](../templates/features/step_definitions/home_check_steps.rb) diff --git a/templates/app/controllers/home_controller.rb b/templates/app/controllers/home_controller.rb deleted file mode 100644 index c8beefde..00000000 --- a/templates/app/controllers/home_controller.rb +++ /dev/null @@ -1,8 +0,0 @@ -# frozen_string_literal: true - -class HomeController < ApplicationController - def check - val = ActiveRecord::Base.connection.execute('select 1+2 as val').first['val'] - render plain: "1+2=#{val}" - end -end diff --git a/templates/features/home_check.feature b/templates/features/home_check.feature index 9d3c1af5..9a361056 100644 --- a/templates/features/home_check.feature +++ b/templates/features/home_check.feature @@ -4,5 +4,5 @@ Feature: So I can assure the app is alive Scenario: - When I visit "/home/check" - Then I see the text "1+2=3" + When I visit "/up" + Then the response status is 200 diff --git a/templates/features/step_definitions/home_check_steps.rb b/templates/features/step_definitions/home_check_steps.rb index 4ee22edb..26e2a48a 100644 --- a/templates/features/step_definitions/home_check_steps.rb +++ b/templates/features/step_definitions/home_check_steps.rb @@ -2,6 +2,6 @@ visit path end -Then(/^I see the text "([^"]*)"$/) do |text| - expect(page).to have_content(text) +Then(/^the response status is (\d+)$/) do |status| + expect(page).to have_http_status(status.to_i) end From 0462d47c02e528abe763b1717d71178511d983af Mon Sep 17 00:00:00 2001 From: Dani Bengl Date: Wed, 20 May 2026 11:18:24 +0200 Subject: [PATCH 4/6] Revert "Cucumber suggestion" This reverts commit e099a8c9b7e185d0fc93f28efc677a89647f6db6. --- ruby_on_rails/cucumber.md | 4 ++-- templates/app/controllers/home_controller.rb | 8 ++++++++ templates/features/home_check.feature | 4 ++-- templates/features/step_definitions/home_check_steps.rb | 4 ++-- 4 files changed, 14 insertions(+), 6 deletions(-) create mode 100644 templates/app/controllers/home_controller.rb diff --git a/ruby_on_rails/cucumber.md b/ruby_on_rails/cucumber.md index 3991daeb..1beba008 100644 --- a/ruby_on_rails/cucumber.md +++ b/ruby_on_rails/cucumber.md @@ -41,8 +41,8 @@ If you add Cucumber to an existing project, test a real page instead of using th Add the following files: -* [`app/controllers/rails/health_controller.rb`](../templates/app/controllers/rails/health_controller.rb) (If you -haven't done so already) in the [RSpec](rspec.md) section. +* [`app/controllers/home_controller.rb`](../templates/app/controllers/home_controller.rb) (If you haven't done so +already) in the [RSpec](rspec.md) section. * [`features/home_check.feature`](../templates/features/home_check.feature) * [`features/step_definitions/home_check_steps.rb`](../templates/features/step_definitions/home_check_steps.rb) diff --git a/templates/app/controllers/home_controller.rb b/templates/app/controllers/home_controller.rb new file mode 100644 index 00000000..c8beefde --- /dev/null +++ b/templates/app/controllers/home_controller.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +class HomeController < ApplicationController + def check + val = ActiveRecord::Base.connection.execute('select 1+2 as val').first['val'] + render plain: "1+2=#{val}" + end +end diff --git a/templates/features/home_check.feature b/templates/features/home_check.feature index 9a361056..9d3c1af5 100644 --- a/templates/features/home_check.feature +++ b/templates/features/home_check.feature @@ -4,5 +4,5 @@ Feature: So I can assure the app is alive Scenario: - When I visit "/up" - Then the response status is 200 + When I visit "/home/check" + Then I see the text "1+2=3" diff --git a/templates/features/step_definitions/home_check_steps.rb b/templates/features/step_definitions/home_check_steps.rb index 26e2a48a..4ee22edb 100644 --- a/templates/features/step_definitions/home_check_steps.rb +++ b/templates/features/step_definitions/home_check_steps.rb @@ -2,6 +2,6 @@ visit path end -Then(/^the response status is (\d+)$/) do |status| - expect(page).to have_http_status(status.to_i) +Then(/^I see the text "([^"]*)"$/) do |text| + expect(page).to have_content(text) end From 6dd8d4965e904e368902b729d20f16bcb689d178 Mon Sep 17 00:00:00 2001 From: Dani Bengl Date: Wed, 20 May 2026 11:56:03 +0200 Subject: [PATCH 5/6] Add supports comment --- bin/mdbook-rewrite-links | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/bin/mdbook-rewrite-links b/bin/mdbook-rewrite-links index 8777bc0b..db0f2e4b 100755 --- a/bin/mdbook-rewrite-links +++ b/bin/mdbook-rewrite-links @@ -8,6 +8,12 @@ require "json" +# mdbook invokes preprocessors with `supports ` to probe compatibility. +# Exit 0 to signal support; no stdin payload is sent in that mode. +if ARGV[0] == "supports" + exit 0 +end + GITHUB_BLOB = "https://github.com/renuo/application-setup-guide/blob/main" # Matches ](path) where path points into templates/ and does NOT end in .md. @@ -30,10 +36,6 @@ def walk(section) end end -if ARGV[0] == "supports" - exit 0 -end - _context, book = JSON.parse($stdin.read) items = book["items"] || book["sections"] || [] items.each { |section| walk(section) } From 31fbabd36e0c35ad4b9c1f1c20d2eb9ec6fc6a7e Mon Sep 17 00:00:00 2001 From: Dani Bengl <53896675+cb341@users.noreply.github.com> Date: Wed, 20 May 2026 13:54:48 +0200 Subject: [PATCH 6/6] Let's remove templates/app/controllers/home_controller.rb from the template for now. We need to update the cucumber page anyways --- templates/app/controllers/home_controller.rb | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 templates/app/controllers/home_controller.rb diff --git a/templates/app/controllers/home_controller.rb b/templates/app/controllers/home_controller.rb deleted file mode 100644 index c8beefde..00000000 --- a/templates/app/controllers/home_controller.rb +++ /dev/null @@ -1,8 +0,0 @@ -# frozen_string_literal: true - -class HomeController < ApplicationController - def check - val = ActiveRecord::Base.connection.execute('select 1+2 as val').first['val'] - render plain: "1+2=#{val}" - end -end