Browse files

moved templates to sickounter.rb, added support for specifying counte…

…rs directory
  • Loading branch information...
1 parent 29b887c commit b8b29ace5e79974ffa305f2c61847e28abdbcb84 @sickill committed Mar 22, 2009
Showing with 43 additions and 38 deletions.
  1. +43 −2 sickounter.rb
  2. +0 −20 views/layout.erb
  3. +0 −16 views/stats.erb
View
45 sickounter.rb
@@ -1,13 +1,12 @@
require 'rubygems'
require 'sinatra'
-COUNTERS_DIR = File.join(File.dirname(__FILE__), 'counters')
+COUNTERS_DIR = ARGV[0] || File.join(File.dirname(__FILE__), 'counters')
get '/' do
url = params[:f] or raise Sinatra::NotFound
filename = url.gsub(/https?:\/\//, "").gsub(/[^a-zA-Z0-9_-]/, ".") + ".txt"
path = File.join(COUNTERS_DIR, filename)
- puts path
val = (File.read(path).strip.to_i rescue 0) + 1
File.open(path, "w") do |f|
f.flock(File::LOCK_EX)
@@ -24,3 +23,45 @@
end
erb :stats
end
+
+__END__
+
+@@stats
+<h1>Sickounter download statistics</h1>
+
+<div id="main">
+<table class="wide">
+ <tr>
+ <th>File</th>
+ <th class="dl">Downloads</th>
+ </tr>
+ <% @downloads.keys.sort_by { |counter| -@downloads[counter] }.each do |counter| %>
+ <tr>
+ <td><%= counter %></td>
+ <td><%= @downloads[counter] %></td>
+ </tr>
+ <% end %>
+</table>
+</div>
+
+@@layout
+<html>
+<head>
+ <title>Sickounter download statistics</title>
+ <style>
+ body { background-color: white; color: black; font: 8pt Verdana }
+ th { background-color: #789 }
+ tr th { font-weight: bold; text-align: left; color: white }
+ td, th { padding: 10px }
+ td { border-right: 1px solid #ccc; border-bottom: 1px solid #ccc }
+ div#main { margin: 0 auto; text-align: center; width: 800px }
+ table { border-left: 1px solid #ccc; border-bottom: 2px solid #ccc; border-spacing:0; }
+ table.wide { width: 100% }
+ th.dl { width: 50px }
+ h1 { text-align: center; margin-bottom: 60px }
+ </style>
+</head>
+<body>
+<%= yield %>
+</body>
+</html>
View
20 views/layout.erb
@@ -1,20 +0,0 @@
-<html>
-<head>
- <title>Sickounter download statistics</title>
- <style>
- body { background-color: white; color: black; font: 8pt Verdana }
- th { background-color: #789 }
- tr th { font-weight: bold; text-align: left; color: white }
- td, th { padding: 10px }
- td { border-right: 1px solid #ccc; border-bottom: 1px solid #ccc }
- div#main { margin: 0 auto; text-align: center; width: 800px }
- table { border-left: 1px solid #ccc; border-bottom: 2px solid #ccc; border-spacing:0; }
- table.wide { width: 100% }
- th.dl { width: 50px }
- h1 { text-align: center; margin-bottom: 60px }
- </style>
-</head>
-<body>
-<%= yield %>
-</body>
-</html>
View
16 views/stats.erb
@@ -1,16 +0,0 @@
-<h1>Sickounter download statistics</h1>
-
-<div id="main">
-<table class="wide">
- <tr>
- <th>File</th>
- <th class="dl">Downloads</th>
- </tr>
- <% @downloads.keys.sort_by { |counter| -@downloads[counter] }.each do |counter| %>
- <tr>
- <td><%= counter %></td>
- <td><%= @downloads[counter] %></td>
- </tr>
- <% end %>
-</table>
-</div>

0 comments on commit b8b29ac

Please sign in to comment.