Parent

Included Modules

Files

Bcat

Constants

VERSION

Attributes

format[R]

Public Class Methods

new(files=[], config={}) click to toggle source
# File lib/bcat.rb, line 14
def initialize(files=[], config={})
  @config = {:Host => '127.0.0.1', :Port => 8091}.merge(config)
  @reader = Bcat::Reader.new(files)
  @format = @config[:format]
end

Public Instance Methods

[](key) click to toggle source
# File lib/bcat.rb, line 20
def [](key)
  @config[key]
end
assemble() click to toggle source
# File lib/bcat.rb, line 41
def assemble
  @format = @reader.sniff if @format.nil?

  @filter = @reader
  @filter = TeeFilter.new(@filter) if @config[:tee]
  @filter = TextFilter.new(@filter) if @format == 'text'
  @filter = ANSI.new(@filter) if @format == 'text' || @config[:ansi]
end
call(env) click to toggle source
# File lib/bcat.rb, line 36
def call(env)
  notice "#{env['REQUEST_METHOD']} #{env['PATH_INFO'].inspect}"
  [200, {"Content-Type" => "text/html;charset=utf-8"}, self]
end
close() click to toggle source
# File lib/bcat.rb, line 102
def close
  notice "closing with interrupt"
  raise Interrupt
end
content_for_head(inject='') click to toggle source
# File lib/bcat.rb, line 79
def content_for_head(inject='')
  [
    "\n" * 1000,
    "<!DOCTYPE html>",
    "<html>",
    "<head>",
    "<!-- bcat was here -->",
    "<title>#{self[:title] || 'bcat'}</title>",
    inject.to_s,
    "</head>"
  ].join("\n")
end
each() click to toggle source
# File lib/bcat.rb, line 50
def each
  assemble

  head_parser = Bcat::HeadParser.new

  @filter.each do |buf|
    if head_parser.nil?
      yield buf
    elsif head_parser.feed(buf)
      yield content_for_head(inject=head_parser.head)
      yield head_parser.body
      head_parser = nil
    end
  end

  if head_parser
    yield content_for_head(inject=head_parser.head) +
          head_parser.body
  end

  yield foot
rescue Errno::EINVAL
  # socket was closed
  notice "browser client went away"
rescue => boom
  notice "boom: #{boom.class}: #{boom.to_s}"
  raise
end
escape_js(string) click to toggle source
# File lib/bcat.rb, line 96
def escape_js(string)
  string = string.gsub(/['\\]/) { |char| "\\#{char}" }
  string.gsub!(/\n/, '\n')
  string
end
foot() click to toggle source
# File lib/bcat.rb, line 92
def foot
  "</body></html>"
end
notice(message) click to toggle source
# File lib/bcat.rb, line 107
def notice(message)
  return if !@config[:debug]
  warn "#{File.basename($0)}: #{message}"
end
serve!(&bk) click to toggle source
# File lib/bcat.rb, line 32
def serve!(&bk)
  Bcat::Server.run to_app, @config, &bk
end
to_app() click to toggle source
# File lib/bcat.rb, line 24
def to_app
  app = self
  Rack::Builder.new do
    use Rack::Chunked
    run app
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.