kat revised this gist 8 hours ago. Go to revision
1 file changed, 20 insertions, 9 deletions
tabref.rb
| @@ -2,14 +2,13 @@ | |||
| 2 | 2 | ||
| 3 | 3 | require "cgi" | |
| 4 | 4 | cgi = CGI.new | |
| 5 | + | tabdir = "/home/kat/Documents/Git/-mine/tabref/tabs/*.txt" | |
| 5 | 6 | ||
| 6 | 7 | puts "Content-Type: text/html" | |
| 7 | 8 | puts "" | |
| 8 | 9 | ||
| 9 | 10 | # HTML structure | |
| 10 | 11 | ||
| 11 | - | divider = "<hr>\n\n" | |
| 12 | - | ||
| 13 | 12 | html_head = <<-EOF | |
| 14 | 13 | <!DOCTYPE html> | |
| 15 | 14 | <html lang="en"> | |
| @@ -27,23 +26,35 @@ html_head = <<-EOF | |||
| 27 | 26 | EOF | |
| 28 | 27 | ||
| 29 | 28 | html_header = <<-EOF | |
| 30 | - | <header id="title-block-header"> | |
| 31 | - | <h1 id="title p-name">guitar tab quick ref :D</h1> | |
| 32 | - | </header> | |
| 29 | + | <header id="title-block-header"> | |
| 30 | + | <h1 id="title p-name">guitar tab quick ref :D</h1> | |
| 31 | + | </header> | |
| 32 | + | <hr> | |
| 33 | 33 | EOF | |
| 34 | 34 | ||
| 35 | 35 | # display HTML content | |
| 36 | 36 | ||
| 37 | - | puts "<main class=\"h-entry\">" | |
| 38 | 37 | puts "#{html_head}" | |
| 38 | + | puts "<main class=\"h-entry\">" | |
| 39 | 39 | puts "#{html_header}" | |
| 40 | 40 | ||
| 41 | - | files = Dir["/home/kat/Documents/Git/-mine/tabref/tabs/*.txt"].each do |tab| | |
| 42 | - | fname = "#{File.basename(tab)}" | |
| 41 | + | puts "<h2 id=\"toc\">table of contents</h2>" | |
| 42 | + | puts "<ol>" | |
| 43 | + | files_toc = Dir[tabdir].each do |tab| | |
| 44 | + | fname = "#{File.basename(tab, ".*")}" | |
| 45 | + | html_toc = "<li><a href=\"##{fname}\">#{fname}</a></li>" | |
| 46 | + | ||
| 47 | + | puts "#{html_toc}" | |
| 48 | + | end | |
| 49 | + | puts "</ol>" | |
| 50 | + | puts "<hr>" | |
| 51 | + | ||
| 52 | + | files = Dir[tabdir].each do |tab| | |
| 53 | + | fname = "#{File.basename(tab, ".*")}" | |
| 43 | 54 | fcontent = "#{File.read(tab)}" | |
| 44 | 55 | ||
| 45 | 56 | html_body = <<-EOF | |
| 46 | - | <h2 id="#{fname}">"#{fname}" (<a href=\"##{fname}\">link</a>)</h2> | |
| 57 | + | <h3 id="#{fname}">"#{fname}" (<a href=\"##{fname}\">link</a>)</h3> | |
| 47 | 58 | ||
| 48 | 59 | <pre>"#{fcontent}"</pre> | |
| 49 | 60 | ||
kat revised this gist 8 hours ago. Go to revision
1 file changed, 55 insertions
tabref.rb(file created)
| @@ -0,0 +1,55 @@ | |||
| 1 | + | #!/usr/bin/env ruby | |
| 2 | + | ||
| 3 | + | require "cgi" | |
| 4 | + | cgi = CGI.new | |
| 5 | + | ||
| 6 | + | puts "Content-Type: text/html" | |
| 7 | + | puts "" | |
| 8 | + | ||
| 9 | + | # HTML structure | |
| 10 | + | ||
| 11 | + | divider = "<hr>\n\n" | |
| 12 | + | ||
| 13 | + | html_head = <<-EOF | |
| 14 | + | <!DOCTYPE html> | |
| 15 | + | <html lang="en"> | |
| 16 | + | <head> | |
| 17 | + | <title>guitar tab quick ref</title> | |
| 18 | + | ||
| 19 | + | <meta name="author" content="kat, girl on the moon"> | |
| 20 | + | <meta name="description" content="why do you look so blue?"> | |
| 21 | + | ||
| 22 | + | <meta charset="UTF-8"> | |
| 23 | + | <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| 24 | + | ||
| 25 | + | <link rel="stylesheet" href="../assets/main.css"> | |
| 26 | + | </head> | |
| 27 | + | EOF | |
| 28 | + | ||
| 29 | + | html_header = <<-EOF | |
| 30 | + | <header id="title-block-header"> | |
| 31 | + | <h1 id="title p-name">guitar tab quick ref :D</h1> | |
| 32 | + | </header> | |
| 33 | + | EOF | |
| 34 | + | ||
| 35 | + | # display HTML content | |
| 36 | + | ||
| 37 | + | puts "<main class=\"h-entry\">" | |
| 38 | + | puts "#{html_head}" | |
| 39 | + | puts "#{html_header}" | |
| 40 | + | ||
| 41 | + | files = Dir["/home/kat/Documents/Git/-mine/tabref/tabs/*.txt"].each do |tab| | |
| 42 | + | fname = "#{File.basename(tab)}" | |
| 43 | + | fcontent = "#{File.read(tab)}" | |
| 44 | + | ||
| 45 | + | html_body = <<-EOF | |
| 46 | + | <h2 id="#{fname}">"#{fname}" (<a href=\"##{fname}\">link</a>)</h2> | |
| 47 | + | ||
| 48 | + | <pre>"#{fcontent}"</pre> | |
| 49 | + | ||
| 50 | + | <hr> | |
| 51 | + | EOF | |
| 52 | + | puts "#{html_body}" | |
| 53 | + | end | |
| 54 | + | ||
| 55 | + | puts "</main>" | |