Skip to content

Instantly share code, notes, and snippets.

@h5y1m141
Created August 9, 2012 22:28
Show Gist options
  • Save h5y1m141/3308607 to your computer and use it in GitHub Desktop.
Save h5y1m141/3308607 to your computer and use it in GitHub Desktop.
Sinatra sample
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
<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>
!!! 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