123456789_123456789_123456789_123456789_123456789_

Class: Rack::Directory::DirectoryBody

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Struct
Instance Chain:
self, Struct
Inherits: Struct
  • Object
Defined in: lib/rack/directory.rb

Overview

Body class for directory entries, showing an index page with links to each file.

Instance Attribute Summary

  • #files rw

    Body class for directory entries, showing an index page with links to each file.

  • #path rw

    Body class for directory entries, showing an index page with links to each file.

  • #root rw

    Body class for directory entries, showing an index page with links to each file.

Instance Method Summary

Instance Attribute Details

#files (rw)

Body class for directory entries, showing an index page with links to each file.

[ GitHub ]

  
# File 'lib/rack/directory.rb', line 51

class DirectoryBody < Struct.new(:root, :path, :files)

#path (rw)

Body class for directory entries, showing an index page with links to each file.

[ GitHub ]

  
# File 'lib/rack/directory.rb', line 51

class DirectoryBody < Struct.new(:root, :path, :files)

#root (rw)

Body class for directory entries, showing an index page with links to each file.

[ GitHub ]

  
# File 'lib/rack/directory.rb', line 51

class DirectoryBody < Struct.new(:root, :path, :files)

Instance Method Details

DIR_FILE_escape(htmls) (private)

Escape each element in the array of html strings.

[ GitHub ]

  
# File 'lib/rack/directory.rb', line 73

def DIR_FILE_escape(htmls)
  htmls.map { |e| Utils.escape_html(e) }
end

#each {|DIR_PAGE_HEADER % [ show_path, show_path ]| ... }

Yield strings for each part of the directory entry

Yields:

[ GitHub ]

  
# File 'lib/rack/directory.rb', line 53

def each
  show_path = Utils.escape_html(path.sub(/^#{root}/, ''))
  yield(DIR_PAGE_HEADER % [ show_path, show_path ])

  unless path.chomp('/') == root
    yield(DIR_FILE % DIR_FILE_escape(files.call('..')))
  end

  Dir.foreach(path) do |basename|
    next if basename.start_with?('.')
    next unless f = files.call(basename)
    yield(DIR_FILE % DIR_FILE_escape(f))
  end

  yield(DIR_PAGE_FOOTER)
end