Sha256: 63294f8800e5034183611f5565a36c07cb1f59a2ef4a75d11c889a4b9642f4e7

Contents?: true

Size: 1.09 KB

Versions: 2

Compression:

Stored size: 1.09 KB

Contents

class Response
  # HTML response
  class HTML < self
    HEADERS = IceNine.deep_freeze('Content-Type' => 'text/html; charset=UTF-8')

    # Build html response with defaults
    #
    # @param [Object] body
    #   rack compatible body
    #
    # @return [Response::HTML]
    #
    # @example
    #
    #   # With defaults
    #   response = Response::HTML.build("<html><body>Hello</body></html>")
    #   response.status  # => Response::Status::OK
    #   response.headers # => { 'Content-Type' => 'text/html; charset=UTF-8' }
    #   response.body    # => "<html><body>Hello</body></html>"
    #
    #   # With overriding defaults
    #   response = Response::HTML.build("<html><body>Hello</body></html>") do |response|
    #     response.with_status(Respnse::Status::NOT_FOUND)
    #   end
    #
    #   response.status  # => Response::Status::NOT_FOUND
    #   response.headers # => { 'Content-Type' => 'text/html; charset=UTF-8' }
    #   response.body    # => "<html><body>Hello</body></html>"
    #
    # @api public
    #
    def self.build(body)
      super(Status::OK, HEADERS, body)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
response-0.0.5 lib/response/html.rb
response-0.0.4 lib/response/html.rb