Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-doc
Path: blob/main/website/tools/releases-toml.rb
18081 views
1
#!/usr/bin/env ruby
2
3
=begin
4
5
BSD 2-Clause License
6
Copyright (c) 2020-2026, The FreeBSD Project
7
Copyright (c) 2020-2026, Sergio Carlavilla <[email protected]>
8
9
This script converts common variables sourced from shared/releases.adoc
10
to the toml format and stores them in data/releases.toml
11
12
=end
13
14
def getValueByKey(key, variables)
15
return variables.fetch(key.gsub("{", "").gsub("}", "")).gsub("\"", "")
16
end
17
18
def mapVariables(path)
19
variables = Hash.new
20
21
File.foreach(path).with_index do |line|
22
if line.match("^:{1}[^\n]+")
23
variable = line.strip.sub(":", '')
24
variable = variable.sub(": ", "=\"")
25
variable << "\""
26
data = variable.split("=")
27
28
if data.length == 2
29
variables.store(data[0], data[1])
30
end
31
end
32
end
33
34
return variables
35
end
36
37
# Main method
38
releasesTOMLFile = File.new("./data/releases.toml", "w")
39
40
releasesTOMLFile.puts("# Code @" + "generated by the FreeBSD Documentation toolchain. DO NOT EDIT.\n")
41
releasesTOMLFile.puts("# Please don't change this file manually but run `make` to update it.\n")
42
releasesTOMLFile.puts("# For more information, please read the FreeBSD Documentation Project Primer\n")
43
releasesTOMLFile.puts("\n")
44
45
variables = mapVariables("./shared/releases.adoc")
46
47
variables.each do |key, value|
48
49
if keyToFind = value.match("\{.*?\}")
50
releasesTOMLFile.puts(key + "=" + value.gsub(keyToFind[0], getValueByKey(keyToFind[0], variables)) + "\n")
51
else
52
releasesTOMLFile.puts(key + "=" + value + "\n")
53
end
54
55
end
56
57
58