Sha256: 3830e9b371934eb78d0167565bcd89cdc9e81fcb24985e2e70a45b0f05d2b64b

Contents?: true

Size: 1.18 KB

Versions: 1

Compression:

Stored size: 1.18 KB

Contents

require 'rubygems'
begin
  require 'sinatra/base'
rescue LoadError
  STDERR << "You need the sinatra gem to use `hyde start`. Type: `gem install sinatra`\n"
  exit
end

$:.unshift File.dirname(__FILE__) + "/.."
require 'hyde'

$project = Hyde::Project.new

class Main < Sinatra::Base
  @@project ||= $project

  def self.show_start
    puts "Starting server..."
    puts "  http://127.0.0.1:4567      Homepage"
    puts "  http://127.0.0.1:4567/-    File list"
    puts ""
  end

  get '/-' do
    @@project.files.inject("") do |a, path|
      a << "<li><a href='#{path}'>#{path}</a></li>"
      a
    end
  end

  get '/*' do
    begin
      path = params[:splat][0]
      type = File.extname(path)[1..-1]
      content_type type.to_sym  if type.is_a? String

      page = Hyde::Page.create path, @@project

      # Send the last modified time
      last_modified File.mtime(page.filename)
      cache_control :public, :must_revalidate, :max_age => 60

      page.render

    rescue Hyde::RenderError => e
      puts " * `#{path}` error"
      puts " *** #{e.message}".gsub("\n","\n *** ")
      e.message

    rescue Hyde::NotFound
      raise Sinatra::NotFound

    end
  end
end

Main.show_start
Main.run!

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hydeweb-0.0.4 lib/hyde/init.rb