Skip to content

Instantly share code, notes, and snippets.

@nishimotz
Created October 14, 2009 14:11
Show Gist options
  • Save nishimotz/210100 to your computer and use it in GitHub Desktop.
Save nishimotz/210100 to your computer and use it in GitHub Desktop.
simple file download page generator
#!/usr/bin/ruby -Ku
# simple file download page generator
# 2009-02-03 by nishimoto
# 2009-10-14 gist version
# [files.txt]
# * : h2
# - : text
# otherwise : link to file
require "erb"
require "cgi"
title = "!!page title here!!"
files = File.open("files.txt").readlines
str = <<"EOS"
<html>
<head>
<link rel="stylesheet" type="text/css" href="pc.css" />
<title>#{title}</title>
</head>
<body>
<h1>#{title}</h1>
<ul>
<% files.each do |i| %>
<% if i[0...1] == '*' %>
</ul><h2><%= i[1..-1] %></h2><ul>
<% elsif i[0...1] == '-' %>
</ul><p><%= i[1..-1] %></p><ul>
<% else %>
<li><a href="<%= i %>"><%= i %></a></li>
<% end %>
<% end %>
</ul>
<hr />
contact : username [atmark] domain.name
<br />
<a href="../index.html">back</a>
</body>
</html>
EOS
puts CGI.new.header("text/html; charset=utf-8")
puts ERB.new(str).result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment