Created
July 12, 2020 01:47
-
-
Save ayosec/7e40f7e4f2790a3890e57f50a5169cfb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require "erb" | |
require "etc" | |
if ARGV.empty? | |
puts "Usage: #$0 files... > output.html" | |
exit 1 | |
end | |
Job = Struct.new(:file, :child) | |
MAX_JOBS = Etc.nprocessors | |
JOBS = [] | |
puts <<~HEAD | |
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
HEAD | |
def wait_job(job) | |
puts "<h1><tt>#{ERB::Util.h job.file}</tt></h1>" | |
while data = job.child.read(1024) | |
print data | |
end | |
Process.waitpid(job.child.pid) | |
end | |
while file = ARGV.shift | |
while JOBS.size >= MAX_JOBS | |
wait_job(JOBS.shift) | |
end | |
child = IO.popen(%W( | |
pygmentize | |
-f html | |
-O nobackground,noclasses,linenos=inline | |
#{file} | |
)) | |
JOBS << Job.new(file, child) | |
end | |
while job = JOBS.shift | |
wait_job(job) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment