Sha256: 9a5616374285079bf1055e1c7c9308e430ccbb77669637b376b59007115fdbb4

Contents?: true

Size: 976 Bytes

Versions: 8

Compression:

Stored size: 976 Bytes

Contents

require 'rack/request'
require 'useless/doc/ui/godel'

module Useless
  module Doc
    class Proxy

      # +Doc::Proxy::UI+ chooses which UI should be used to render the
      # documentation and sets it to 'useless.doc.ui'.
      #
      # It could theoretically be chosen via the 'ui' parameter,
      # but until there are other UIs, it will alway choose +UI::Godel+.
      #
      class UI
        def initialize(app)
          @app = app
        end

        def call(env)
          request = ::Rack::Request.new(env)

          env['useless.doc.ui'] = case request.params['ui']
            when 'godel'; Useless::Doc::UI::Godel.new(env['useless.doc.router'])
            else          Useless::Doc::UI::Godel.new(env['useless.doc.router'])
          end

          if env['useless.doc.logger']
            env['useless.doc.logger'].debug "selected UI: #{env['useless.doc.ui'].class.name}"
          end

          @app.call(env)
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
useless-doc-0.7.0 lib/useless/doc/proxy/ui.rb
useless-doc-0.6.5 lib/useless/doc/proxy/ui.rb
useless-doc-0.6.4 lib/useless/doc/proxy/ui.rb
useless-doc-0.6.3 lib/useless/doc/proxy/ui.rb
useless-doc-0.6.2 lib/useless/doc/proxy/ui.rb
useless-doc-0.6.1 lib/useless/doc/proxy/ui.rb
useless-doc-0.6.0 lib/useless/doc/proxy/ui.rb
useless-doc-0.5.0 lib/useless/doc/proxy/ui.rb