百科.dev
全部条目AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
H

has_calendar

> 编程语言
开源

一个使用表格创建日历的视图辅助工具。您可以轻松添加任何内容的事件。

100 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

一个使用表格创建日历的视图辅助工具。您可以轻松添加任何内容的事件。

has_calendar

has_calendar is a view helper that creates a calendar using a table. You can easily add events with any content.

This plugin relies on the cal command, available on *nix systems. Instead of calculating dates, I parse the output.

NOTE: Only on Mac OS X (Unix?) the first day of week is Sunday; Linux (tested on Ubuntu) uses the argument -m, starting on Monday.

Want this to work on Windows systems? Make sure you have a command cal on your PATH that returns exactly the *nix output (haven't tested though).

Instalation

  1. Install the plugin with script/plugin install git://github.com/fnando/has_calendar.git

Usage

 2008, :month => 9 %>

or, if you want to register some events:

 2008, :month => 9 do |date| %>

As you can see, this will hit your database up to 31 times (one hit for each day) if you don't optimize it. Fortunately, you can use the options :events:

 Schedule.all do |date, events| %>

By default, each record will use the created_at attribute as date grouping. You can specify a different attribute with the option :field:

 Schedule.all, :field => :scheduled_at do |date, events| %>

By default, has_calendar will look for a date format called :day\_of\_week to use on the header of the calendar, you can change it using the :header_format option:

     :short_day_name %>

You can also change the caption provided by has_calendar (that defaults to the :default format):

     :short_day_name, :caption_format => :month_year %>

To set formats do something like this:

Date::DATE_FORMATS[:short_day_name] = '%a' # => (Sun..Sat)

Or on your locale file, if your application is internationalized.

You can set the HTML id: 'cal' %>

Formatting the calendar

You can use this CSS to start:

#calendar {
	border-collapse: collapse;
	width: 100%;
}

#calendar td,
#calendar th {
	color: #ccc;
	font-family: "Lucida Grande",arial,helvetica,sans-serif;
	font-size: 10px;
	padding: 6px;
}

#calendar th {
	border: 1px solid #ccc;
	background: #ccc;
	color: #666;
	text-align: left;
}

#calendar td {
	background: #f0f0f0;
	border: 1px solid #ddd;
}

#calendar span {
	display: block;
}

#calendar td.events {
	background: #fff;
}

#calendar td.today {
	background: #ffc;
	color: #666;
}

#calendar caption {
  display: none;
}

TO-DO

  • Write some specs as soon as possible!

Contributors

  • Carlos Júnior (xjunior)

Copyright (c) 2008 Nando Vieira, released under the MIT license

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Ruby

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言