Class: TDiary::TDiaryLatest
- Inherits:
-
TDiaryView
- Object
- TDiaryBase
- TDiaryView
- TDiary::TDiaryLatest
- Defined in:
- lib/tdiary/view.rb
Overview
class TDiaryLatest
show latest mode view
Constant Summary
Constants inherited from TDiaryBase
TDiary::TDiaryBase::DIRTY_COMMENT, TDiary::TDiaryBase::DIRTY_DIARY, TDiary::TDiaryBase::DIRTY_NONE, TDiary::TDiaryBase::DIRTY_REFERER
Instance Attribute Summary
Attributes inherited from TDiaryBase
#cgi, #conf, #cookies, #date, #diaries, #ignore_parser_cache, #rhtml
Instance Method Summary collapse
-
#initialize(cgi, rhtml, conf) ⇒ TDiaryLatest
constructor
A new instance of TDiaryLatest.
- #latest(limit = 5) ⇒ Object
Methods inherited from TDiaryView
Methods inherited from TDiaryBase
#[], #calendar, #eval_rhtml, #last_modified
Methods included from ViewHelper
Constructor Details
#initialize(cgi, rhtml, conf) ⇒ TDiaryLatest
Returns a new instance of TDiaryLatest.
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 |
# File 'lib/tdiary/view.rb', line 318 def initialize( cgi, rhtml, conf ) super if @cgi.params['date'][0] then ym = [@cgi.params['date'][0][0,4].to_i, @cgi.params['date'][0][4,2].to_i] @date = nil else ym = latest_month end unless @date then @date = ym ? Time::local( ym[0], ym[1] ) : Time::now @io.transaction( @date ) do |diaries| @diaries = diaries if @cgi.params['date'][0] then @diary = @diaries[@cgi.params['date'][0][0,8]] @date = @diary.date if @diary end unless @diary then @diaries.keys.sort.reverse_each do |d| diary = @diaries[d] if diary.visible? @diary = diary break end end @diary = @diaries[@diaries.keys.sort.reverse[0]] unless @diary @date = @diary.date if @diary end DIRTY_NONE end end if ym then # read +2 days for calc ndays.prev in count_diaries method limit = limit_size( @conf.latest_limit ) + 2 # read next month data until limit y = ym[0].to_i m = ym[1].to_i latest = latest_month diaries_tmp = {}.update( @diaries ) diaries_size = count_diaries_after( diaries_tmp ) while ( latest and diaries_size < limit ) date = if m == 12 then Time::local( y += 1, m = 1 ) else Time::local( y, m += 1 ) end break if date > Time::local( *latest ) @io.transaction( date ) do |diaries| diaries_tmp.update( diaries ) diaries_size = count_diaries_after( diaries_tmp ) DIRTY_NONE end end # read prev month data until limit y = ym[0].to_i m = ym[1].to_i oldest = oldest_month diaries_size = count_diaries_before( @diaries ) while ( oldest and diaries_size < limit ) date = if m == 1 then Time::local( y -= 1, m = 12 ) else Time::local( y, m -= 1 ) end break if date < Time::local( *oldest ) @io.transaction( date ) do |diaries| @diaries.update( diaries ) diaries_size = count_diaries_before( @diaries ) DIRTY_NONE end end end end |
Instance Method Details
#latest(limit = 5) ⇒ Object
396 397 398 399 400 401 402 403 404 405 406 407 408 |
# File 'lib/tdiary/view.rb', line 396 def latest( limit = 5 ) start = start_date limit = limit_size( limit ) idx = 0 @diaries.keys.sort.reverse_each do |date| next if date > start diary = @diaries[date] next unless diary.visible? yield diary idx += 1 break if idx >= limit end end |