Calendar Package
Introduction The package is based on the Calendar class, a class capable of printing an ascii calendar table that closely resembles the output of the typical Unix cal command. The internal code is written entirely in Tcl, therefore doesn't rely on the existance of cal on the system. XmlCalendar inherits the basic methods and adds XML tagging to the table. XmlCalendar prints an XML calendar table whose header, weekdays banner and days rows tags are configurable. Also specific days or specific weeks can be given arbitrary attributes. Calendar core methods are based on the cal procedure written by Richard Suchenwirth and published on the Tcl Wiki The Calendar package uses Tcl dict command to manage markup information. Hence either Tcl8.5 or Tcl8.4 with package dict are required.
Calendar Utility class the builds and prints a calendar table Calendar calendar_name Calendar object subcommands The main public command for a calendar object is emit that returns a calendar table calendar_obj emit calendar_obj emit month year calendar_obj emit month | year The method 'emit' if invoked without arguments returns an ASCII formatted calendar of the current month set cal [Calendar #auto] set current_month [$cal emit] puts $current_month Jun 2010 Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 The method emit when invoked with a single argument takes it as an year number and prints the whole calendar of that year. When invoked with 2 arguments takes the first as a month, either expressed in its shortened form ('Jan','Feb',...) or as a number in the range 1-12. The second argument is a year number. XmlCalendar Prints XML formatted calendar tables XmlCalendar calendar_name -option1 option_list -option2 option_list ... An XmlCalendar object is created and returned. XmlCalendar objects print XML formatted calendar tables. The markup can be customized using the configuration options. Configuration options accept odd-length lists as values. An option_list has the following structure tag_name The first element of an option list is a tag name, the remaining terms are therefore an even-length sublist which is interpreted as a sequence of attribute-value pairs that will in turn become attributes of the tag. Methods cal_obj emit cal_obj emit month year cal_obj emit month | year The method 'emit' if invoked without arguments returns an XML calendar table of the current month Options -container tag_name Assigns an options list to the XML element that will hold the whole table. The default tag for the container is 'calendar', with no attributes. -header tag_name Assigns tag name and attributes to the XML header element (default: calheader) -body tag_name Assigns tag name and attributes to the XML body element of the table (default: calbody) -banner tag_name Assigns tag name and attributes to the XML banner element of the table (default: monthyear) The header of a calendar table is made of a banner, showing the Month and Year number, and of a weekdays bar. -foot tag_name Assigns tag name and attributes to the XML foot element of the table (default: calfoot). This option was added for completeness, but it's not implemented yet -banner_month tag_name Tag name and attributes for the XML element holding the month name (default:month) -banner_year tag_name Tag name and attributes for the XML element holding the month name (default: year) -weekdays tag_name Tag name and attributes for the XML element holding the weekday header (default: weekdays) -weekdays_cell tag_name Tag name and attributes for the XML element holding the each single weekday (default: wkdays) -days_row tag_name Tag name and attributes for the XML element holding the each row of the calendar table (default: week) -days_cell tag_name Tag name and attributes for the XML element representing a cell in the calendar table (default: day) -cell_function If set this option is the name of a procedure that gets called for every day of the month. The procedure must accept 4 argument representing day, month, year and weekday and must return an odd-length list interpreted in the same way as options lists. -current_day This option works as a simple method for pointing out a specific day of the month. If set with a day number that day will get the class attribute automatically set as "current" -current_weekday This option works as a simple method for pointing out a specific weekday of the month. If set with a weekday index (0: Sunday, 6: Saturday) the corresponding cell in the weekdays header will get the class attribute automatically set as "current_wkday" HtmlCalendar Concrete class derived from XmlCalendar HtmlCalendar calendar_name -option1 option_list -option2 option_list ... Concrete XmlCalendar class for printing html calendar tables. The markup of the class is xhtml compliant and prints a code fragment for inclusion in a webpage. The following is the class definition. ::itcl::class HtmlCalendar { inherit XmlCalendar constructor {args} {XmlCalendar::constructor $args} { $this configure -container table \ -header thead \ -body tbody \ -banner tr \ -banner_month {th colspan 3 style "text-align: right;"} \ -banner_year {th colspan 4 style "text-align: left;"} \ -weekdays tr \ -weekday_cell th \ -days_row tr \ -days_cell td } } A sample output from HtmlCalendar (with some styling)