Sha256: 3fa9d3501080ba880db54dbc4dcf82a1d3110ce4a1f9341b5007b71ad301d905

Contents?: true

Size: 1023 Bytes

Versions: 3

Compression:

Stored size: 1023 Bytes

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
      @@project.render path
    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

3 entries across 3 versions & 1 rubygems

Version Path
hydeweb-0.0.3.pre lib/hyde/init.rb
hydeweb-0.0.2.pre lib/hyde/init.rb
hydeweb-0.0.1.pre5 lib/hyde/init.rb