# -*- coding: utf-8; -*- # # pstoreio.rb: tDiary IO class of tdiary 1.x format. # # Copyright (C) 2001-2005, TADA Tadashi # You can redistribute it and/or modify it under GPL2 or any later version. # require 'pstore' module TDiary module IO class PStore def initialize( tdiary ) @data_path = tdiary.conf.data_path end # # block must be return boolean which dirty diaries. # def transaction( date ) diaries = {} filename = date.strftime( "#{@data_path}%Y%m" ) begin PStore::new( filename ).transaction do |db| dirty = false if db.root?( 'diary' ) then diaries.update( db['diary'] ) end dirty = yield( diaries ) if iterator? if dirty != TDiary::TDiaryBase::DIRTY_NONE then db['diary'] = diaries else db.abort end end rescue PStore::Error, NameError, Errno::EACCES raise PermissionError::new( "make your @data_path to writable via httpd. #$!" ) end begin File::delete( filename ) if diaries.empty? rescue Errno::ENOENT end return diaries end def calendar calendar = {} Dir["#{@data_path}??????"].sort.each do |file| year, month = file.scan( %r[/(\d{4})(\d\d)$] )[0] next unless year calendar[year] = [] unless calendar[year] calendar[year] << month end calendar end def diary_factory( date, title, body, style = nil ) Diary::new( date, title, body ) end end end end =begin == class Comment Management a comment. =end class Comment attr_reader :name, :mail, :body, :date def initialize( name, mail, body, date = Time::now ) @name, @mail, @body, @date = name, mail, body, date @show = true end def shorten( len = 120 ) lines = NKF::nkf( "-e -m0 -f#{len}", @body.gsub( /\n/, ' ' ) ).split( /\n/ ) lines[0].concat( '..' ) if lines[0] and lines[1] lines[0] || '' end def visible?; @show; end def show=( s ); @show = s; end def ==( c ) (@name == c.name) and (@mail == c.mail) and (@body == c.body) end end =begin == Paragraph class Management a paragraph. =end class Paragraph attr_reader :subtitle, :body alias :body_to_html :body alias :subtitle_to_html :subtitle def initialize( fragment, author = nil ) @author = author lines = fragment.split( /\n+/ ) if lines.size > 1 then if /^<\n] if paragraph.subtitle then r << %Q[

">#{opt['section_anchor']} ] if opt['multi_user'] and paragraph.author then r << %Q|[#{paragraph.author}]| end r << %Q[#{paragraph.subtitle}

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

\n

" )}

] else r << %Q[

">#{opt['section_anchor']} #{paragraph.body.collect{|l|l.chomp.sub( /^[  ]/u, '' )}.join( "

\n

" )}

] end r << %Q[] idx += 1 end r end def to_chtml( opt ) idx = 0 r = '' each_section do |paragraph| if paragraph.subtitle then r << %Q[

* #{paragraph.subtitle}

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

\n

" )}

] else r << %Q[

* ] if opt['multi_user'] and paragraph.author then r << %Q|[#{paragraph.author}]| end r << %Q[#{paragraph.body.collect{|l|l.chomp.sub( /^[  ]/u, '' )}.join( "

\n

" )}

] end end r end def to_s "date=#{@date.strftime('%Y%m%d')}, title=#{@title}, body=[#{@paragraphs.join('][')}]" end end # Local Variables: # mode: ruby # indent-tabs-mode: t # tab-width: 3 # ruby-indent-level: 3 # End: