Sha256: 9ca56f591892f176cd0d7cdf215098d15db829c62c16e7dc43953b97ce3cf570

Contents?: true

Size: 1.39 KB

Versions: 13

Compression:

Stored size: 1.39 KB

Contents

module Juli::Command
  # generate recent_updates.shtml which lists recent updated entries.
  # The file is for server-side-include(SSI).
  class RecentUpdate
    include Juli::Util
    include Juli::Visitor::Html::TagHelper
  
    # define maximum file limit in order to reduce process time.
    FILE_LIMIT = 20

    # cache recent_update
    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

    def run(opts)
      File.open(File.join(conf['output_top'], 'recent_update.shtml'), 'w') do |f|
        f.write(gen(opts))
      end
    end

  private
    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
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
juli-2.3.2 lib/juli/command/recent_update.rb
juli-2.3.1 lib/juli/command/recent_update.rb
juli-2.3.0 lib/juli/command/recent_update.rb
juli-2.2.4 lib/juli/command/recent_update.rb
juli-2.2.3 lib/juli/command/recent_update.rb
juli-2.2.1 lib/juli/command/recent_update.rb
juli-2.2.0 lib/juli/command/recent_update.rb
juli-2.1.0 lib/juli/command/recent_update.rb
juli-2.0.4 lib/juli/command/recent_update.rb
juli-2.0.3 lib/juli/command/recent_update.rb
juli-2.0.2 lib/juli/command/recent_update.rb
juli-2.0.1 lib/juli/command/recent_update.rb
juli-2.0.0 lib/juli/command/recent_update.rb