Sha256: 409fec6d0fae92eac94798e4e6b52a072ac70d3b2bf7029617421fb808b4bafb

Contents?: true

Size: 1.75 KB

Versions: 7

Compression:

Stored size: 1.75 KB

Contents

#!/usr/bin/env ruby
$:<< '../lib' << 'lib'

# A simple dashboard for goliath
# See
#   examples/views              -- templates
#   examples/public             -- static files
#   examples/config/template.rb -- configuration
#
# The templating is based on, but not as fancy-pants as, Sinatra's. Notably,
# your template's extension must match the engine (foo.markdown, not foo.md)

require 'tilt'

if RUBY_PLATFORM != 'java'
  require 'yajl/json_gem'
  require 'bluecloth' # use bluecloth as default markdown renderer
  Tilt.register 'markdown', Tilt::BlueClothTemplate
else
  require 'maruku'
  Tilt.register 'markdown', Tilt::MarukuTemplate
end

require 'goliath'
require 'goliath/rack/templates'
require 'goliath/plugins/latency'

class Template < Goliath::API
  include Goliath::Rack::Templates      # render templated files from ./views

  use(Rack::Static,                     # render static files from ./public
      :root => Goliath::Application.app_path("public"),
      :urls => ["/favicon.ico", '/stylesheets', '/javascripts', '/images'])

  plugin Goliath::Plugin::Latency       # ask eventmachine reactor to track its latency

  def recent_latency
    Goliath::Plugin::Latency.recent_latency
  end

  def response(env)
    case env['PATH_INFO']
    when '/'         then [200, {}, haml(:root)]
    when '/haml_str' then [200, {}, haml("%h1 Header")]
    when '/debug'    then [200, {}, haml(:debug)]
    when '/oops'     then [200, {}, haml(:no_such_template)] # will 500
    when '/joke'     then
      [200, {}, markdown(:joke, :locals => {:title => "HERE IS A JOKE"})]
    when '/erb_me'   then
      [200, {}, markdown(:joke, :layout_engine => :erb, :locals => {:title => "HERE IS A JOKE"})]
    else                  raise Goliath::Validation::NotFoundError
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
goliath-1.0.7 examples/template.rb
goliath-1.0.6 examples/template.rb
goliath-1.0.5 examples/template.rb
goliath-1.0.4 examples/template.rb
goliath-1.0.3 examples/template.rb
goliath-1.0.2 examples/template.rb
goliath-1.0.1 examples/template.rb