Skip to content

Instantly share code, notes, and snippets.

@rummelonp
Created April 21, 2011 14:09
Show Gist options
  • Save rummelonp/934588 to your computer and use it in GitHub Desktop.
Save rummelonp/934588 to your computer and use it in GitHub Desktop.
SinatraとRubytterとHamlでTwitter検索
# -*- coding: utf-8 -*-
##
## requirements
## sinatra
## rubytter
## haml
## install
## $ gem install sinatra rubytter haml
## usage
## $ ruby twitter_search.rb
##
require 'sinatra'
require 'rubytter'
require 'haml'
set :haml, format: :html5
get '/' do
@q = params[:q]
@tweets = Rubytter.new.search @q if @q
haml :index
end
__END__
@@layout
!!!
%title&= @title
%meta{'http-equiv' => 'content-type', content: 'text/html; charset=utf-8'}
= yield
@@index
%header
%h1 Twitter Search by Sinatra
%form
%input{type: 'search', name: 'q', placeholder: 'search text', value: @q}
- if @tweets
%dl
- @tweets.each do |t|
%dt
%img{src: t.user.profile_image_url, width: 40, height: 40}
%dd #{t.user.screen_name}
%dd #{t.text}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment