Created
April 21, 2011 14:09
-
-
Save rummelonp/934588 to your computer and use it in GitHub Desktop.
SinatraとRubytterとHamlでTwitter検索
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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