suma 0.5.22 → 0.5.24

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: 0c89b77873c034c41b9b7660ec2909985af7436ae422672843e9317f4f8fc341
4
- data.tar.gz: 28f6d6ae1d113a0237f54dc156ace158430df12b98761858ee01518811ae2ea9
3
+ metadata.gz: 84aed10cf4b395df03b1e9c479f211c35620ea1b25c7fdc820b53445b82aba35
4
+ data.tar.gz: 66ebda5f4630fe796071be9109c2f9a89f472a22d9904dd62bdf2f58e91c9e8a
5
5
  SHA512:
6
- metadata.gz: ca38065478452e1aba7f79c52fe0a5f28a3de20d1301fb9153fa0f63f44cf9f0cf096248f4f1d1a03ce6d3e001eb47151f8bf848b5ada46f857b697c20bba1ff
7
- data.tar.gz: 977e635c1e99e0a119d8c48f72f4ef763492dfe54ab3561da56485a8becb08c0cb5bc64960dc2dd5322d9a1e6e1d5fe66e39cdb1f6f6717fc11092e0201207b9
6
+ metadata.gz: 26085e6362b8acd67ba3d80b6aef6f7bcc64ff81317702d01f34f1b359b2e9944a83b0dde81c0d933022953d93cfc8d581b77064fa117b94724bbc08ccc49d6d
7
+ data.tar.gz: 2a5a8d7b7b10ceaee01719e18c8ce4431470311e1642db68ef27d2811e4ed47f000cbe770d534120460675e3a14eb36be73c0081314c28dd2af31112a1a686d1
data/.rubocop_todo.yml CHANGED
@@ -77,6 +77,7 @@ Layout/LineLength:
77
77
  - 'spec/suma/register_manifest_generator_spec.rb'
78
78
  - 'spec/suma/schema_category_spec.rb'
79
79
  - 'spec/suma/schema_comparer_integration_spec.rb'
80
+ - 'spec/suma/delivery/plan_spec.rb'
80
81
  - 'spec/suma/schema_discovery_spec.rb'
81
82
  - 'spec/suma/schema_exporter_spec.rb'
82
83
  - 'spec/suma/schema_index_spec.rb'
@@ -87,6 +88,10 @@ Layout/LineLength:
87
88
  - 'spec/suma/term_extractor_spec.rb'
88
89
  - 'spec/suma/urn_spec.rb'
89
90
  - 'suma.gemspec'
91
+ - 'spec/suma/delivery/frame_nav_spec.rb'
92
+ - 'spec/suma/delivery/site_verifier_spec.rb'
93
+ - 'spec/suma/delivery/stitcher_spec.rb'
94
+ - 'spec/suma/delivery/plan_spec.rb'
90
95
 
91
96
  # Offense count: 2
92
97
  # Configuration parameters: IgnoreLiteralBranches, IgnoreConstantBranches, IgnoreDuplicateElseBranch.
@@ -116,19 +121,21 @@ Lint/UnusedMethodArgument:
116
121
  # Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes, Max.
117
122
  Metrics/AbcSize:
118
123
  Exclude:
119
- - 'lib/suma/gcr_package.rb'
120
124
  - 'bin/benchmark_corpus'
121
- - 'lib/suma/worker_pool.rb'
122
- - 'spec/suma/reproducibility_spec.rb'
123
- - 'spec/suma/cli/build_integration_spec.rb'
124
- - 'lib/suma/cli/resolve.rb'
125
- - 'lib/suma/urn_resolver.rb'
125
+ - 'lib/suma/change_manifest.rb'
126
126
  - 'lib/suma/cli/check_svg_quality.rb'
127
127
  - 'lib/suma/cli/core.rb'
128
+ - 'lib/suma/cli/export.rb'
129
+ - 'lib/suma/cli/generate_register.rb'
130
+ - 'lib/suma/cli/resolve.rb'
131
+ - 'lib/suma/closure_validator.rb'
132
+ - 'lib/suma/corpus_graph.rb'
133
+ - 'lib/suma/gcr_package.rb'
128
134
  - 'lib/suma/jsdai/figure.rb'
129
135
  - 'lib/suma/jsdai/figure_image.rb'
130
136
  - 'lib/suma/link_validator.rb'
131
137
  - 'lib/suma/manifest_traverser.rb'
138
+ - 'lib/suma/owl_projection.rb'
132
139
  - 'lib/suma/processor.rb'
133
140
  - 'lib/suma/schema_collection.rb'
134
141
  - 'lib/suma/schema_comparer.rb'
@@ -138,12 +145,11 @@ Metrics/AbcSize:
138
145
  - 'lib/suma/svg_quality/formatters/terminal_formatter.rb'
139
146
  - 'lib/suma/term_extractor.rb'
140
147
  - 'lib/suma/thor_ext.rb'
141
- - 'lib/suma/closure_validator.rb'
142
- - 'lib/suma/corpus_graph.rb'
143
- - 'lib/suma/change_manifest.rb'
144
- - 'lib/suma/cli/generate_register.rb'
145
- - 'lib/suma/owl_projection.rb'
146
- - 'lib/suma/cli/export.rb'
148
+ - 'lib/suma/urn_resolver.rb'
149
+ - 'lib/suma/worker_pool.rb'
150
+ - 'spec/suma/cli/build_integration_spec.rb'
151
+ - 'spec/suma/reproducibility_spec.rb'
152
+ - spec/suma/delivery/stitcher_spec.rb
147
153
 
148
154
  # Offense count: 2
149
155
  # Configuration parameters: CountComments, Max, CountAsOne, AllowedMethods, AllowedPatterns, inherit_mode.
@@ -255,6 +261,7 @@ Performance/CollectionLiteralInLoop:
255
261
  - 'spec/suma/cli/export_spec.rb'
256
262
  - 'spec/suma/cli_spec.rb'
257
263
  - 'spec/suma/schema_comparer_integration_spec.rb'
264
+ - 'spec/suma/delivery/plan_spec.rb'
258
265
 
259
266
  # Offense count: 2
260
267
  # Configuration parameters: Prefixes, AllowedPatterns.
@@ -267,65 +274,70 @@ RSpec/ContextWording:
267
274
  # Configuration parameters: Max, CountAsOne.
268
275
  RSpec/ExampleLength:
269
276
  Exclude:
270
- - 'spec/suma/site_build_spec.rb'
271
- - 'spec/suma/output_canonicalizer_spec.rb'
272
277
  - 'spec/suma/anchor_validator_spec.rb'
273
- - 'spec/suma/translation_ingester_spec.rb'
274
- - 'spec/suma/ifc_profile_pipeline_spec.rb'
275
- - 'spec/suma/schema_manifest_generator_spec.rb'
276
- - 'spec/suma/schema_naming_spec.rb'
277
- - 'spec/suma/cli/build_integration_spec.rb'
278
278
  - 'spec/suma/artifact_server_spec.rb'
279
- - 'spec/suma/gcr_package_spec.rb'
280
- - 'spec/suma/schema_cache_spec.rb'
281
- - 'spec/suma/worker_pool_spec.rb'
282
- - 'spec/suma/schema_collection_rebuild_targets_spec.rb'
283
279
  - 'spec/suma/build_plan_spec.rb'
284
- - 'spec/suma/reproducibility_spec.rb'
285
- - 'spec/suma/provenance_spec.rb'
286
- - 'spec/suma/term_extractor_spec.rb'
287
- - 'spec/suma/cli/resolve_spec.rb'
288
- - 'spec/suma/urn_resolver_spec.rb'
280
+ - 'spec/suma/change_classification_spec.rb'
281
+ - 'spec/suma/change_impact_spec.rb'
282
+ - 'spec/suma/change_manifest_spec.rb'
283
+ - 'spec/suma/cli/build_integration_spec.rb'
289
284
  - 'spec/suma/cli/export_spec.rb'
290
285
  - 'spec/suma/cli/extract_terms_spec.rb'
291
286
  - 'spec/suma/cli/generate_register_spec.rb'
292
287
  - 'spec/suma/cli/generate_schemas_spec.rb'
293
288
  - 'spec/suma/cli/reformat_spec.rb'
289
+ - 'spec/suma/cli/resolve_spec.rb'
294
290
  - 'spec/suma/cli_spec.rb'
295
- - 'spec/suma/collection_config_spec.rb'
296
291
  - 'spec/suma/closure_validator_spec.rb'
292
+ - 'spec/suma/collection_config_spec.rb'
297
293
  - 'spec/suma/collection_manifest_spec.rb'
298
294
  - 'spec/suma/corpus_graph_spec.rb'
299
- - 'spec/suma/owl_projection_spec.rb'
300
- - 'spec/suma/schema_profile_spec.rb'
301
295
  - 'spec/suma/eengine_converter_spec.rb'
302
296
  - 'spec/suma/express_reformatter_spec.rb'
303
297
  - 'spec/suma/express_schema_spec.rb'
298
+ - 'spec/suma/gcr_package_spec.rb'
299
+ - 'spec/suma/ifc_profile_pipeline_spec.rb'
304
300
  - 'spec/suma/jsdai/figure_spec.rb'
305
301
  - 'spec/suma/link_validation_spec.rb'
306
302
  - 'spec/suma/link_validator/step_spec.rb'
307
303
  - 'spec/suma/link_validator_spec.rb'
308
304
  - 'spec/suma/manifest_traverser_spec.rb'
309
305
  - 'spec/suma/note_processor_spec.rb'
310
- - 'spec/suma/publication_spec.rb'
306
+ - 'spec/suma/output_canonicalizer_spec.rb'
307
+ - 'spec/suma/owl_projection_spec.rb'
311
308
  - 'spec/suma/owl_projection_spec.rb'
312
309
  - 'spec/suma/processor_spec.rb'
310
+ - 'spec/suma/provenance_spec.rb'
311
+ - 'spec/suma/publication_spec.rb'
313
312
  - 'spec/suma/register_manifest_generator_spec.rb'
313
+ - 'spec/suma/reproducibility_spec.rb'
314
+ - 'spec/suma/schema_cache_spec.rb'
314
315
  - 'spec/suma/schema_category_spec.rb'
316
+ - 'spec/suma/schema_collection_rebuild_targets_spec.rb'
315
317
  - 'spec/suma/schema_comparer_integration_spec.rb'
318
+ - 'spec/suma/delivery/plan_spec.rb'
316
319
  - 'spec/suma/schema_comparer_spec.rb'
317
320
  - 'spec/suma/schema_compiler_spec.rb'
318
321
  - 'spec/suma/schema_discovery_spec.rb'
319
322
  - 'spec/suma/schema_exporter_spec.rb'
323
+ - 'spec/suma/schema_manifest_generator_spec.rb'
324
+ - 'spec/suma/schema_naming_spec.rb'
325
+ - 'spec/suma/schema_profile_spec.rb'
320
326
  - 'spec/suma/schema_template_spec.rb'
327
+ - 'spec/suma/site_build_spec.rb'
321
328
  - 'spec/suma/site_config/config_spec.rb'
322
329
  - 'spec/suma/svg_quality/scanner_spec.rb'
323
330
  - 'spec/suma/term_classification_spec.rb'
324
331
  - 'spec/suma/term_extractor_spec.rb'
332
+ - 'spec/suma/term_extractor_spec.rb'
333
+ - 'spec/suma/translation_ingester_spec.rb'
334
+ - 'spec/suma/urn_resolver_spec.rb'
325
335
  - 'spec/suma/urn_spec.rb'
326
- - 'spec/suma/change_classification_spec.rb'
327
- - 'spec/suma/change_manifest_spec.rb'
328
- - 'spec/suma/change_impact_spec.rb'
336
+ - 'spec/suma/worker_pool_spec.rb'
337
+ - 'spec/suma/delivery/frame_nav_spec.rb'
338
+ - 'spec/suma/delivery/site_verifier_spec.rb'
339
+ - 'spec/suma/delivery/stitcher_spec.rb'
340
+ - 'spec/suma/delivery/plan_spec.rb'
329
341
 
330
342
  # Offense count: 4
331
343
  # Configuration parameters: Max, AllowedIdentifiers, AllowedPatterns.
@@ -333,18 +345,21 @@ RSpec/IndexedLet:
333
345
  Exclude:
334
346
  - 'spec/suma/cli/export_spec.rb'
335
347
  - 'spec/suma/schema_comparer_integration_spec.rb'
348
+ - 'spec/suma/delivery/plan_spec.rb'
336
349
 
337
350
  # Offense count: 22
338
351
  # Configuration parameters: AssignmentOnly.
339
352
  RSpec/InstanceVariable:
340
353
  Exclude:
341
354
  - 'spec/suma/schema_comparer_integration_spec.rb'
355
+ - 'spec/suma/delivery/plan_spec.rb'
342
356
 
343
357
  # Offense count: 1
344
358
  # This cop supports safe autocorrection (--autocorrect).
345
359
  RSpec/IteratedExpectation:
346
360
  Exclude:
347
361
  - 'spec/suma/schema_comparer_integration_spec.rb'
362
+ - 'spec/suma/delivery/plan_spec.rb'
348
363
 
349
364
  # Offense count: 1
350
365
  # Configuration parameters: .
@@ -356,60 +371,65 @@ RSpec/MessageSpies:
356
371
  # Configuration parameters: Max.
357
372
  RSpec/MultipleExpectations:
358
373
  Exclude:
359
- - 'spec/suma/site_build_spec.rb'
360
- - 'spec/suma/output_canonicalizer_spec.rb'
361
- - 'spec/suma/cli/build_integration_spec.rb'
362
374
  - 'spec/suma/artifact_server_spec.rb'
363
- - 'spec/suma/gcr_package_spec.rb'
364
- - 'spec/suma/schema_cache_spec.rb'
365
- - 'spec/suma/worker_pool_spec.rb'
366
- - 'spec/suma/reproducibility_spec.rb'
367
- - 'spec/suma/provenance_spec.rb'
368
- - 'spec/suma/term_extractor_spec.rb'
369
- - 'spec/suma/cli/resolve_spec.rb'
370
- - 'spec/suma/urn_resolver_spec.rb'
375
+ - 'spec/suma/change_classification_spec.rb'
376
+ - 'spec/suma/change_impact_spec.rb'
377
+ - 'spec/suma/change_manifest_spec.rb'
378
+ - 'spec/suma/cli/build_integration_spec.rb'
371
379
  - 'spec/suma/cli/build_spec.rb'
372
380
  - 'spec/suma/cli/export_spec.rb'
373
381
  - 'spec/suma/cli/expressir_spec.rb'
374
382
  - 'spec/suma/cli/extract_terms_spec.rb'
375
383
  - 'spec/suma/cli/reformat_spec.rb'
384
+ - 'spec/suma/cli/resolve_spec.rb'
376
385
  - 'spec/suma/cli_spec.rb'
377
- - 'spec/suma/collection_config_spec.rb'
378
386
  - 'spec/suma/closure_validator_spec.rb'
387
+ - 'spec/suma/collection_config_spec.rb'
379
388
  - 'spec/suma/collection_manifest_spec.rb'
380
389
  - 'spec/suma/corpus_graph_spec.rb'
381
- - 'spec/suma/owl_projection_spec.rb'
382
- - 'spec/suma/schema_profile_spec.rb'
383
390
  - 'spec/suma/eengine_converter_spec.rb'
384
391
  - 'spec/suma/eengine_spec.rb'
385
392
  - 'spec/suma/express_reformatter_spec.rb'
386
393
  - 'spec/suma/express_schema_spec.rb'
394
+ - 'spec/suma/gcr_package_spec.rb'
387
395
  - 'spec/suma/jsdai/figure_spec.rb'
388
396
  - 'spec/suma/link_validation_spec.rb'
389
397
  - 'spec/suma/link_validator/step_spec.rb'
390
398
  - 'spec/suma/link_validator_spec.rb'
391
399
  - 'spec/suma/manifest_traverser_spec.rb'
392
400
  - 'spec/suma/note_processor_spec.rb'
393
- - 'spec/suma/publication_spec.rb'
401
+ - 'spec/suma/output_canonicalizer_spec.rb'
402
+ - 'spec/suma/owl_projection_spec.rb'
394
403
  - 'spec/suma/owl_projection_spec.rb'
395
404
  - 'spec/suma/processor_spec.rb'
405
+ - 'spec/suma/provenance_spec.rb'
406
+ - 'spec/suma/publication_spec.rb'
396
407
  - 'spec/suma/register_manifest_generator_spec.rb'
408
+ - 'spec/suma/reproducibility_spec.rb'
409
+ - 'spec/suma/schema_cache_spec.rb'
397
410
  - 'spec/suma/schema_category_spec.rb'
398
411
  - 'spec/suma/schema_comparer_integration_spec.rb'
412
+ - 'spec/suma/delivery/plan_spec.rb'
399
413
  - 'spec/suma/schema_compiler_spec.rb'
400
414
  - 'spec/suma/schema_discovery_spec.rb'
401
415
  - 'spec/suma/schema_exporter_spec.rb'
402
416
  - 'spec/suma/schema_index_spec.rb'
403
417
  - 'spec/suma/schema_naming_spec.rb'
418
+ - 'spec/suma/schema_profile_spec.rb'
404
419
  - 'spec/suma/schema_template_spec.rb'
420
+ - 'spec/suma/site_build_spec.rb'
405
421
  - 'spec/suma/site_config/config_spec.rb'
406
422
  - 'spec/suma/staged_collection_builder_spec.rb'
407
423
  - 'spec/suma/svg_quality/scanner_spec.rb'
408
424
  - 'spec/suma/term_classification_spec.rb'
409
425
  - 'spec/suma/term_extractor_spec.rb'
410
- - 'spec/suma/change_classification_spec.rb'
411
- - 'spec/suma/change_manifest_spec.rb'
412
- - 'spec/suma/change_impact_spec.rb'
426
+ - 'spec/suma/term_extractor_spec.rb'
427
+ - 'spec/suma/urn_resolver_spec.rb'
428
+ - 'spec/suma/worker_pool_spec.rb'
429
+ - 'spec/suma/delivery/frame_nav_spec.rb'
430
+ - 'spec/suma/delivery/site_verifier_spec.rb'
431
+ - 'spec/suma/delivery/stitcher_spec.rb'
432
+ - 'spec/suma/delivery/plan_spec.rb'
413
433
 
414
434
  # Offense count: 3
415
435
  # Configuration parameters: Max, AllowedGroups.
@@ -435,6 +455,7 @@ RSpec/SpecFilePathFormat:
435
455
  RSpec/StubbedMock:
436
456
  Exclude:
437
457
  - 'spec/suma/schema_comparer_integration_spec.rb'
458
+ - 'spec/suma/delivery/plan_spec.rb'
438
459
 
439
460
  # Offense count: 2
440
461
  # Configuration parameters: Max.
@@ -66,6 +66,11 @@ module Suma
66
66
  option :no_valid, type: :boolean, default: false,
67
67
  desc: "Skip Metanorma document validation " \
68
68
  "(equivalent of metanorma --no-valid)"
69
+ option :unresolved_eref_markers, type: :boolean, default: false,
70
+ desc: "Emit <span class=\"unresolved-eref\"> " \
71
+ "markers for cross-document erefs " \
72
+ "(isodoc 3.7.9+; consumed by the " \
73
+ "SRL stitcher)"
69
74
 
70
75
  def build(metanorma_site_manifest)
71
76
  unless File.exist?(metanorma_site_manifest)
@@ -95,6 +100,7 @@ module Suma
95
100
  sign_method: options[:sign],
96
101
  sign_key: options[:sign_key],
97
102
  no_valid: options[:no_valid],
103
+ unresolved_eref_markers: options[:unresolved_eref_markers],
98
104
  **staged_options(options),
99
105
  ).run
100
106
  end
data/lib/suma/cli/core.rb CHANGED
@@ -58,6 +58,9 @@ module Suma
58
58
  desc: "Signing key (sigstore signs keylessly when omitted)"
59
59
  option :no_valid, type: :boolean, default: false,
60
60
  desc: "Skip Metanorma document validation"
61
+ option :unresolved_eref_markers, type: :boolean, default: false,
62
+ desc: "Emit unresolved-eref span " \
63
+ "markers for the stitcher"
61
64
  def build(_site_manifest)
62
65
  Cli::Build.start
63
66
  end
@@ -183,6 +186,9 @@ module Suma
183
186
  desc "validate SUBCOMMAND ...ARGS", "Validate express documents"
184
187
  subcommand "validate", Cli::Validate
185
188
 
189
+ desc "srl SUBCOMMAND ...ARGS", "SRL delivery: stitch per-part bundles into one site"
190
+ subcommand "delivery", Cli::Delivery
191
+
186
192
  desc "resolve [URN]", "Resolve URNs to canonical JSON + HTML artifacts" # Mirrors so Core accepts the switches Cli::Resolve reparses; the
187
193
  # inner class owns their declarations.
188
194
  option :manifest, type: :string, required: true,
@@ -0,0 +1,129 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+ require "thor"
5
+
6
+ module Suma
7
+ module Cli
8
+ # Stitched-delivery commands (introduced for TCSC410303-2952): enumerate
9
+ # parts, merge independently rendered per-part bundles into one stitched
10
+ # site, resolve their unresolved cross-document references, and verify
11
+ # the result. Artifact names (SRL/SMRL/...) are corpus-side; this
12
+ # surface is name-neutral and driven by whatever manifests the caller
13
+ # points it at.
14
+ class Delivery < Thor
15
+ desc "verify SITE_DIR",
16
+ "Verify every link in the stitched site resolves: cross-file " \
17
+ "hrefs to files, fragments to anchors in their target. The " \
18
+ "production gate is zero broken links; exits 1 on any break. " \
19
+ "Intra-file fragment hrefs are reported but do not fail."
20
+ option :out, type: :string,
21
+ desc: "Also write the report as JSON to this path"
22
+ option :no_fragments, type: :boolean, default: false,
23
+ desc: "Skip fragment checking (file existence only)"
24
+
25
+ def verify(site_dir)
26
+ result = Suma::Delivery::SiteVerifier.new(site_dir,
27
+ **verify_options).verify
28
+ log_verify(result)
29
+ raise "broken links found (#{result.broken_count})" unless
30
+ result.broken_count.zero?
31
+ end
32
+
33
+ desc "stitch BUNDLES_DIR",
34
+ "Merge per-part bundles (each bundle.json + site/) into one " \
35
+ "_site/, resolving every unresolved-eref span through the " \
36
+ "anchor/doc/attachment registries; writes the audit records " \
37
+ "and the merged index"
38
+ option :plan, type: :string, required: true,
39
+ desc: "plan.json (part inventory: part_dir + doc_id " \
40
+ "per part)"
41
+ option :out, type: :string, required: true,
42
+ desc: "Output merged _site directory"
43
+ option :assets, type: :string,
44
+ desc: "Directory with srl_index.html, images/, sys/ " \
45
+ "frame-navigation assets"
46
+ option :inject, type: :string, banner: "PART_DIR",
47
+ desc: "Rebuilding one part: validate the " \
48
+ "link-signature invariants before stitching"
49
+ option :source_commit, type: :string,
50
+ desc: "Commit SHA recorded in build-info.json"
51
+ option :source_branch, type: :string,
52
+ desc: "Branch recorded in build-info.json"
53
+
54
+ def stitch(bundles_dir)
55
+ result = Suma::Delivery::Stitcher.new(**stitch_options(bundles_dir)).stitch
56
+ Utils.log "Stitched #{result.parts.size} into #{options[:out]}: " \
57
+ "#{result.resolved} ok, #{result.broken} broken"
58
+ end
59
+
60
+ desc "plan", "Enumerate parts from the collection manifest and " \
61
+ "write plan.json for the stitcher: per-part identity " \
62
+ "(iso_name, doc_id, year), input inventory, and " \
63
+ "doc/deps content hashes"
64
+ option :collection, type: :string, default: "collection-resources.yml",
65
+ desc: "Collection manifest listing one docref per " \
66
+ "part, relative to --repo-root"
67
+ option :repo_root, type: :string, default: ".",
68
+ desc: "Repository root"
69
+ option :out, type: :string, required: true,
70
+ desc: "Output plan.json path"
71
+
72
+ def plan
73
+ result = Suma::Delivery::Plan.new(**plan_options).generate
74
+ Utils.log "Planned #{result['parts_count']} parts " \
75
+ "from #{result['source_collection']}"
76
+ end
77
+
78
+ desc "frame-nav SITE_DIR", "Post-process a stitched site for " \
79
+ "frame navigation: strip the index chrome, " \
80
+ "build the top-level index, wire onclick " \
81
+ "index links, inject the frameset script, " \
82
+ "and add target attributes"
83
+ def frame_nav(site_dir)
84
+ Suma::Delivery::FrameNav.new(site_dir).process
85
+ Utils.log "Frame navigation applied to #{site_dir}"
86
+ end
87
+
88
+ private
89
+
90
+ def verify_options
91
+ { check_fragments: !options[:no_fragments] }
92
+ end
93
+
94
+ def log_verify(result)
95
+ report = result.report
96
+ write_report(report) if options[:out]
97
+ Utils.log "Links: #{report['total_links']} total, " \
98
+ "#{report['broken_links'].size} broken; " \
99
+ "fragments: #{report['total_fragments']} total, " \
100
+ "#{report['broken_fragments'].size} broken; " \
101
+ "#{report['cross_document_links']} cross-document"
102
+ end
103
+
104
+ def write_report(report)
105
+ File.write(options[:out], JSON.pretty_generate(report))
106
+ end
107
+
108
+ def stitch_options(bundles_dir)
109
+ {
110
+ bundles_dir: bundles_dir,
111
+ plan_path: options[:plan],
112
+ out_dir: options[:out],
113
+ assets_dir: options[:assets],
114
+ inject: options[:inject],
115
+ source_commit: options[:source_commit],
116
+ source_branch: options[:source_branch],
117
+ }
118
+ end
119
+
120
+ def plan_options
121
+ {
122
+ repo_root: options[:repo_root],
123
+ collection: options[:collection],
124
+ out: options[:out],
125
+ }
126
+ end
127
+ end
128
+ end
129
+ end
data/lib/suma/cli.rb CHANGED
@@ -12,6 +12,7 @@ module Suma
12
12
  autoload :ExtractTerms, "suma/cli/extract_terms"
13
13
  autoload :GenerateRegister, "suma/cli/generate_register"
14
14
  autoload :GenerateSchemas, "suma/cli/generate_schemas"
15
+ autoload :Delivery, "suma/cli/delivery"
15
16
  autoload :IngestTranslations, "suma/cli/ingest_translations"
16
17
  autoload :PackageGcr, "suma/cli/package_gcr"
17
18
  autoload :Reformat, "suma/cli/reformat"
@@ -0,0 +1,173 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "leptris"
4
+
5
+ module Suma
6
+ module Delivery
7
+ # Frame-navigation delivery postprocess (port of suma2srl.py): turns a
8
+ # stitched site into the SRL frameset presentation.
9
+ #
10
+ # - index.html: strip Attachments, unwrap collection/document nesting,
11
+ # flatten the doc list, wire onclick handlers that drive the
12
+ # index+info frames, and add the frameset redirect script.
13
+ # - every document index file: target="info" on all links.
14
+ # - every section file: inject the CSS override suppressing
15
+ # metanorma's built-in sidebar (the left frame replaces it) with
16
+ # the DRAFT watermark. Idempotent on re-runs.
17
+ class FrameNav
18
+ # A faithful port: the constants carry the Python payload verbatim
19
+ # and the metrics would fragment the pipeline without clarifying it.
20
+ # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Layout/LineLength
21
+ FRAMESET_JS = 'if(window.self===window.top)window.location.replace("srl_index.html");else window.addEventListener("pageshow",function(){try{parent.index.location="sys/frame_toc_short.htm"}catch(e){}});'
22
+
23
+ CSS_OVERRIDE = '<style>nav{display:none !important}#toggle{display:none !important}body{margin-left:2em !important}body::after{content:"DRAFT";position:fixed;top:50%;left:50%;transform:translate(-50%,-50%) rotate(-45deg);font-size:8em;font-weight:bold;font-family:sans-serif;color:rgba(200,200,200,0.3);pointer-events:none;z-index:9999;}</style>'
24
+
25
+ PREVIOUS_OVERRIDE_RE = %r{<style>nav\{display:none !important\}.*?</style>}m
26
+ PREVIOUS_TOGGLE_RE = %r{<div id="toggle">\s*<span>[^<]*</span>\s*</div>}m
27
+
28
+ def initialize(site_dir)
29
+ @site_dir = Pathname.new(site_dir)
30
+ end
31
+
32
+ def process
33
+ top_level = process_index
34
+ add_target_attributes(top_level)
35
+ strip_metanorma_sidebar
36
+ top_level
37
+ end
38
+
39
+ private
40
+
41
+ # -- index.html ---------------------------------------------------
42
+
43
+ def process_index
44
+ path = @site_dir / "index.html"
45
+ doc = Leptris::XML.parse_html(path.read)
46
+ strip_index_chrome(doc)
47
+ top_level = build_top_level(doc)
48
+ wire_index_links(doc, top_level)
49
+ inject_frameset_script(doc)
50
+ path.write(doc.to_html)
51
+ top_level
52
+ end
53
+
54
+ def strip_index_chrome(doc)
55
+ # Decompose the element containing the "Attachments" text: the
56
+ # raw index nests the whole schema-exp attachment list inside that
57
+ # <li>, so subtree removal drops all of it (Python decompose).
58
+ doc.xpath("//text()[contains(., 'Attachments')]")
59
+ .each { |t| t.parent.remove }
60
+ # Unwrap two levels above every anchor text naming the collection
61
+ # wrappers ("ISO Collection"/"Document"), then drop the text: the
62
+ # per-document subtrees collapse into the flat list the frameset
63
+ # nav expects. (Text-substring match, doc order, exactly like the
64
+ # Python phase.)
65
+ doc.xpath("//text()[contains(., 'ISO Collection') or " \
66
+ "contains(., 'Document')]").each do |t|
67
+ unwrap(t.parent.parent) if t.parent&.parent
68
+ unwrap(t.parent) if t.parent
69
+ t.parent&.remove_child(t)
70
+ end
71
+ doc.xpath("//text()[contains(., 'STEP Resources Library')]")
72
+ .each { |t| t.parent.remove_child(t) }
73
+ doc.css("nav a").each do |a|
74
+ next unless a.parent&.parent&.name == "ul"
75
+
76
+ unwrap(a.parent.parent)
77
+ unwrap(a.parent)
78
+ end
79
+ end
80
+
81
+ # Replace the node with its children (BeautifulSoup's unwrap).
82
+ def unwrap(node)
83
+ node.children.each { |c| node.add_previous_sibling(c) }
84
+ node.parent.remove_child(node)
85
+ end
86
+
87
+ # href -> the first page of that document (for the onclick target).
88
+ # Single-file documents map to themselves; index files map to the
89
+ # first <a href> inside them, prefixed with the href's subdirectory.
90
+ def build_top_level(doc)
91
+ top_level = {}
92
+ doc.css("a").each do |a|
93
+ href = a["href"]
94
+ top_level[href] = href if href
95
+ end
96
+ top_level.each_key do |href|
97
+ next unless File.basename(href).end_with?("_index.html")
98
+
99
+ top_level[href] = first_page_of(href) || href
100
+ end
101
+ top_level
102
+ end
103
+
104
+ def first_page_of(href)
105
+ doc_path = @site_dir / href
106
+ return nil unless doc_path.exist?
107
+
108
+ first = Leptris::XML.parse_html(doc_path.read).at_css("a[href]")
109
+ return nil unless first
110
+
111
+ subdir = File.dirname(href)
112
+ subdir == "." ? first["href"] : "#{subdir}/#{first['href']}"
113
+ end
114
+
115
+ def wire_index_links(doc, top_level)
116
+ doc.css("a").each do |a|
117
+ href = a["href"]
118
+ next unless href && top_level.key?(href)
119
+
120
+ a["onclick"] =
121
+ if File.basename(href).end_with?("_index.html")
122
+ # Multi-section docs drive both frames; replace() avoids a
123
+ # second history entry so back needs one click.
124
+ "parent.index.location.replace('#{href}');" \
125
+ "parent.info.location='#{top_level[href]}';return false;"
126
+ else
127
+ "parent.info.location='#{top_level[href]}'"
128
+ end
129
+ end
130
+ end
131
+
132
+ def inject_frameset_script(doc)
133
+ # Idempotent: drop previously injected scripts first.
134
+ doc.xpath("//script").each do |s|
135
+ s.parent.remove_child(s) if s.text.include?("window.top")
136
+ end
137
+ head = doc.at_css("head") || doc.at_css("html").prepend_child("<head/>")
138
+ script = doc.create_element("script")
139
+ script.content = FRAMESET_JS
140
+ head.add_child(script)
141
+ end
142
+
143
+ # -- document index files ------------------------------------------
144
+
145
+ def add_target_attributes(top_level)
146
+ top_level.each_key do |href|
147
+ next unless File.basename(href).end_with?("_index.html")
148
+
149
+ doc_path = @site_dir / href
150
+ next unless doc_path.exist?
151
+
152
+ doc = Leptris::XML.parse_html(doc_path.read)
153
+ doc.css("a").each { |a| a["target"] = "info" }
154
+ doc_path.write(doc.to_html)
155
+ end
156
+ end
157
+
158
+ # -- section files ---------------------------------------------------
159
+
160
+ def strip_metanorma_sidebar
161
+ Dir.glob("#{@site_dir}/**/*_section_*.html").each do |file|
162
+ content = File.read(file)
163
+ updated = content
164
+ .gsub(PREVIOUS_OVERRIDE_RE, "")
165
+ .gsub(PREVIOUS_TOGGLE_RE, "")
166
+ .sub("</head>", "#{CSS_OVERRIDE}</head>")
167
+ File.write(file, updated) if updated != content
168
+ end
169
+ end
170
+ # rubocop:enable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Layout/LineLength
171
+ end
172
+ end
173
+ end