Sha256: 15ba75822dc2d81fdd301708692273edda41c01be057e4faefca0d80bfdacbcd

Contents?: true

Size: 770 Bytes

Versions: 2

Compression:

Stored size: 770 Bytes

Contents

# frozen_string_literal: true

require 'sinatra/base'

module Trifle
  module Docs
    class App < Sinatra::Base
      configure do
        set :bind, '0.0.0.0'
        set :views, proc { Trifle::Docs.default.views }
      end

      get '/*' do
        url = params['splat'].first.chomp('/')
        meta = Trifle::Docs.meta(url: url)
        halt(404, 'Not Found') if meta.nil?

        if meta['type'] == 'file'
          send_file meta['path']
        else
          erb (meta['template'] || 'page').to_sym, {}, {
            sitemap: Trifle::Docs.sitemap,
            collection: Trifle::Docs.collection(url: url),
            content: Trifle::Docs.content(url: url),
            meta: meta,
            url: url
          }
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
trifle-docs-0.3.1 lib/trifle/docs/app.rb
trifle-docs-0.3.0 lib/trifle/docs/app.rb