Class: Diary

Inherits:
Object
  • Object
show all
Includes:
TDiary::BaseDiary, TDiary::UncategorizableDiary
Defined in:
lib/tdiary/io/pstore.rb

Overview

Diary class

Management a day of diary

Instance Method Summary collapse

Constructor Details

#initialize(date, title, body) ⇒ Diary



139
140
141
142
# File 'lib/tdiary/io/pstore.rb', line 139

def initialize( date, title, body )
  init_diary
  replace( date, title, body )
end

Instance Method Details

#append(body, author = nil) ⇒ Object



155
156
157
158
159
160
161
162
# File 'lib/tdiary/io/pstore.rb', line 155

def append( body, author = nil )
  body.gsub( /\r/, '' ).split( /\n\n+/ ).each do |fragment|
    paragraph = Paragraph::new( fragment, author )
    @paragraphs << paragraph if paragraph
  end
  @last_modified = Time::now
  self
end

#each_sectionObject



164
165
166
167
168
# File 'lib/tdiary/io/pstore.rb', line 164

def each_section
  @paragraphs.each do |paragraph|
    yield paragraph
  end
end

#replace(date, title, body) ⇒ Object



148
149
150
151
152
153
# File 'lib/tdiary/io/pstore.rb', line 148

def replace( date, title, body )
  set_date( date )
  set_title( title )
  @paragraphs = []
  append( body )
end

#styleObject



144
145
146
# File 'lib/tdiary/io/pstore.rb', line 144

def style
  'tDiary'
end

#to_chtml(opt) ⇒ Object



220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
# File 'lib/tdiary/io/pstore.rb', line 220

def to_chtml( opt )
  idx = 0
  r = ''
  each_section do |paragraph|
    if paragraph.subtitle then
      r << %Q[<P><A NAME="p#{'%02d' % idx += 1}">*</A> #{paragraph.subtitle}</P>]
    end
    if /^</ =~ paragraph.body then
      idx += 1
      r << paragraph.body
    elsif paragraph.subtitle
      r << %Q[<P>#{paragraph.body.collect{|l|l.chomp.sub( /^[  ]/u, '' )}.join( "</P>\n<P>" )}</P>]
    else
      r << %Q[<P><A NAME="p#{'%02d' % idx += 1}">*</A> ]
      if opt['multi_user'] and paragraph.author then
        r << %Q|[#{paragraph.author}]|
      end
      r << %Q[#{paragraph.body.collect{|l|l.chomp.sub( /^[  ]/u, '' )}.join( "</P>\n<P>" )}</P>]
    end
  end
  r
end

#to_html(opt, mode = :HTML) ⇒ Object



178
179
180
181
182
183
184
185
# File 'lib/tdiary/io/pstore.rb', line 178

def to_html( opt, mode = :HTML )
  case mode
  when :CHTML
    to_chtml( opt )
  else
    to_html4( opt )
  end
end

#to_html4(opt) ⇒ Object



187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/tdiary/io/pstore.rb', line 187

def to_html4( opt )
  idx = 1
  r = ''
  each_section do |paragraph|
    r << %Q[<div class="section">\n]
    if paragraph.subtitle then
      r << %Q[<h3><a ]
      if opt['anchor'] then
        r << %Q[name="p#{'%02d' % idx}" ]
      end
      r << %Q[href="#{opt['index']}<%=anchor "#{@date.strftime( '%Y%m%d' )}#p#{'%02d' % idx}" %>">#{opt['section_anchor']}</a> ]
      if opt['multi_user'] and paragraph.author then
        r << %Q|[#{paragraph.author}]|
      end
      r << %Q[#{paragraph.subtitle}</h3>]
    end
    if /^</ =~ paragraph.body then
      r << %Q[#{paragraph.body}]
    elsif paragraph.subtitle
      r << %Q[<p>#{paragraph.body.collect{|l|l.chomp.sub( /^[  ]/u, '' )}.join( "</p>\n<p>" )}</p>]
    else
      r << %Q[<p><a ]
      if opt['anchor'] then
        r << %Q[name="p#{'%02d' % idx}" ]
      end
      r << %Q[href="#{opt['index']}<%=anchor "#{@date.strftime( '%Y%m%d' )}#p#{'%02d' % idx}" %>">#{opt['section_anchor']}</a> #{paragraph.body.collect{|l|l.chomp.sub( /^[  ]/u, '' )}.join( "</p>\n<p>" )}</p>]
    end
    r << %Q[</div>]
    idx += 1
  end
  r
end

#to_sObject



243
244
245
# File 'lib/tdiary/io/pstore.rb', line 243

def to_s
  "date=#{@date.strftime('%Y%m%d')}, title=#{@title}, body=[#{@paragraphs.join('][')}]"
end

#to_srcObject



170
171
172
173
174
175
176
# File 'lib/tdiary/io/pstore.rb', line 170

def to_src
  src = ''
  each_section do |para|
    src << para.to_src
  end
  src
end