- Start using haml.

This commit is contained in:
Jordan Sissel 2010-10-25 09:53:11 +00:00
parent 49af98b731
commit 8fd6ca9422
7 changed files with 57 additions and 8 deletions

View file

@ -10,34 +10,51 @@ require "sinatra/async"
#require "haml"
require "erb"
require "ap"
#require"sass/plugin/rack"
class EventMachine::ConnectionError < RuntimeError; end
class LogStashWeb < Sinatra::Base
register Sinatra::Async
set :haml, :format => :html5
set :logging, true
aget '/style.css' do
headers "Content-Type" => "text/css; charset=utf8"
body sass :style
end
aget '/' do
body haml :"main/index"
end # '/'
aget '/search' do
http = EventMachine::HttpRequest.new("http://localhost:9200/_search")
esreq = {
"sort" => [
{ "received_timestamp" => "desc" }
],
"query" => {
"query_string" => {
"query" => params[:q]
}
}
},
}
req = http.get :body => esreq.to_json
req.callback do
headers req.response_header
data = JSON.parse(req.response)
@hits = data["hits"]["hits"]
body erb :search
p data
@hits = data["hits"]["hits"] rescue []
body haml :"search/results"
end
req.errback do
body "Failed."
end
end
end # '/search'
end
#Sass::Plugin::Rack.new( \
Rack::Handler::Thin.run(
Rack::CommonLogger.new( \
Rack::ShowExceptions.new( \

4
web/views/header.haml Normal file
View file

@ -0,0 +1,4 @@
.logo
logstash

11
web/views/layout.haml Normal file
View file

@ -0,0 +1,11 @@
!!! 5
%html
%head
%title= @title || "Default title"
%link{ :rel => "stylesheet", :href => "/style.css", :type => "text/css" }
%body
#header
=haml :header, :layout => false
#content
=yield
#footer

View file

@ -0,0 +1,5 @@
%form.search{ :action => "/search" }
%label{ :for => "q" }
%input.query{ :type => "text", :name => "q" }
%input{ :type => "submit" }

View file

@ -1,4 +0,0 @@
<% @hits.each do |hit| %>
<%= hit["_source"].inspect %>
<p>
<% end %>

View file

@ -0,0 +1,3 @@
- @hits.each do |hit|
%pre
= hit["_source"].inspect

13
web/views/style.sass Normal file
View file

@ -0,0 +1,13 @@
body
margin: 0
padding: 0
#header
border-top: 4px solid black
border-bottom: 1px solid black
background-color: lightgreen
padding-left: 1em
width: 100%
.logo
font-size: 130%
font-weight: bold