auto-platform-guide 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aa4919c7e60428d1c7b4c3d96d22e46982f5932359bb878acb31e6ed726b4ba8
4
- data.tar.gz: 23830b2e83e5e395e51e11b9426b2ff9c149e66ce2a8f76175e7a7ca131e580d
3
+ metadata.gz: 6a0f92f354b138123f8bb9195f00fe36761bb28a71076101409eb1202e85a7cd
4
+ data.tar.gz: 4e8933ef7687c1b6cbc1e26c8acd6f2cb0f105853b258a3140caf840e5aa8d82
5
5
  SHA512:
6
- metadata.gz: 4f0a075013f5c25be41e7cd678c2f506b6403f43d5a6736e0a2d7505808628d00e5243e02e6d2967b890bb47493d21b94eae715e259e03c2846dbcdcd3814d04
7
- data.tar.gz: 3e42c02cfc75cfdc339230cda2dfabab7e1c89e7e23de382f264db65ff2183eaddd9f20079df8af719054843a39f7d1b3800af52fa65e15a93a7df346719d718
6
+ metadata.gz: 44d659d32d930bacc31e42b4c23732508d56e4680a63188ed733d7931165e883f3aaa7126e30e4e5ae38e79e72f6731bb7d73353c1040514a931f0f7b9204518
7
+ data.tar.gz: ffd5c19017221d77f4910d606338dd36313b9c51587632b3c68c6c66b1fc9c55b8d857dd2730e33da52d03cf06d9ecda9fde9af1181c68a7ac2f965f63de6829
data/CHANGELOG.md CHANGED
@@ -8,6 +8,21 @@ and this project adheres to
8
8
 
9
9
  ## [Unreleased]
10
10
 
11
+ ## [0.3.0] - 2026-11-12
12
+
13
+ ### Added
14
+
15
+ - `AutoPlatformGuide::TableOfContents`: reads the `toc.yml` the generator writes
16
+ next to each README (`toc.<locale>.yml` for translated runs) and returns the
17
+ guides around an id as `{ previous:, next: }`, so a host app can build
18
+ previous/next navigation without parsing the README or reading specs at runtime.
19
+
20
+ ### Changed
21
+
22
+ - `check` also reports a missing or outdated `toc.yml` next to the README.
23
+
24
+ ## [0.2.0] - 2026-10-29
25
+
11
26
  ### Added
12
27
 
13
28
  - `locales` configuration: translated guides from per-spec `<spec>.<locale>.yml`
@@ -71,5 +86,7 @@ browser driver wiring, and markdown docs viewer.
71
86
 
72
87
  - `bin/generate-docs`; use `auto_platform_guide:generate` instead.
73
88
 
74
- [Unreleased]: https://github.com/mauriciozaffari/auto-platform-guide/compare/v0.1.0...HEAD
89
+ [Unreleased]: https://github.com/mauriciozaffari/auto-platform-guide/compare/v0.3.0...HEAD
90
+ [0.3.0]: https://github.com/mauriciozaffari/auto-platform-guide/compare/v0.2.0...v0.3.0
91
+ [0.2.0]: https://github.com/mauriciozaffari/auto-platform-guide/compare/v0.1.0...v0.2.0
75
92
  [0.1.0]: https://github.com/mauriciozaffari/auto-platform-guide/releases/tag/v0.1.0
data/README.md CHANGED
@@ -13,6 +13,15 @@ The gem documents itself: `docs/platform-guide/` is generated from
13
13
  - `AutoPlatformGuide::Generator` renders markdown guides from `# =` doc comments in
14
14
  system specs into `generated_docs_dir`, with an ordered README TOC grouped by
15
15
  `@category`/`@order` directives.
16
+ - `AutoPlatformGuide::TableOfContents` reads the `toc.yml` the generator writes next
17
+ to the README (`toc.<locale>.yml` for a translated run), so a host app can build
18
+ previous/next navigation from generated data, without parsing the README or
19
+ reading specs at runtime:
20
+
21
+ ```ruby
22
+ AutoPlatformGuide::TableOfContents.neighbours('EVENTS', locale: I18n.locale)
23
+ # => { previous: #<data Entry id="DELIVERIES", title="Deliveries">, next: #<data Entry ...> }
24
+ ```
16
25
  - `AutoPlatformGuide.setup_rspec(config)` wires system-spec screenshot support:
17
26
  `doc_screenshot('name')` captures to `screenshots_dir` when `SCREENSHOTS=true`,
18
27
  and specs run on `rack_test` unless they need a browser (`:js` tag or
@@ -3,6 +3,7 @@
3
3
  require 'fileutils'
4
4
  require 'stringio'
5
5
  require 'pathname'
6
+ require 'yaml'
6
7
 
7
8
  module AutoPlatformGuide
8
9
  # Generates markdown guides from system specs with doc comments, plus the
@@ -11,6 +12,7 @@ module AutoPlatformGuide
11
12
  # SCREENSHOTS=true run.
12
13
  class Generator
13
14
  include LocalizedGeneration
15
+ include ReadmeGeneration
14
16
 
15
17
  # Fallbacks for specs that omit the directives below. Specs with no
16
18
  # `@category` collect under DEFAULT_CATEGORY; specs with no `@order` sort
@@ -96,13 +98,13 @@ module AutoPlatformGuide
96
98
  # screenshot binaries themselves. Returns true when everything is up to date.
97
99
  def up_to_date?
98
100
  stale = find_documented_specs.select { |spec_file| doc_stale?(spec_file) || translations_stale?(spec_file) }
99
- readme_stale = stale.empty? && readmes_stale?
101
+ readme_stale = stale.empty? && (readmes_stale? || tocs_stale?)
100
102
  unless stale.any? || readme_stale
101
103
  puts '✓ Platform-guide docs are up to date.'
102
104
  return true
103
105
  end
104
106
 
105
- warn '✗ Localized README is out of date; run rake auto_platform_guide:readme' if readme_stale
107
+ warn '✗ Generated README or toc is out of date; run rake auto_platform_guide:readme' if readme_stale
106
108
  report_stale(stale)
107
109
  false
108
110
  end
@@ -112,7 +114,7 @@ module AutoPlatformGuide
112
114
  def regenerate_readme
113
115
  validate_translations
114
116
  generate_readme
115
- config.locales.each { |locale| translate_readme(locale) }
117
+ config.locales.each { |locale| write_readme(locale) }
116
118
  puts '✓ Regenerated README.md table of contents.'
117
119
  end
118
120
 
@@ -250,76 +252,5 @@ module AutoPlatformGuide
250
252
  .gsub(/\s+/, '-').squeeze('-')
251
253
  .gsub(/^-|-$/, '')
252
254
  end
253
-
254
- # Writes the README table of contents grouped by `@category` and ordered by
255
- # `@order`. Called at the end of a full/partial generation run and standalone
256
- # via `regenerate_readme` (the `--readme-only` mode).
257
- def generate_readme
258
- File.write(File.join(config.generated_docs_dir, 'README.md'), "#{timestamp_header}#{readme_body}")
259
- end
260
-
261
- # The README markdown after the timestamp header. With a locale it uses the
262
- # translated titles and category names, and `localized_readme[locale]`
263
- # (`'preamble'`, `'contents'`) for the fixed texts, falling back to English.
264
- def readme_body(locale = nil)
265
- texts = config.localized_readme.fetch(locale.to_s, {})
266
- out = StringIO.new
267
-
268
- out.write(texts['preamble'] || config.readme_preamble || README_PREAMBLE)
269
-
270
- # Build the TOC from every documented spec (not just the ones regenerated
271
- # in this run) so running for a subset of specs doesn't drop other
272
- # entries. Group by `@category` and order by `@order`.
273
- groups = toc_groups(locale)
274
-
275
- out.puts category_workflow_diagram(groups.map(&:first))
276
- out.puts
277
- out.puts %(<h2 id="table-of-contents">#{texts['contents'] || 'Table of Contents'}</h2>)
278
-
279
- groups.each { |category, entries| out.write(toc_section(category, entries)) }
280
-
281
- out.string
282
- end
283
-
284
- def toc_section(category, entries)
285
- links = entries.map { |entry| "- [#{entry[:title]}](#{entry[:file]})\n" }.join
286
- %(\n<h3 id="#{slugify(category)}">#{category}</h3>\n\n#{links})
287
- end
288
-
289
- # A Mermaid flowchart of the guide categories in workflow order, rendered by
290
- # the in-app docs viewer. Derived from the same ordered categories as the TOC,
291
- # so it never drifts from the actual guides.
292
- def category_workflow_diagram(categories)
293
- return '' if categories.empty?
294
-
295
- nodes = categories.each_with_index.map { |category, index| %(c#{index}["#{category}"]) }
296
- <<~DIAGRAM.chomp
297
-
298
- ```mermaid
299
- flowchart LR
300
- #{nodes.join(' --> ')}
301
- ```
302
- DIAGRAM
303
- end
304
-
305
- # Returns the TOC as an ordered list of [category, entries] pairs.
306
- # Category order is derived entirely from the specs: categories are
307
- # listed in ascending order of the smallest `@order` they contain (ties broken
308
- # alphabetically), and entries within a category are ordered by `@order` then
309
- # title. Only specs whose generated doc actually exists on disk are linked.
310
- def toc_groups(locale = nil)
311
- entries = find_documented_specs.filter_map do |spec_file|
312
- file = File.basename(generate_output_filename(spec_file))
313
- next unless File.exist?(File.join(config.generated_docs_dir, file))
314
-
315
- toc_entry(spec_file, file, locale)
316
- end
317
-
318
- groups = entries.group_by { |entry| entry[:category] }
319
- .sort_by { |category, group| [group.map { |entry| entry[:order] }.min, category] }
320
- groups.map do |category, group|
321
- [localized_category(group, category), group.sort_by { |entry| [entry[:order], entry[:title]] }]
322
- end
323
- end
324
255
  end
325
256
  end
@@ -25,8 +25,14 @@ module AutoPlatformGuide
25
25
  config.locales.any? { |locale| readme_stale?(locale) }
26
26
  end
27
27
 
28
+ # The generated toc files drive host-app navigation, so a stale or missing
29
+ # one is as stale as the docs themselves.
30
+ def tocs_stale?
31
+ ([nil] + config.locales).any? { |locale| table_of_contents(locale).stale? }
32
+ end
33
+
28
34
  def readme_stale?(locale)
29
- committed = strip_timestamp_header(File.read(translated_readme_path(locale), encoding: 'UTF-8'))
35
+ committed = strip_timestamp_header(File.read(readme_path(locale), encoding: 'UTF-8'))
30
36
  committed != readme_body(locale)
31
37
  rescue Errno::ENOENT
32
38
  true
@@ -49,14 +55,14 @@ module AutoPlatformGuide
49
55
  body = render_doc_body(parsed.translated_comments(locale), parsed.screenshot_calls, locale:)
50
56
  File.write(translated_filename(file, locale), "#{timestamp_header}#{body.rstrip}\n")
51
57
  end
52
- translate_readme(locale)
58
+ write_readme(locale)
53
59
  end
54
60
 
55
61
  def toc_entry(spec_file, file, locale)
56
62
  parsed = spec(spec_file)
57
63
  directives = parsed.directives
58
64
  {
59
- file: locale ? file.sub(/\.md\z/, ".#{locale}.md") : file,
65
+ id: file.delete_suffix('.md'),
60
66
  title: locale ? parsed.translated_comments(locale).first.fetch(:title) : parsed.title,
61
67
  category: directives[:category] || Generator::DEFAULT_CATEGORY,
62
68
  translated_category: locale ? parsed.translated_category(locale) : nil,
@@ -68,13 +74,5 @@ module AutoPlatformGuide
68
74
  def localized_category(group, category)
69
75
  group.filter_map { |entry| entry[:translated_category] }.first || category
70
76
  end
71
-
72
- def translate_readme(locale)
73
- File.write(translated_readme_path(locale), "#{timestamp_header}#{readme_body(locale)}")
74
- end
75
-
76
- def translated_readme_path(locale)
77
- File.join(config.generated_docs_dir, "README.#{locale}.md")
78
- end
79
77
  end
80
78
  end
@@ -0,0 +1,101 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AutoPlatformGuide
4
+ # Writes the README table of contents and the machine-readable toc files the
5
+ # docs viewer navigation reads, for the English run and every locale.
6
+ module ReadmeGeneration
7
+ private
8
+
9
+ # Writes the README table of contents grouped by `@category` and ordered by
10
+ # `@order`. Called at the end of a full/partial generation run and standalone
11
+ # via `regenerate_readme` (the `--readme-only` mode).
12
+ def generate_readme
13
+ write_readme(nil)
14
+ end
15
+
16
+ # The ordered guides of a locale. The README sections and the generated
17
+ # `toc.yml` are both rendered from it, so navigation cannot drift from the
18
+ # index, and host apps read the toc instead of parsing the README.
19
+ def table_of_contents(locale = nil)
20
+ entries = toc_groups(locale).flat_map { |category, group| guides(category, group) }
21
+ TableOfContents.new(entries, locale:)
22
+ end
23
+
24
+ def write_readme(locale)
25
+ table_of_contents(locale).write
26
+ File.write(readme_path(locale), "#{timestamp_header}#{readme_body(locale)}")
27
+ end
28
+
29
+ def readme_path(locale)
30
+ File.join(config.generated_docs_dir, locale ? "README.#{locale}.md" : 'README.md')
31
+ end
32
+
33
+ def guides(category, entries)
34
+ entries.map { |entry| TableOfContents::Entry.new(id: entry[:id], title: entry[:title], category:) }
35
+ end
36
+
37
+ # The README markdown after the timestamp header. With a locale it uses the
38
+ # translated titles and category names, and `localized_readme[locale]`
39
+ # (`'preamble'`, `'contents'`) for the fixed texts, falling back to English.
40
+ def readme_body(locale = nil)
41
+ texts = config.localized_readme.fetch(locale.to_s, {})
42
+ out = StringIO.new
43
+
44
+ out.write(texts['preamble'] || config.readme_preamble || Generator::README_PREAMBLE)
45
+
46
+ # Build the TOC from every documented spec (not just the ones regenerated
47
+ # in this run) so running for a subset of specs doesn't drop other
48
+ # entries. Group by `@category` and order by `@order`.
49
+ groups = table_of_contents(locale).groups
50
+
51
+ out.puts category_workflow_diagram(groups.keys)
52
+ out.puts
53
+ out.puts %(<h2 id="table-of-contents">#{texts['contents'] || 'Table of Contents'}</h2>)
54
+
55
+ groups.each { |category, entries| out.write(toc_section(category, entries, locale)) }
56
+
57
+ out.string
58
+ end
59
+
60
+ def toc_section(category, entries, locale)
61
+ suffix = locale ? ".#{locale}.md" : '.md'
62
+ links = entries.map { |entry| "- [#{entry.title}](#{entry.id}#{suffix})\n" }.join
63
+ %(\n<h3 id="#{slugify(category)}">#{category}</h3>\n\n#{links})
64
+ end
65
+
66
+ # A Mermaid flowchart of the guide categories in workflow order, rendered by
67
+ # the in-app docs viewer. Derived from the same ordered categories as the TOC,
68
+ # so it never drifts from the actual guides.
69
+ def category_workflow_diagram(categories)
70
+ return '' if categories.empty?
71
+
72
+ nodes = categories.each_with_index.map { |category, index| %(c#{index}["#{category}"]) }
73
+ <<~DIAGRAM.chomp
74
+
75
+ ```mermaid
76
+ flowchart LR
77
+ #{nodes.join(' --> ')}
78
+ ```
79
+ DIAGRAM
80
+ end
81
+
82
+ # Returns the TOC as an ordered list of [category, entries] pairs.
83
+ # Category order is derived entirely from the specs: categories are
84
+ # listed in ascending order of the smallest `@order` they contain (ties broken
85
+ # alphabetically), and entries within a category are ordered by `@order` then
86
+ # title. Only specs whose generated doc actually exists on disk are linked.
87
+ def toc_groups(locale = nil)
88
+ entries = find_documented_specs.filter_map do |spec_file|
89
+ file = File.basename(generate_output_filename(spec_file))
90
+ next unless File.exist?(File.join(config.generated_docs_dir, file))
91
+
92
+ toc_entry(spec_file, file, locale)
93
+ end
94
+
95
+ entries.sort_by { |entry| [entry[:order], entry[:title]] }
96
+ .group_by { |entry| entry[:category] }
97
+ .sort_by { |category, group| [group.first[:order], category] }
98
+ .map { |category, group| [localized_category(group, category), group] }
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'yaml'
4
+
5
+ module AutoPlatformGuide
6
+ # The ordered guides of one locale. The generator builds one from the spec
7
+ # directives and writes it as `toc.yml`; a host app loads the committed file to
8
+ # navigate between guides, and the README sections are rendered from `#groups`.
9
+ class TableOfContents
10
+ # One guide in the table of contents.
11
+ class Entry
12
+ attr_reader :id, :title, :category
13
+
14
+ def initialize(id:, title:, category:)
15
+ @id = id
16
+ @title = title
17
+ @category = category
18
+ end
19
+
20
+ def to_h
21
+ { 'id' => id, 'title' => title, 'category' => category }
22
+ end
23
+ end
24
+
25
+ # Reads the committed toc for a locale, falling back to English when the
26
+ # locale has none.
27
+ def self.load(locale: nil)
28
+ path = path_for(locale)
29
+ path = path_for(nil) unless File.exist?(path)
30
+ entries = YAML.load_file(path).map do |entry|
31
+ Entry.new(id: entry['id'], title: entry['title'], category: entry['category'])
32
+ end
33
+ new(entries, locale:)
34
+ end
35
+
36
+ # Where a locale's toc is written.
37
+ def self.path_for(locale)
38
+ File.join(AutoPlatformGuide.configuration.generated_docs_dir, locale ? "toc.#{locale}.yml" : 'toc.yml')
39
+ end
40
+
41
+ def initialize(entries, locale: nil)
42
+ @entries = entries
43
+ @locale = locale
44
+ end
45
+
46
+ attr_reader :entries, :locale
47
+
48
+ # Guides by category, in the order the categories first appear.
49
+ def groups
50
+ entries.group_by(&:category)
51
+ end
52
+
53
+ # The guides either side of `id`, e.g. `{ previous: Entry, next: Entry }`.
54
+ # Omits a side that has no neighbour and returns `{}` for an unknown guide.
55
+ def neighbours(id)
56
+ sequence[id] || {}
57
+ end
58
+
59
+ def write
60
+ File.write(self.class.path_for(locale), to_yaml)
61
+ end
62
+
63
+ def stale?
64
+ File.read(self.class.path_for(locale), encoding: 'UTF-8') != to_yaml
65
+ rescue Errno::ENOENT
66
+ true
67
+ end
68
+
69
+ def to_yaml
70
+ entries.map(&:to_h).to_yaml
71
+ end
72
+
73
+ private
74
+
75
+ def sequence
76
+ @sequence ||= [nil, *entries, nil].each_cons(3).to_h do |previous, entry, following|
77
+ [entry.id, { previous:, next: following }.compact]
78
+ end
79
+ end
80
+ end
81
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AutoPlatformGuide
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.0'
5
5
  end
@@ -5,7 +5,9 @@ require 'auto_platform_guide/configuration'
5
5
  require 'auto_platform_guide/spec_file'
6
6
  require 'auto_platform_guide/document'
7
7
  require 'auto_platform_guide/localized_generation'
8
+ require 'auto_platform_guide/readme_generation'
8
9
  require 'auto_platform_guide/generator'
10
+ require 'auto_platform_guide/table_of_contents'
9
11
  require 'auto_platform_guide/docs_controller_actions'
10
12
 
11
13
  module AutoPlatformGuide
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: auto-platform-guide
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mauricio Zaffari
@@ -130,8 +130,10 @@ files:
130
130
  - lib/auto_platform_guide/generator.rb
131
131
  - lib/auto_platform_guide/localized_generation.rb
132
132
  - lib/auto_platform_guide/rake_tasks.rb
133
+ - lib/auto_platform_guide/readme_generation.rb
133
134
  - lib/auto_platform_guide/rspec.rb
134
135
  - lib/auto_platform_guide/spec_file.rb
136
+ - lib/auto_platform_guide/table_of_contents.rb
135
137
  - lib/auto_platform_guide/version.rb
136
138
  - lib/generators/auto_platform_guide/styles/styles_generator.rb
137
139
  homepage: https://github.com/mauriciozaffari/auto-platform-guide