Permalink
Browse files

spruce up the bot site interface. wot

  • Loading branch information...
1 parent ff244a5 commit b5938c3ecaae0f591f0ad383c27d92ab18f23769 @dkeskar dkeskar committed Aug 15, 2010
Showing with 41 additions and 23 deletions.
  1. +15 −13 application.rb
  2. +1 −1 environment.rb
  3. +2 −1 lib/comment.rb
  4. +5 −2 views/configure.haml
  5. +2 −2 views/hn.haml
  6. +10 −0 views/layout.haml
  7. +5 −4 views/streams.haml
  8. +1 −0 views/watch.haml
View
@@ -27,20 +27,16 @@
# add your helpers here
end
-# root page
-get '/' do
- haml :root
-end
-get '/hn' do
+get '/' do
@top10 = Posting.where(
:posted_at.gte => (Time.now - 10.hours)
).sort(:pntx.desc).limit(10).all
@stats = HackerNews.stats
haml :hn
end
-get %r{/hn/watch(/([\w]+))?} do
+get %r{/watch(/([\w]+))?} do
if (opt = params[:captures]) and opt.is_a?(Array) and opt.size == 2
@highlight = opt.last
end
@@ -49,26 +45,32 @@
haml :watch
end
-post '/hn/watch' do
+post '/watch' do
@watch = Avatar.first_or_new(:name => params[:user])
inc = params[:unwatch] ? -1 : 1
@watch.increment(:nwx => inc)
redirect "/hn/watch/#{@watch.id}"
end
-get '/configure' do
+get '/streams/new' do
# UI for viewing stream types and configuring a new stream instance
haml :configure
end
-get '/streams' do
- Stream.paginate(:page => params[:page]).to_json
+get %r{/streams([\.](json|html))?$} do |specified, format|
+ $stderr.puts "Streams format: #{format} spec #{specified}"
+ @streams = Stream.paginate(:page => params[:page])
+ if format and format == 'json'
+ @streams.to_json
+ else
+ haml :streams
+ end
end
-get '/streams/:stream_id.:format' do
+get '/streams/show/:stream_id.:format' do
# get activity for a stream
@stream = Stream.where(:sid => params[:stream_id]).first
- $stderr.puts "format: #{params[:format].inspect}"
+ $stderr.puts @stream.inspect
case params[:format]
when :json, 'json'; @stream.activity.to_json
else; haml :streams
@@ -86,7 +88,7 @@
@stream.title = params[:title]
@stream.save
if params[:format] == 'html'
- redirect "/streams/#{@stream.sid}.html"
+ redirect "/streams/show/#{@stream.sid}.html"
else
puts @stream.to_json
end
View
@@ -3,7 +3,7 @@
require 'ostruct'
SiteConfig = OpenStruct.new(
- :title => 'Watchbots',
+ :title => 'Hacker News Watch',
:author => 'Dhananjay Keskar',
:app => 'watchbots',
:url_base => 'http://localhost:4567/'
View
@@ -24,7 +24,7 @@ class Comment
<a href="{{link}}">{{title}}</a> within {{interval}}</div>
{{text}}
<div style="text-align:right; font-size:smaller; ">
- <a href="{{comment}}">{{numrsp}} responses</a>
+ {{points}}, <a href="{{comment}}">{{numrsp}} responses</a>
</div>
</div>
END
@@ -43,6 +43,7 @@ def self.add(info={})
def info
ret = {:user => self.name, :text => self.text}
ret[:comment] = "#{HackerNews::URL}/item?id=#{self.cid}"
+ ret[:points] = "#{self.pntx} point#{self.pntx > 1 ? 's' : ''}"
ret[:numrsp] = self.nrsp
if not (post = Posting.where(:pid => self.pid).first)
ret[:interval] = ((Time.now - self.posted_at)/1.hour).round
View
@@ -1,4 +1,7 @@
-%h2 Hacker News User Activity Stream
+%h2 Create New Stream
+%p
+ Currently, there is only one type of stream. <br/>
+ This is a user watch, which tracks their comments and submissions.
%form{:method => 'post', :action => '/streams'}
%p
%label Username
@@ -9,7 +12,7 @@
%input{:type => 'text', :name => 'points', :value => 1}
%p
%label Give it a descriptive title<br/>
- %input{:type => 'text', :name => 'title'}
+ %input{:type => 'text', :name => 'title', :size => 42}
%p
%input{:type => 'hidden', :name => 'format', :value => 'html'}
%input{:type => 'submit', :value => 'Watch'}
View
@@ -1,9 +1,9 @@
%h2 Set Watch
%p
Select a HN user to watch (e.g. pg, patio11).
- %a{:href => "/hn/watch"} See the watchlist.
+ %a{:href => "/watch"} See the watchlist.
-%form{:method => 'post', :action => '/hn/watch'}
+%form{:method => 'post', :action => '/watch'}
%input{:type => 'text', :name => 'user'}
%input{:type => 'submit', :value => 'Watch'}
<br/>
View
@@ -9,6 +9,16 @@
#logo
%h1
%a{:href => '/'}= SiteConfig.title
+ %div{:style => 'float:right; text-align:right'}
+ %ul.horizontal
+ %li
+ %a{:href => '/watch'} Watchlist
+ %li
+ %a{:href => '/streams'} Streams
+ %li
+ %a{:href => '/streams/new'} Create Stream
+ %div{:style => 'clear:both;'}
+
#content= yield
#footer
%p#legal= "&mdash; &copy; #{Time.now.strftime('%Y')} #{SiteConfig.app} &mdash;"
View
@@ -1,15 +1,16 @@
- if @stream
- %h2= "Stream #{@stream.title || 'Untitled'}"
+ %h2= "#{@stream.title || 'Untitled Stream'}"
- @stream.activity.each do |item|
%div= Stream.display(item)
- if @streams
%h2 Instantiated Streams
- @streams.each do |stream|
- %div
- %h4= stream.sid + " - " + stream.title || "Untitled"
- %p= stream.config.to_yaml.gsub(/\n/, '<br/>')
+ %div{:style => 'margin: 10px 0'}
+ %strong
+ %a{:href => "/streams/show/#{stream.sid}.html"}= stream.title || "Untitled"
+ %div= stream.config.inspect
- if @streams.blank?
%p <i>No streams</i>
View
@@ -9,6 +9,7 @@
%li{:id => av.id}
%a{:href => "#", :onclick => "removeWatch('#{av.name}'); return false;"} [u]
%span{:style => (av.id.to_s == @highlight ? "font-weight:bold" : "")}= av.name
+ %span{:style => 'font-size:smaller;'}= "#{av.nwx} watchers"
%a{:href => "/hn"} Back

0 comments on commit b5938c3

Please sign in to comment.