# # tdiary_style.rb: tDiary style class for tDiary 2.x format. $Revision: 1.16 $ # # if you want to use this style, add @style into tdiary.conf below: # # @style = 'tDiary' # # Copyright (C) 2001-2005, TADA Tadashi # You can redistribute it and/or modify it under GPL2 or any later version. # module TDiary module Style class TdiarySection attr_reader :subtitle, :body, :author attr_reader :categories, :stripped_subtitle alias :subtitle_to_html :subtitle alias :stripped_subtitle_to_html :stripped_subtitle def initialize( fragment, author = nil ) @author = author lines = fragment.split( /\n+/ ) if lines.size > 1 then if /^<#{p}

" end html end def to_s "subtitle=#{@subtitle}, body=#{@body}" end def categorized_subtitle @categories.collect do |c| %Q|<%= category_anchor("#{c}") %>| end.join + @stripped_subtitle.to_s end private def get_categories return [] unless @subtitle cat = /^(\[(.*?)\])+/.match(@subtitle).to_a[0] return [] unless cat cat.scan(/\[(.*?)\]/).collect do |c| c[0].split(/,/) end.flatten end def strip_subtitle return nil unless @subtitle @subtitle.sub( /^(\[(.*?)\])+\s*/, '' ) end end class TdiaryDiary def initialize( date, title, body, modified = Time::now ) init_diary replace( date, title, body ) @last_modified = modified end def style 'tDiary' end def append( body, author = nil ) body.gsub( /\r/, '' ).split( /\n\n+/ ).each do |fragment| section = TdiarySection::new( fragment, author ) @sections << section if section end @last_modified = Time::now self end def add_section(subtitle, body) sec = TdiarySection::new("\n\n ") sec.subtitle = subtitle sec.body = body @sections << sec @sections.size end def to_html4( opt ) r = '' each_section do |section| r << %Q[
\n] r << %Q[<%= section_enter_proc( Time::at( #{date.to_i} ) ) %>\n] if section.subtitle then r << %Q[

<%= subtitle_proc( Time::at( #{date.to_i} ), #{section.subtitle.dump.gsub( /%/, '\\\\045' )} ) %>

\n] end if /^#{section.body.lines.collect{|l|l.chomp.sub( /^[  ]/u, '')}.join( "

\n

" )}

\n] else r << %Q[

<%= subtitle_proc( Time::at( #{date.to_i} ), nil ) %>] r << %Q[#{section.body.lines.collect{|l|l.chomp.sub( /^[  ]/u, '' )}.join( "

\n

" )}

] end r << %Q[<%= section_leave_proc( Time::at( #{date.to_i} ) ) %>\n] r << %Q[
] end r end def to_chtml( opt ) r = '' each_section do |section| r << %Q[<%= section_enter_proc( Time::at( #{date.to_i} ) ) %>\n] if section.subtitle then r << %Q[

<%= subtitle_proc( Time::at( #{date.to_i} ), #{section.subtitle.dump.gsub( /%/, '\\\\045' )} ) %>

\n] end if /^#{section.body.lines.collect{|l|l.chomp.sub( /^[  ]/u, '' )}.join( "

\n

" )}

\n] else r << %Q[

<%= subtitle_proc( Time::at( #{date.to_i} ), nil ) %>] r << %Q[#{section.body.lines.collect{|l|l.chomp.sub( /^[  ]/u, '' )}.join( "

\n

" )}

\n] end r << %Q[<%= section_leave_proc( Time::at( #{date.to_i} ) ) %>\n] end r end end end end # Local Variables: # mode: ruby # indent-tabs-mode: t # tab-width: 3 # ruby-indent-level: 3 # End: