releasehx 0.1.2 → 0.2.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.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/README.adoc +363 -330
  3. data/build/docs/_config.yml +1 -0
  4. data/build/docs/_release_index.adoc +3 -2
  5. data/build/docs/config-reference.adoc +197 -10
  6. data/build/docs/config-reference.json +56 -7
  7. data/build/docs/index.adoc +315 -59
  8. data/build/docs/landing.adoc +1 -1
  9. data/build/docs/manpage.adoc +2 -2
  10. data/build/docs/release-procedure.adoc +365 -0
  11. data/build/docs/release-procedure.html +87 -0
  12. data/build/docs/releasehx.1 +17 -5
  13. data/build/docs/sample-config.yml +14 -7
  14. data/lib/releasehx/cli.rb +5 -2
  15. data/lib/releasehx/configuration.rb +0 -1
  16. data/lib/releasehx/generated.rb +1 -1
  17. data/lib/releasehx/mcp/assets/agent-config-guide.md +1 -1
  18. data/lib/releasehx/mcp/assets/config-def.yml +122 -6
  19. data/lib/releasehx/mcp/assets/config-reference.adoc +197 -10
  20. data/lib/releasehx/mcp/assets/config-reference.json +56 -7
  21. data/lib/releasehx/mcp/assets/sample-config.yml +14 -7
  22. data/lib/releasehx/mcp/server.rb +0 -1
  23. data/lib/releasehx/ops/enrich_ops.rb +161 -55
  24. data/lib/releasehx/ops/template_ops.rb +1 -1
  25. data/lib/releasehx/rhyml/adapter.rb +0 -3
  26. data/lib/releasehx/rhyml/templates/bootstrap-overrides.css +15 -0
  27. data/lib/releasehx/rhyml/templates/changelog.adoc.liquid +2 -0
  28. data/lib/releasehx/rhyml/templates/changelog.html.liquid +6 -4
  29. data/lib/releasehx/rhyml/templates/changelog.md.liquid +1 -0
  30. data/lib/releasehx/rhyml/templates/embedded.css.liquid +263 -0
  31. data/lib/releasehx/rhyml/templates/entry.adoc.liquid +1 -0
  32. data/lib/releasehx/rhyml/templates/entry.html.liquid +21 -20
  33. data/lib/releasehx/rhyml/templates/entry.md.liquid +15 -21
  34. data/lib/releasehx/rhyml/templates/head-parser.liquid +6 -2
  35. data/lib/releasehx/rhyml/templates/header.liquid +13 -4
  36. data/lib/releasehx/rhyml/templates/history.html.liquid +152 -33
  37. data/lib/releasehx/rhyml/templates/metadata-entry.adoc.liquid +83 -38
  38. data/lib/releasehx/rhyml/templates/metadata-entry.html.liquid +60 -1
  39. data/lib/releasehx/rhyml/templates/metadata-entry.md.liquid +65 -113
  40. data/lib/releasehx/rhyml/templates/metadata-note.adoc.liquid +83 -38
  41. data/lib/releasehx/rhyml/templates/metadata-note.html.liquid +59 -22
  42. data/lib/releasehx/rhyml/templates/metadata-note.md.liquid +68 -23
  43. data/lib/releasehx/rhyml/templates/note.html.liquid +25 -19
  44. data/lib/releasehx/rhyml/templates/note.md.liquid +44 -26
  45. data/lib/releasehx/rhyml/templates/release-notes.adoc.liquid +2 -0
  46. data/lib/releasehx/rhyml/templates/release-notes.html.liquid +6 -4
  47. data/lib/releasehx/rhyml/templates/release-notes.md.liquid +1 -0
  48. data/lib/releasehx/rhyml/templates/release.adoc.liquid +2 -0
  49. data/lib/releasehx/rhyml/templates/release.md.liquid +8 -7
  50. data/lib/releasehx/rhyml/templates/rhyml-change.yaml.liquid +36 -36
  51. data/lib/releasehx/rhyml/templates/wrapper.html.liquid +103 -0
  52. data/lib/releasehx/sgyml/helpers.rb +0 -2
  53. data/lib/releasehx/transforms/adf_to_markdown.rb +1 -1
  54. data/lib/releasehx/version.rb +0 -2
  55. data/lib/releasehx.rb +2 -2
  56. data/specs/data/config-def.yml +122 -6
  57. metadata +48 -25
  58. data/build/docs/schemagraphy_readme.html +0 -0
  59. data/build/docs/sourcerer_readme.html +0 -46
  60. data/lib/schemagraphy/attribute_resolver.rb +0 -48
  61. data/lib/schemagraphy/cfgyml/definition.rb +0 -90
  62. data/lib/schemagraphy/cfgyml/doc_builder.rb +0 -52
  63. data/lib/schemagraphy/cfgyml/path_reference.rb +0 -24
  64. data/lib/schemagraphy/data_query/json_pointer.rb +0 -42
  65. data/lib/schemagraphy/loader.rb +0 -59
  66. data/lib/schemagraphy/regexp_utils.rb +0 -235
  67. data/lib/schemagraphy/safe_expression.rb +0 -189
  68. data/lib/schemagraphy/schema_utils.rb +0 -124
  69. data/lib/schemagraphy/tag_utils.rb +0 -32
  70. data/lib/schemagraphy/templating.rb +0 -104
  71. data/lib/schemagraphy.rb +0 -17
  72. data/lib/sourcerer/builder.rb +0 -120
  73. data/lib/sourcerer/jekyll/bootstrapper.rb +0 -78
  74. data/lib/sourcerer/jekyll/liquid/file_system.rb +0 -74
  75. data/lib/sourcerer/jekyll/liquid/filters.rb +0 -215
  76. data/lib/sourcerer/jekyll/liquid/tags.rb +0 -44
  77. data/lib/sourcerer/jekyll/monkeypatches.rb +0 -73
  78. data/lib/sourcerer/jekyll.rb +0 -26
  79. data/lib/sourcerer/plaintext_converter.rb +0 -75
  80. data/lib/sourcerer/templating.rb +0 -190
  81. data/lib/sourcerer.rb +0 -322
data/lib/sourcerer.rb DELETED
@@ -1,322 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # This module is a pre-alpha version of what I will eventually spin off
4
- # as AsciiSourcery, for single-sourcing documentation AND product data
5
- # in AsciiDoc and YAML files
6
- # It is pretty messy for now as I play around with various ways it might
7
- # get used, including as a build-time generator of artifacts to be used
8
- # in both the app and the docs
9
-
10
- require 'asciidoctor'
11
- require 'fileutils'
12
- require 'yaml'
13
- require_relative 'sourcerer/builder'
14
- require_relative 'sourcerer/plaintext_converter'
15
- require_relative 'sourcerer/templating'
16
- require_relative 'sourcerer/jekyll'
17
- require_relative 'schemagraphy'
18
-
19
- # A tool for single-sourcing documentation and data from AsciiDoc and YAML files.
20
- # It provides methods for extracting data, rendering templates, and generating various outputs.
21
- module Sourcerer
22
- # Loads AsciiDoc attributes from a document header as a Hash.
23
- #
24
- # @param path [String] The path to the AsciiDoc file.
25
- # @return [Hash] A hash of the document attributes.
26
- def self.load_attributes path
27
- doc = Asciidoctor.load_file(path, safe: :unsafe)
28
- doc.attributes
29
- end
30
-
31
- # Loads a snippet from an AsciiDoc file using an `include::` directive.
32
- #
33
- # @param path_to_main_adoc [String] The path to the main AsciiDoc file.
34
- # @param tag [String] A single tag to include.
35
- # @param tags [Array<String>] An array of tags to include.
36
- # @param leveloffset [Integer] The level offset for the include.
37
- # @return [String] The content of the included snippet.
38
- def self.load_include path_to_main_adoc, tag: nil, tags: [], leveloffset: nil
39
- opts = []
40
- opts << "tag=#{tag}" if tag
41
- opts << "tags=#{tags.join(',')}" if tags.any?
42
- opts << "leveloffset=#{leveloffset}" if leveloffset
43
-
44
- snippet_doc = <<~ADOC
45
- include::#{path_to_main_adoc}[#{opts.join(', ')}]
46
- ADOC
47
-
48
- doc = Asciidoctor.load(
49
- snippet_doc,
50
- safe: :unsafe,
51
- base_dir: File.expand_path('.'),
52
- header_footer: false,
53
- attributes: { 'source-highlighter' => nil }) # disable extras
54
-
55
- # Get raw text from all top-level blocks
56
- doc.blocks.map(&:content).join("\n")
57
- end
58
-
59
- # Extracts tagged content from a file.
60
- #
61
- # @param path_to_tagged_adoc [String] The path to the file with tagged content.
62
- # @param tag [String] A single tag to extract.
63
- # @param tags [Array<String>] An array of tags to extract.
64
- # @param comment_prefix [String] The prefix for comment lines.
65
- # @param comment_suffix [String] The suffix for comment lines.
66
- # @param skip_comments [Boolean] Whether to skip comment lines in the output.
67
- # @return [String] The extracted content.
68
- # rubocop:disable Lint/UnusedMethodArgument
69
- def self.extract_tagged_content path_to_tagged_adoc, tag: nil, tags: [], comment_prefix: '// ', comment_suffix: '',
70
- skip_comments: false
71
- # rubocop:enable Lint/UnusedMethodArgument
72
- # NOTE: comment_suffix parameter is currently unused but kept for future functionality
73
- raise ArgumentError, 'tag and tags cannot coexist' if tag && !tags.empty?
74
-
75
- tags = [tag] if tag
76
- raise ArgumentError, 'at least one tag must be specified' if tags.empty?
77
- raise ArgumentError, 'tags must all be strings' unless tags.is_a?(Array) && tags.all? { |t| t.is_a?(String) }
78
-
79
- tagged_content = []
80
- open_tags = {}
81
- tag_comment_prefix = comment_prefix.strip || '//'
82
- tag_pattern = /^#{Regexp.escape(tag_comment_prefix)}\s*tag::([\w-]+)\[\]/
83
- end_pattern = /^#{Regexp.escape(tag_comment_prefix)}\s*end::([\w-]+)\[\]/
84
- comment_line_init_pattern = /^#{Regexp.escape(tag_comment_prefix)}+/
85
- collecting = false
86
- File.open(path_to_tagged_adoc, 'r') do |file|
87
- file.each_line do |line|
88
- # check for tag:: line
89
- if line =~ tag_pattern
90
- tag_name = Regexp.last_match(1)
91
- if tags.include?(tag_name)
92
- collecting = true
93
- open_tags[tag_name] = true
94
- end
95
- elsif line =~ end_pattern
96
- tag_name = Regexp.last_match(1)
97
- if open_tags[tag_name]
98
- open_tags.delete(tag_name)
99
- collecting = false if open_tags.empty?
100
- end
101
- elsif collecting
102
- tagged_content << line unless skip_comments && line =~ comment_line_init_pattern
103
- end
104
- end
105
- tagged_content = if tagged_content.empty?
106
- ''
107
- else
108
- # return a string of concatenated lines
109
- tagged_content.join
110
- end
111
- end
112
-
113
- tagged_content
114
- end
115
-
116
- # Generates a manpage from an AsciiDoc source file.
117
- #
118
- # @param source_adoc [String] The path to the source AsciiDoc file.
119
- # @param target_manpage [String] The path to the target manpage file.
120
- def self.generate_manpage source_adoc, target_manpage
121
- FileUtils.mkdir_p File.dirname(target_manpage)
122
- Asciidoctor.convert_file(
123
- source_adoc,
124
- backend: 'manpage',
125
- safe: :unsafe,
126
- standalone: true,
127
- to_file: target_manpage)
128
- end
129
-
130
- # Renders a set of templates based on a configuration.
131
- #
132
- # @param templates_config [Array<Hash>] An array of template configurations.
133
- def self.render_templates templates_config
134
- render_outputs(templates_config)
135
- end
136
-
137
- # Renders templates or converter outputs based on a configuration.
138
- #
139
- # @param render_config [Array<Hash>] A list of render configurations.
140
- def self.render_outputs render_config
141
- return if render_config.nil? || render_config.empty?
142
-
143
- render_config.each do |render_entry|
144
- if render_entry[:converter]
145
- render_with_converter(render_entry)
146
- next
147
- end
148
-
149
- data_obj = render_entry[:key] || 'data'
150
- attrs_source = render_entry[:attrs]
151
- engine = render_entry[:engine] || 'liquid'
152
-
153
- render_template(
154
- render_entry[:template],
155
- render_entry[:data],
156
- render_entry[:out],
157
- data_object: data_obj,
158
- attrs_source: attrs_source,
159
- engine: engine)
160
- end
161
- end
162
-
163
- # Renders a single template with data.
164
- #
165
- # @param template_file [String] The path to the template file.
166
- # @param data_file [String] The path to the data file (YAML).
167
- # @param out_file [String] The path to the output file.
168
- # @param data_object [String] The name of the data object in the template.
169
- # @param includes_load_paths [Array<String>] Paths for Liquid includes.
170
- # @param attrs_source [String] The path to an AsciiDoc file for attributes.
171
- # @param engine [String] The template engine to use.
172
- def self.render_template template_file, data_file, out_file, data_object: 'data', includes_load_paths: [],
173
- attrs_source: nil, engine: 'liquid'
174
- data = load_render_data(data_file, attrs_source)
175
- out_file = File.expand_path(out_file)
176
- FileUtils.mkdir_p(File.dirname(out_file))
177
-
178
- template_path = File.expand_path(template_file)
179
- template_content = File.read(template_path)
180
-
181
- # Prepare context
182
- context = {
183
- data_object => data,
184
- 'include' => { data_object => data } # for compatibility with {% include ... %} expecting include.var
185
- }
186
-
187
- rendered = case engine.to_s
188
- when 'erb' then render_erb(template_content, context)
189
- when 'liquid' then render_liquid(template_file, template_content, context, includes_load_paths)
190
- else raise ArgumentError, "Unsupported template engine: #{engine}"
191
- end
192
-
193
- File.write(out_file, rendered)
194
- end
195
-
196
- def self.render_with_converter render_entry
197
- data_file = render_entry[:data]
198
- out_file = render_entry[:out]
199
- raise ArgumentError, 'render entry missing :data' unless data_file
200
- raise ArgumentError, 'render entry missing :out' unless out_file
201
-
202
- data = load_render_data(data_file, render_entry[:attrs])
203
- converter = resolve_converter(render_entry[:converter])
204
- rendered = converter.call(data, render_entry)
205
- raise ArgumentError, 'converter returned non-string output' unless rendered.is_a?(String)
206
-
207
- out_file = File.expand_path(out_file)
208
- FileUtils.mkdir_p(File.dirname(out_file))
209
- File.write(out_file, rendered)
210
- end
211
-
212
- def self.load_render_data data_file, attrs_source
213
- if attrs_source
214
- attrs = load_attributes(attrs_source)
215
- SchemaGraphy::Loader.load_yaml_with_attributes(data_file, attrs)
216
- else
217
- SchemaGraphy::Loader.load_yaml_with_tags(data_file)
218
- end
219
- end
220
-
221
- def self.resolve_converter converter
222
- return converter if converter.respond_to?(:call)
223
- return Object.const_get(converter) if converter.is_a?(String)
224
-
225
- raise ArgumentError, "Unsupported converter: #{converter.inspect}"
226
- end
227
-
228
- def self.render_erb template_content, context
229
- require 'erb'
230
- ERB.new(template_content, trim_mode: '-').result_with_hash(context)
231
- end
232
-
233
- def self.render_liquid template_file, template_content, context, includes_load_paths
234
- require_relative 'sourcerer/jekyll'
235
- require_relative 'sourcerer/jekyll/liquid/filters'
236
- require_relative 'sourcerer/jekyll/liquid/tags'
237
- require 'liquid' unless defined?(Liquid::Template)
238
- Sourcerer::Jekyll.initialize_liquid_runtime
239
-
240
- # Determine includes root; add template directory to search paths
241
- fallback_templates_dir = File.expand_path('.', Dir.pwd)
242
- template_dir = File.dirname(File.expand_path(template_file))
243
- # For templates that use includes like cfgyml/config-property.adoc.liquid,
244
- # we need the parent directory of the template's directory as well
245
- template_parent_dir = File.dirname(template_dir)
246
-
247
- paths = if includes_load_paths.any?
248
- includes_load_paths
249
- else
250
- [template_parent_dir, template_dir, fallback_templates_dir]
251
- end
252
-
253
- # Create a fake Jekyll site
254
- site = Sourcerer::Jekyll::Bootstrapper.fake_site(
255
- includes_load_paths: paths,
256
- plugin_dirs: [])
257
-
258
- # Setup file system for includes with multiple paths
259
- file_system = Sourcerer::Jekyll::Liquid::FileSystem.new(paths)
260
-
261
- template = Liquid::Template.parse(template_content)
262
- options = {
263
- registers: {
264
- site: site,
265
- file_system: file_system
266
- }
267
- }
268
- template.render(context, options)
269
- end
270
-
271
- # Extracts commands from listing and literal blocks with a specific role.
272
- #
273
- # @param file_path [String] The path to the AsciiDoc file.
274
- # @param role [String] The role to look for.
275
- # @return [Array<String>] An array of command groups.
276
- def self.extract_commands file_path, role: 'testable'
277
- doc = Asciidoctor.load_file(file_path, safe: :unsafe)
278
- command_groups = []
279
- current_group = []
280
-
281
- blocks = doc.find_by(context: :listing) + doc.find_by(context: :literal)
282
-
283
- blocks.each do |block|
284
- next unless block.has_role?(role)
285
-
286
- commands = process_block_content(block.content)
287
- if block.has_role?('testable-newshell')
288
- command_groups << current_group.join("\n") unless current_group.empty?
289
- command_groups << commands.join("\n") unless commands.empty?
290
- current_group = []
291
- else
292
- current_group.concat(commands)
293
- end
294
- end
295
-
296
- command_groups << current_group.join("\n") unless current_group.empty?
297
- command_groups
298
- end
299
-
300
- # @api private
301
- # Processes the content of a block to extract commands.
302
- # It handles line continuations and skips comments.
303
- # @param content [String] The content of the block.
304
- # @return [Array<String>] An array of commands.
305
- def self.process_block_content content
306
- processed_commands = []
307
- current_command = ''
308
- content.each_line do |line|
309
- stripped_line = line.strip
310
- next if stripped_line.start_with?('#') # Skip comments
311
-
312
- if stripped_line.end_with?('\\')
313
- current_command += "#{stripped_line.chomp('\\')} "
314
- else
315
- current_command += stripped_line
316
- processed_commands << current_command unless current_command.empty?
317
- current_command = ''
318
- end
319
- end
320
- processed_commands
321
- end
322
- end