public void RenderEventsAsHtml(ZonelessEventStore es, StringBuilder builder, Dictionary<string,object> args)
{
if (args == null)
args = new Dictionary<string, object>();
args["hub_tags"] = es.hub_tags; // so the event renderer can exclude these
bool bare_events = args.HasValue("bare_events", true);
//bool mobile = args.ContainsKey("mobile") && (bool)args["mobile"] == true;
var event_renderer = new EventRenderer(RenderEvtAsHtml);
var year_month_anchors = new List<string>(); // e.g. ym201201
var day_anchors = new List<string>(); // e.g. d20120119
var current_time_of_day = TimeOfDay.Initialized;
var sources_dict = new Dictionary<string, int>();
int sequence_position = 0;
bool sequence_at_zero = true;
string last_source_key = null;
string current_date_key = null;
var announce_time_of_day = args.HasValue("announce_time_of_day", true) && ! args.HasValue("bare_events",true);
BuildSourcesDict(es, announce_time_of_day, sources_dict);
foreach (ZonelessEvent evt in es.events)
{
string datekey = Utils.DateKeyFromDateTime(evt.dtstart);
var event_builder = new StringBuilder();
var year_month_anchor = datekey.Substring(1, 6);
if (! year_month_anchors.Exists(ym => ym == year_month_anchor) )
{
builder.Append(string.Format("\n<a name=\"ym{0}\"></a>\n", year_month_anchor));
year_month_anchors.Add(year_month_anchor);
}
if (! day_anchors.Exists(d => d == datekey))
{
event_builder.Append(string.Format("\n<a name=\"{0}\"></a>\n", datekey));
var date = Utils.DateFromDateKey(datekey);
event_builder.Append(string.Format("<h1 id=\"{0}\" class=\"ed\"><b>{1}</b></h1>\n", datekey, date));
day_anchors.Add(datekey);
sequence_at_zero = true;
}
if (announce_time_of_day)
{
var time_of_day = Utils.ClassifyTime(evt.dtstart);
if (time_of_day != current_time_of_day || datekey != current_date_key) // see http://blog.jonudell.net/2009/06/18/its-the-headings-stupid/
{
current_date_key = datekey;
current_time_of_day = time_of_day;
event_builder.Append(string.Format("<h2 id=\"t{0}\" class=\"timeofday\">{1}</h2>", this.time_of_day_counter, time_of_day.ToString()));
this.time_of_day_counter += 1;
sequence_at_zero = true;
}
}
var source_key = MakeSourceKey(current_time_of_day, datekey, evt);
if (source_key != last_source_key)
{
sequence_at_zero = true;
last_source_key = source_key;
}
if (sequence_at_zero)
{
sequence_position = 1;
sequence_at_zero = false;
}
else
sequence_position++;
if (evt.urls_and_sources.Count == 1) // else multiple coalesced sources, nothing to hide
{
args["source_key"] = source_key;
args["sequence_count"] = sources_dict[source_key];
args["sequence_position"] = sequence_position;
}
AppendEvent(event_builder, event_renderer, evt, args );
builder.Append(event_builder);
}
}