# -*- tcl-*-
# $Id$
::xowiki::Object new -title "News" -text {
  #
  # A sample News object.
  #
  my initialize -parameter {
    {-page_size:integer 100}
    {-page_number:integer 1}
    {-summary:boolean 0}
    {-date ""}
    {-tag ""}
    {-ptag ""}
    {-entries_of en:announcement-talk|en:announcement-workshop}
  }

  #
  # The following definition is the default rendering per 
  # news entry. This is executed in the context of every displayed page.
  #
  Class create IcalEntryRenderer -instproc render {} {
    array set {} [my instance_attributes]
    array set event $(event)
    #my msg [my instance_attributes]
    set dtstart  [::xo::ical clock_to_utc [clock scan $event(event.dtstart)]]
    set dtend    [::xo::ical clock_to_utc [clock scan $event(event.dtend)]]
    set body     "SUMMARY:[::xo::ical text_to_ical -remove_tags true $event(event.summary)]"
    foreach f {location} {
      set key event(event.$f)
      if {[info exists $key] && [set $key] ne ""} {
        append body \n[string toupper $f]:[::xo::ical text_to_ical -remove_tags true [set $key]]
      }
    }

    return [subst {BEGIN:VEVENT
DTSTART:$dtstart
DTEND:$dtend
$body
URL:[my pretty_link -absolute true]
END:VEVENT
}]
  }

  #
  # The following definition is the renderer for the aggregated content.
  # This is executed in the context of the whole weblog object
  #
  Class create IcalRenderer -instproc render {} {
    return [subst {BEGIN:VCALENDAR
VERSION:2.0
[next]END:VCALENDAR
}]
}
  
  my proc content {} {
    my get_parameters
    #
    # this is not a HTML page, decativate master and provide content-type
    # 
    ::xo::cc set_parameter master 0
    ::xo::cc set_parameter content-type text/plain

    # use the above defined custom renderers
    set renderer       [self]::IcalRenderer
    set entry_renderer [self]::IcalEntryRenderer 
    
    set w [::xowiki::Weblog new -destroy_on_cleanup \
               -package_id $package_id \
               -page_size $page_size \
               -page_number $page_number \
               -summary $summary \
               -date $date \
               -category_id [ns_queryget category_id] \
               -tag $tag \
               -ptag $ptag \
               -entry_renderer $entry_renderer \
               -entry_flag __no_form_page_footer \
               -entries_of $entries_of \
              ]

    $w set __page [my info parent]
    $w mixin add $renderer
    return [$w render]
  }
  
}



