Sha256: 3a6182c2284afa4ed5c39fada1711a7d5d98ed210e7920fb83d8598f92df0f1c

Contents?: true

Size: 1.4 KB

Versions: 11

Compression:

Stored size: 1.4 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',
          'can-i-deploy-pacticipant-version-to-tag' => 'can-i-deploy',
          'pacticipant' => 'pacticipants'
        }.freeze

        helpers do
          def view_name_for rel_name, context = nil
            view_name = MAPPINGS[rel_name] || rel_name
            context ? "#{context}/#{view_name}" : view_name
          end

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

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

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
pact_broker-2.48.0 lib/pact_broker/doc/controllers/app.rb
pact_broker-2.47.1 lib/pact_broker/doc/controllers/app.rb
pact_broker-2.47.0 lib/pact_broker/doc/controllers/app.rb
pact_broker-2.46.0 lib/pact_broker/doc/controllers/app.rb
pact_broker-2.45.0 lib/pact_broker/doc/controllers/app.rb
pact_broker-2.44.0 lib/pact_broker/doc/controllers/app.rb
pact_broker-2.43.0 lib/pact_broker/doc/controllers/app.rb
pact_broker-2.42.0 lib/pact_broker/doc/controllers/app.rb
pact_broker-2.41.0 lib/pact_broker/doc/controllers/app.rb
pact_broker-2.40.0 lib/pact_broker/doc/controllers/app.rb
pact_broker-2.39.0 lib/pact_broker/doc/controllers/app.rb