かんたん作成【HTML CSS JavaScript PHP CGI Perl Ruby Python .htaccess】

カレンダー

#! /usr/local/bin/ruby

today = Time.now

startday = Time.local(today.year, today.month, 1)            # 今月1日の曜日
days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
days[1] += 1 if today.month == 2 and                    # うるう年
        (today.year % 4 == 0 and today.year % 100 != 0 or today.year % 400 == 0)
endday = days[today.month - 1]                        # 今月最後の日

print "Content-type: text/html; charset=Shift_JIS\n\n"
print <<END
    <html>
    <head>
    <title>#{today.year}年#{today.month}月カレンダー</title>
    </head>
    <body>
    <table border="2" bordercolor="#000099" cellspacing="0" cellpadding="5">
    <tr>
        <th colspan="7">
            #{today.year}<span style="font-size:xx-small">年</span>#{today.month}<span style="font-size:xx-small">月</span>
        </th>
    </tr>
    <tr>
        <td align="center" style="font-size:xx-small;color:red">日</td>
        <td align="center" style="font-size:xx-small">月</td>
        <td align="center" style="font-size:xx-small">火</td>
        <td align="center" style="font-size:xx-small">水</td>
        <td align="center" style="font-size:xx-small">木</td>
        <td align="center" style="font-size:xx-small">金</td>
        <td align="center" style="font-size:xx-small;color:blue">土</font></td>
    </tr>
END

count = 0
i = 0
while i < startday.wday                        # 1日までの空欄
    print "<tr>" if count % 7 == 0
    print "<td> </td>"
    count += 1
    i += 1
end
i = 1
while i <= endday                        # 日付を書き込む
    print "<tr>" if count % 7 == 0
    print "<td align=\"right\""
    print " bgcolor=\"#ddffdd\"" if i == today.day
    print " style=\"color:red\"" if count % 7 == 0
    print " style=\"color:blue\"" if count % 7 == 6
    print ">"
    print i
    print "</td>"
    count += 1
    print "</tr>\n" if count % 7 == 0
    i += 1
end
while count % 7 != 0                        # 最後の日からの空欄
    print "<td> </td>"
    count += 1
    print "</tr>\n" if count % 7 == 0
end

print <<END
    </table>
    </body>
    </html>
END

exit
CGI(Ruby)
Hello world ! ユーザーエージェント取得・表示(ENV['HTTP_USER_AGENT'])
IPアドレス取得・表示(ENV['REMOTE_ADDR']) リンク元取得・表示(ENV['HTTP_REFERER'])
URL取得・表示(ENV['HTTP_HOST'], ENV['REQUEST_URI']) 環境変数一覧(ENV.each)
日時を取得・表示(Time.now) 指定の日までの日数を表示
時刻によって挨拶文を変える 日によって背景色を変える
見るたびに背景色を変える 見るたびに背景画像を変える
おみくじ(rand) カラーチャート
グラフ(横棒グラフ) アクセスカウンター
アクセスカウンター(画像) 訪問回数(クッキー)
パスワード認証 クッションページ(ENV['QUERY_STRING'])
クッションページ(ENV['PATH_INFO']) カレンダー
カレンダー(今年1月〜12月) カレンダー(今年1月〜12月, 前年次年リンク付)
掲示板 ディレクトリ内ファイル一覧表示
リダイレクト(Location) 条件指定リダイレクト(Location)
条件指定アクセス拒否(ステータスコードを返す) HTMLファイル読み込み・表示
HTMLファイル読み込み・パスワード認証 HTMLファイル読み込み・条件指定アクセス拒否
HTMLファイル読み込み・条件指定リダイレクト 外部CGIファイル読み込み(require)
画像ファイル読み込み・表示
かんたん作成【HTML CSS JavaScript PHP CGI Perl Ruby Python .htaccess】