Skip to content

Commit

Permalink
support/docs: Add package entries converter tool
Browse files Browse the repository at this point in the history
  • Loading branch information
samueldr committed Sep 22, 2023
1 parent cf828ce commit bc22edc
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
62 changes: 62 additions & 0 deletions support/docs/converter/packages.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/usr/bin/env ruby

require_relative "lib"

require "json"

$level = 2

begin
unused = []
while opt = ARGV.shift
case opt
when /^--level/
$level = ARGV.shift.to_i
when /^-/
$stderr.puts "Unexepected parameter: #{opt}"
exit 2
else
unused << opt
end
end

if unused.length < 3 then
$stderr.puts "Usage: main.rb <template_dir> <packages.json> <page.md|page.html>"
exit 1
end

$template_dir = unused.shift
$packagesJSON = unused.shift
$output_file = unused.shift
end

packages = JSON.parse(File.read($packagesJSON))

packages = packages.to_a.sort do |a, b|
a.first <=> b.first
end

out = File.open($output_file, "a")

$template = ERB.new(File.read(File.join($template_dir, "package.erb")))

packages.each do |pair|
attrname, data = pair
next unless data["entry_type"] == "package"

data["h_name"] = "h#{$level}"
data["h_package"] = "h#{$level+1}"
data["attrname"] = attrname
#data["declaration"] = data["declarations"].first
#data["description"] = MarkdownDocument.new(data["description"]).to_html

blurb = $template.result_with_hash(data)

# Strip leading spaces because markdown will interpret as code even though it's within HTML
blurb =
blurb
.strip
.gsub(/^\s+/, "")

out.puts(blurb)
end
3 changes: 3 additions & 0 deletions support/docs/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ let
--namespace jovian.steam --level 3 \
${./template} ${optionsJSONFile} src/steam.md
ruby ${./converter}/packages.rb \
${./template} ${overlayJSONFile} src/packages.md
ruby ${./converter}/main.rb \
--fixups ${./fixups.rb} \
${./template} src/ $out/
Expand Down

0 comments on commit bc22edc

Please sign in to comment.