class Juli::Command::RecentUpdate

generate recent_updates.shtml which lists recent updated entries. The file is for server-side-include(SSI).

Constants

FILE_LIMIT

define maximum file limit in order to reduce process time.

Public Class Methods

new() click to toggle source

cache recent_update

# File lib/juli/command/recent_update.rb, line 12
def initialize
  @file = []
  Dir.chdir(juli_repo){
    Dir.glob('**/*.txt'){|f|
      @file << FileEntry.new(f, File.stat(f).mtime)
    }
    @file.sort!{|a,b| b.mtime <=> a.mtime}
  }
end

Public Instance Methods

run(opts) click to toggle source
# File lib/juli/command/recent_update.rb, line 22
def run(opts)
  File.open(File.join(conf['output_top'], 'recent_update.shtml'), 'w') do |f|
    f.write(gen(opts))
  end
end

Private Instance Methods

gen(opts) click to toggle source
# File lib/juli/command/recent_update.rb, line 29
def gen(opts)
  title   = I18n.t('recent_updates')
  content_tag(:table, :class=>'juli_recent_update') do
    content_tag(:tr, content_tag(:th, title, :colspan=>2)) +
    begin
      result = ''
      for i in 0..FILE_LIMIT-1 do
        f = @file[i]
        break if !f
        result +=
          content_tag(:tr) do
            content_tag(:td) do
              content_tag(:a, f.path.gsub(/.txt$/, ''),
                :href=>f.path.gsub(/.txt$/, conf['ext'])) + "\n<br/>"
            end +
            content_tag(:td, f.mtime.strftime('%Y/%m/%d'))
          end
      end
      result
    end
  end
end