SInatra?
SInatra?
Sinatra?• Ruby製     Webフレームワーク• MCモデル• お手軽
Agenda• Hello Sinatra• View (Haml)• DB(Active Record)
Hello World!# coding: utf-8require ‘sinatra’get ‘/’ do‘Hello Sinatra!’endsinatra.rbhttp://0.0.0.0:4567/COMMANDruby sinatra...
環境作り gem install sinatra
VIEW / Template• Erb• Haml• Markdown• 鋸など
haml• HTML abstraction markup language• Haml accelerates and simplifiestemplate creation down to veritablehaiku
HAML%html%head%titleHaml Sample%bodyHello Haml!<html><head><title>Haml Sample</title></head><body>Hello Haml!</body></html>
Sinatra with hamlhttp://twitter.github.io/bootstrap/https://github.com/kaakaa/SinatraBenkyou1
#coding: utf-8require sinatrarequire hamlget / doredirect /Sinatra/endget /:name/ do@display_name = params[:name]haml :ind...
%html%head%titleHaml Sample%meta{ :charset => "utf-8" }%script{ :src => "/js/jquery-1.9.0.min.js" }%link{ :rel => "stylesh...
%html%head%titleHaml Sample%meta{ :charset => "utf-8" }%script{ :src => "/js/jquery-1.9.0.min.js" }%link{ :rel => "stylesh...
%form{ :method => "post", :action => "/hello" }%input{ :type => "text", :name => "name",:class => "span2" }%input{ :type =...
Active Record Design PatternO/R Mapper1Record = 1Objecthttps://github.com/kaakaa/Sinatra-Benkyou2
history Recordnamedate_time
require active_recordActiveRecord::Base.configurations = YAML.load_file(database.yml)ActiveRecord::Base.establish_connection...
require active_recordActiveRecord::Base.configurations = YAML.load_file(database.yml)ActiveRecord::Base.establish_connection...
require active_recordActiveRecord::Base.configurations = YAML.load_file(database.yml)ActiveRecord::Base.establish_connection...
get / doredirect /Sinatra/endget /:name/ do@display_name = params[:name]@histories = History.allhaml :indexend%h3HISTORY-@...
post /*/hello do@name = params[:name]if @name.nil? then@name = "Sinatra"endday = Time.nowdate_time =day.strftime("%Y/%m/%d...
summary• Hello Sinatra• 簡単• View (Haml)• 楽• DB(Active Record)• 楽
summary怠惰
bundlesource "https://rubygems.org"ruby 2.0.0group :development, :test dogem "sqlite3", 1.3.7gem "dm-sqlite-adapter"endgem...
感想
感想• Ruby周りは楽• ただ、楽過ぎて怖い• テスト環境ならOK?• 本棚アプリ…
Sinatra slideshare
Sinatra slideshare
Upcoming SlideShare
Loading in …5
×

Sinatra slideshare

600
-1

Published on

とある組織の勉強会議 #5

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
600
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Sinatra slideshare

  1. 1. SInatra?
  2. 2. SInatra?
  3. 3. Sinatra?• Ruby製     Webフレームワーク• MCモデル• お手軽
  4. 4. Agenda• Hello Sinatra• View (Haml)• DB(Active Record)
  5. 5. Hello World!# coding: utf-8require ‘sinatra’get ‘/’ do‘Hello Sinatra!’endsinatra.rbhttp://0.0.0.0:4567/COMMANDruby sinatra.rb
  6. 6. 環境作り gem install sinatra
  7. 7. VIEW / Template• Erb• Haml• Markdown• 鋸など
  8. 8. haml• HTML abstraction markup language• Haml accelerates and simplifiestemplate creation down to veritablehaiku
  9. 9. HAML%html%head%titleHaml Sample%bodyHello Haml!<html><head><title>Haml Sample</title></head><body>Hello Haml!</body></html>
  10. 10. Sinatra with hamlhttp://twitter.github.io/bootstrap/https://github.com/kaakaa/SinatraBenkyou1
  11. 11. #coding: utf-8require sinatrarequire hamlget / doredirect /Sinatra/endget /:name/ do@display_name = params[:name]haml :indexendpost /hello do@name = params[:name]if @name.nil? then@name = "Sinatra"endredirect / + @name + /endsinatra.rb
  12. 12. %html%head%titleHaml Sample%meta{ :charset => "utf-8" }%script{ :src => "/js/jquery-1.9.0.min.js" }%link{ :rel => "stylesheet", :href => "/css/bootstrap.css" }%body%div.input-append%h3INPUT YOUT NAME!%form{ :method => "post", :action => "/hello" }%input{ :type => "text", :name => "name",:class => "span2" }%input{ :type => "submit", :value => "SEND",:class => "btn btn-small" }%h2= "Hello " + @display_name.to_s + " !"index.haml
  13. 13. %html%head%titleHaml Sample%meta{ :charset => "utf-8" }%script{ :src => "/js/jquery-1.9.0.min.js" }%link{ :rel => "stylesheet", :href => "/css/bootstrap.css" }%body%div.input-append%h3INPUT YOUT NAME!%form{ :method => "post", :action => "/hello" }%input{ :type => "text", :name => "name",:class => "span2" }%input{ :type => "submit", :value => "SEND",:class => "btn btn-small" }%h2= "Hello " + @display_name.to_s + " !"index.haml
  14. 14. %form{ :method => "post", :action => "/hello" }%input{ :type => "text", :name => "name",:class => "span2" }%input{ :type => "submit", :value => "SEND",:class => "btn btn-small" }post /hello do@name = params[:name]if @name.nil? then@name = "Sinatra"endredirect / + @name + /end
  15. 15. Active Record Design PatternO/R Mapper1Record = 1Objecthttps://github.com/kaakaa/Sinatra-Benkyou2
  16. 16. history Recordnamedate_time
  17. 17. require active_recordActiveRecord::Base.configurations = YAML.load_file(database.yml)ActiveRecord::Base.establish_connection(development)class History < ActiveRecord::Baseenddevelopment:adapter: sqlite3database: db/benkyo.dbsinatra.rb(partially)database.yml
  18. 18. require active_recordActiveRecord::Base.configurations = YAML.load_file(database.yml)ActiveRecord::Base.establish_connection(development)class History < ActiveRecord::Baseenddevelopment:adapter: sqlite3database: db/benkyo.dbsinatra.rb(partially)database.ymlhistorynamedate_time
  19. 19. require active_recordActiveRecord::Base.configurations = YAML.load_file(database.yml)ActiveRecord::Base.establish_connection(development)class History < ActiveRecord::Baseenddevelopment:adapter: sqlite3database: db/benkyo.dbhistory = History.newhistory.name = @namehistory.date_time = @date_timehistory.savehistory = History.find(‘2013/05/14 00:00:00’)history.destroyHistory.destroy_allsinatra.rb(partially)
  20. 20. get / doredirect /Sinatra/endget /:name/ do@display_name = params[:name]@histories = History.allhaml :indexend%h3HISTORY-@histories.each do |history|%div= history.date_time= history.namesinatra.rb(partially) index.haml(partially)
  21. 21. post /*/hello do@name = params[:name]if @name.nil? then@name = "Sinatra"endday = Time.nowdate_time =day.strftime("%Y/%m/%d %H:%M:%S")history = History.newhistory.name = @namehistory.date_time = @date_timehistory.saveredirect / + @name + /sinatra.rb(partially)
  22. 22. summary• Hello Sinatra• 簡単• View (Haml)• 楽• DB(Active Record)• 楽
  23. 23. summary怠惰
  24. 24. bundlesource "https://rubygems.org"ruby 2.0.0group :development, :test dogem "sqlite3", 1.3.7gem "dm-sqlite-adapter"endgem "activerecord"gem "sinatra",git: https://github.com/juanpastas/sinatra.gitgem "haml"bundle install --path vendor/bundlebundle exec ruby sinatra.rbGemfile
  25. 25. 感想
  26. 26. 感想• Ruby周りは楽• ただ、楽過ぎて怖い• テスト環境ならOK?• 本棚アプリ…

×