Created
August 9, 2012 22:28
-
-
Save h5y1m141/3308607 to your computer and use it in GitHub Desktop.
Sinatra sample
This file contains 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
require 'sinatra' | |
require 'open-uri' | |
require 'json' | |
require 'haml' | |
get '/hello' do | |
'hello' | |
end | |
get '/hello/:yourname' do | |
'hello!' + params[:yourname] | |
end | |
get '/template' do | |
erb :index | |
end | |
get '/' do | |
url ='https://api.twitter.com/1/statuses/public_timeline.json?count=3&include_entities=true' | |
json = open(url).read | |
@items = JSON.parse(json) | |
haml :index | |
end |
This file contains 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
<html> | |
<head> | |
<title>erb sample</title> | |
<link href='css/bootstrap.min.css' rel='stylesheet' /> | |
</head> | |
<body> | |
<h1>ERB sample</h1> | |
<ul> | |
<% | |
url ='https://api.twitter.com/1/statuses/public_timeline.json?count=3&include_entities=true' | |
json = open(url).read | |
JSON.parse(json).each do |items| | |
%> | |
<li> | |
<%= items["text"] %> | |
</li> | |
<% end %> | |
</ul> | |
</body> | |
</html> |
This file contains 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
!!! XML | |
!!! | |
%html{html_attrs('ja')} | |
%head | |
%title= "Show twitter TL" | |
%link(rel='stylesheet' href='css/bootstrap.min.css') | |
%body | |
.navbar.navbar-fixed-top | |
.navbar-inner | |
.container | |
%a.brand{:href => '/'} | |
recent time line | |
.nav-collapse | |
.container-fluid | |
%div{:style => 'padding-top:60px'} | |
%table | |
- @items.each do |item| | |
%tr | |
%td | |
%i.icon-pencil! = "" | |
%td.table-striped!= item["text"]+ "(" + item["user"]["name"] + ")" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment