Class: Rack::Typekit

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/typekit.rb

Constant Summary collapse

VERSION =
"0.2.0"

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ Typekit

Returns a new instance of Typekit.

Raises:

  • (ArgumentError)


6
7
8
9
10
# File 'lib/rack/typekit.rb', line 6

def initialize(app, options = {})
  raise ArgumentError, "Typekit Kit ID Required" unless options[:kit] &&
    !options[:kit].empty?
  @app, @options = app, options
end

Instance Method Details

#call(env) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/rack/typekit.rb', line 12

def call(env)
  @status, @headers, @response = @app.call(env)
  return [@status, @headers, @response] unless html?
  response = Rack::Response.new([], @status, @headers)
  if @response.respond_to?(:to_ary)
    @response.each { |fragment| response.write inject_typekit(fragment) }
  end
  response.finish
end