Sha256: 05b8f373eadecab5d44b6558bffc914d802cfd98e74560c6942126da33a283ac

Contents?: true

Size: 1.01 KB

Versions: 15

Compression:

Stored size: 1.01 KB

Contents

require 'padrino-core'
require 'redcarpet'

Tilt.prefer Tilt::RedcarpetTemplate

module PactBroker
  module Doc
    module Controllers
      class App < Padrino::Application

        set :root, File.join(File.dirname(__FILE__), '..')
        set :show_exceptions, true

        MAPPINGS = {
          'webhooks-create' => 'webhooks',
          'webhooks-webhooks' => 'webhooks',
          'pact-webhooks' => 'webhooks',
        }.freeze

        helpers do
          def view_name_for rel_name
            MAPPINGS[rel_name] || rel_name
          end

          def resource_exists? rel_name
            File.exist? File.join(self.class.root, 'views', "#{view_name_for(rel_name)}.markdown")
          end
        end

        get ":rel_name" do
          rel_name = params[:rel_name]
          if resource_exists? rel_name
            markdown view_name_for(rel_name).to_sym, {:layout_engine => :haml, layout: :'layouts/main'}, {}
          else
            response.status = 404
          end
        end

      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
pact_broker-2.22.0 lib/pact_broker/doc/controllers/app.rb
pact_broker-2.21.0 lib/pact_broker/doc/controllers/app.rb
pact_broker-2.20.0 lib/pact_broker/doc/controllers/app.rb
pact_broker-2.19.2 lib/pact_broker/doc/controllers/app.rb
pact_broker-2.19.1 lib/pact_broker/doc/controllers/app.rb
pact_broker-2.19.0 lib/pact_broker/doc/controllers/app.rb
pact_broker-2.18.0 lib/pact_broker/doc/controllers/app.rb
pact_broker-2.17.1 lib/pact_broker/doc/controllers/app.rb
pact_broker-2.17.0 lib/pact_broker/doc/controllers/app.rb
pact_broker-2.16.1 lib/pact_broker/doc/controllers/app.rb
pact_broker-2.16.0 lib/pact_broker/doc/controllers/app.rb
pact_broker-2.15.0 lib/pact_broker/doc/controllers/app.rb
pact_broker-2.14.0 lib/pact_broker/doc/controllers/app.rb
pact_broker-2.13.1 lib/pact_broker/doc/controllers/app.rb
pact_broker-2.13.0 lib/pact_broker/doc/controllers/app.rb