class Glog::Server

Public Instance Methods

call(rack_env) click to toggle source
# File lib/glog/server.rb, line 6
def call(rack_env)
  Glog.env = Env.new(rack_env)
  Glog.env.path?('/') ? send_root_page : send_path(Glog.env.path)
end

Private Instance Methods

render_page(page) click to toggle source
# File lib/glog/server.rb, line 41
def render_page(page)
  locals = { :env => Glog.env, :config => Glog.config, :pages => Page }
  Template.wrap(page, locals).render
end
send_not_found() click to toggle source
# File lib/glog/server.rb, line 33
def send_not_found
  [404, { 'Content-Type' => 'text/html' }, [ '404 Not Found' ]]
end
send_page(page) click to toggle source
# File lib/glog/server.rb, line 29
def send_page(page)
  [200, { 'Content-Type' => page.content_type }, [ render_page(page) ]]
end
send_path(path) click to toggle source
# File lib/glog/server.rb, line 13
def send_path(path)
  path = path[1..-1] # /my/page => my/page
  if page = Page.get(path)
    send_page(page)
  elsif page = try_dir_index(path)
    send_page(page)
  else
    send_not_found
  end
end
send_root_page() click to toggle source
# File lib/glog/server.rb, line 37
def send_root_page
  Page.root ? send_page(Page.root) : send_not_found
end
try_dir_index(path) click to toggle source
# File lib/glog/server.rb, line 24
def try_dir_index(path)
  File.directory?(File.join('pages', path))
  Page.get(File.join(path, 'index'))
end