Waves ãã¥ã¼ããªã¢ã« ãã¼ã2
http://www.rubywaves.com/tutorial-2
ãã¼ã1ã®ç¿»è¨³ã¯こちらã
ã2008-03-18æ´æ°ãid:t-wadaããã®ãææã«ãã誤訳ãä¿®æ£ãã¾ããã
-
-
-
- -
-
-
次ã«ãã¥ã¼ãä½ãï¼ããã°ã¨ã³ããªã®ãªã¹ãã表示ãã¾ããã¾ãã¨ã³ããªé¢é£ã®ãã³ãã¬ã¼ãã®ãã£ã¬ã¯ããªãä½ãã¾ããunixãªããããªæãã
~/blog $ mkdir templates/entry
次㫠template/entry ã« list.mab ã¨ãããã¡ã¤ã«ãä½ãã¾ãã"mab" æ¡å¼µå㯠Markaby ãã³ãã¬ã¼ãç¨ã§ãï¼Markaby 㯠ruby ã©ã¤ã¯ãªè¨æ³ããã®ã¾ã¾ä½¿ãããã³ãã¬ã¼ãã¨ã³ã¸ã³ï¼ãWaves 㯠Markaby 㨠Erubis ããµãã¼ããã¦ãã¾ãï¼ããã¦è¿½å ãç°¡åã§ãï¼ãï¼ããã§ã¯ Markaby ã使ãã¾ãã
layout :default, :title => 'Blog Entries' do h1 'My Blog' @entries.each do |entry| view :entry, :summary, :entry => entry end end
ããã§ä½¿ã£ã¦ãããã¯ããã¯ã®ãã¤ã³ãã¯ä»¥ä¸ã®éãã
- Markaby ãã³ãã¬ã¼ã㯠Ruby ã®ææ³ã使ãã¾ããå®é Ruby ãã®ãã®ã§ããã¡ã½ãã㯠HTML ã¿ã°ã«é¢é£ã¥ãããã¦ãã¾ãããããã¯ã¿ã°ã¯ãããã¯ãä¼´ãã¡ã½ããã§ãã詳ããã¯こちらã
- layout ãã«ãã¼ã使ã£ã¦ãã¾ããããã¯ã³ã³ãã³ãã "Blog Entries" ã¨ããã¿ã¤ãã«ã®ãããã©ã«ãã®ãã¬ã¤ã¢ã¦ãã«åãè¾¼ã¿ã¾ããWaves ã§ã¯ï¼ã¬ã¤ã¢ã¦ããï¼Railsã®ãããªï¼ã³ã³ããã¼ã©ã§ã¯ãªããã³ãã¬ã¼ãã®ä¸ã§æå®ãã¾ãã
- entriesã¤ã³ã¹ã¿ã³ã¹å¤æ°ã¯èªåçã«å®ç¾©ããã¾ãããªããªããªã¹ããã¥ã¼ã使ã£ã¦ããããã§ãããã¨ã§ããå°ã詳ãã説æãã¾ãã
- view ãã«ãã¼ã§å¥ã®ãã¥ã¼ãå¼ã³åºãã¦ãã¾ããããã¯åå©ç¨ã§ãããã¥ã¼ã®ä½ãæ¹ã示ãã¦ãã¾ããåå©ç¨å¯è½ãªãã¥ã¼ãå¿ è¦ãªãï¼ãã®ããã«ãªãã¡ã¯ã¿ãªã³ã°ã㦠view ãã«ãã¼ã使ãã ãã§ãã表示ãã¹ããªãã¸ã§ã¯ããæ ¼ç´ãã¦ãã entry ã¨ããã¤ã³ã¹ã¿ã³ã¹å¤æ°ã渡ãã¾ãã
次ã«å¼ã³åºãã¦ãããã¥ã¼ãå®ç¾©ããªããã°ãªãã¾ãããsummary.mab ã templates/entry ã«ä½ãã¾ãã
h2 do a @entry.title, :href => "/entry/#{@entry.name}" end textile @entry.summary a 'Read more ...', :href => "/entry/#{@entry.name}"
ããã§å èµã® textile ãã©ã¼ãããã使ãã¾ãããæ®ãã®é¨åã¯èªæã§ãããããã¤ãçåãããããããã¾ãããï¼å ã«é²ãã§ã¢ããªãèµ·åãï¼æ°ãããã¥ã¼ãè¦ã¦ã¿ã¾ãããã
~/blog $ waves-server I, [2008-01-28T11:01:19.945459 #3755] INFO -- : ** Waves Server Starting ... I, [2008-01-28T11:01:20.059007 #3755] INFO -- : ** Waves Server Running on 127.0.0.1:3000 I, [2008-01-28T11:01:20.059482 #3755] INFO -- : Server started in 30 ms.
ãã©ã¦ã¶ãéã http://localhost:3000/entries ã«ã¢ã¯ã»ã¹ãã¦ãã ããã以ä¸ã®ãããªç»é¢ãè¦ãããã¯ãã§ãã
http://www.rubywaves.com/images/our-first-view.png?size=small
ã¨ã³ããªå ¨ä½ãè¦ããã¥ã¼ã追å ãã¾ããããã¯ã¨ã³ããªãµããªã¨ããä¼¼ã¦ãã¾ããshow.mabãã¡ã¤ã«ãä½æãã¾ãããã
layout :default, :title => @entry.title do h1 @entry.title textile @entry.content end
"Read more ..." ãã¯ãªãã¯ãã¦ï¼ã©ã®ããã«è¦ããã確èªãã¦ãã ããã
http://www.rubywaves.com/images/show-entry-view.png?size=small
ã§ãã¾ããï¼ ããã¾ã§ã³ã³ããã¼ã©ãã¢ãã«ã®ã³ã¼ãã1è¡ãæ¸ãã¦ããªããã¨ã¯å¼·èª¿ãã¦ããã¦ãããã§ããããããã¤ãã®æ±ºã¾ãäºãå®ãã°ï¼Waves ã¯æã ãä½ããããã®ããæ¨è«ãããã¨ãã§ããã®ã§ãã
- ä½ãã®ãªã¹ãã® URL 㯠/entries ã¨ããããã«ãªã
- ç¹å®ã®ã¤ã³ã¹ã¿ã³ã¹ã® URL 㯠/entry/first-entry ã¨ããããã«ãªã
ãããã決ã¾ãäºã¯ç°¡åã«ã«ã¹ã¿ãã¤ãºã§ãã¾ããï¼ããã§ãããå°ãå ã«é²ã¿ã¾ããããlist ãã³ãã¬ã¼ãã®å é ã«ç°¡åãªãã©ã¼ã ã追å ãã¾ãããããªæãã§ãã
layout :default, :title => 'Blog Entries' do h1 'My Blog' form :action => '/entries', :method => 'post' do label 'Name' input :type => :text, :name => 'entry.name' input :type => :submit, :value => 'Add' end @entries.each do |entry| view :entry, :summary, :entry => entry end end
ããã§ã¯ REST ã¹ã¿ã¤ã«ã®ã¤ã³ã¿ã¼ãã§ã¼ã¹ã«å¾ãï¼æ°ããã¨ã³ããªã追å ãã URL ã¨ï¼ã¨ã³ããªå ¨ä½ã®ãªã¹ããåå¾ãã URL ãåããã®ã«ãã¦ãã¾ããéãã¯ãªã¯ã¨ã¹ãã®ã¡ã½ããã ãã§ããã¨ã³ããªã追å ããã«ã¯ POST ã使ãã¾ãããã㯠/entries ã«æ°ãããªã½ã¼ã¹ãä½ãã¨ãããã¨ã§ããï¼ãããã¾ãã«è¡ããããã¨ã§ãã
ä½ã£ãã¨ã³ããªãç·¨éããããã®å¥ã®ãã¥ã¼ãå¿ è¦ã§ããç°¡åã§ããeditor.mab ã追å ãã¾ãã
layout :default, :title => 'Edit Entry' do form :action => "/entry/#{@entry.name}/", :method => 'POST' do label 'Title'; br input :type => :text, :value => @entry.title, :name => 'entry.title'; br label 'Summary'; br textarea @entry.summary, :name => 'entry.summary', :rows => 10, :cols => 80; br label 'Content'; br textarea @entry.content, :name => 'entry.content', :rows => 20, :cols => 80; br input :type => :submit, :value => 'Save' end end
/entries ãã¼ã¸ã®ãã©ã¼ã ã使ã£ã¦ã¨ã³ããªã追å ãï¼ç·¨éãã¦ã¿ã¾ãããããã®æ°ããã¨ã³ããªã 'second-entry' ã¨ãã¾ãã
http://www.rubywaves.com/images/second-entry.png?size=medium
Save ãã¯ãªãã¯ããã¨ï¼æ°ããã¨ã³ããªããã©ã¦ã¶ã§è¦ãããã¯ãã§ãã
ä»ã®ã¨ããã¢ãã«ãã³ã³ããã¼ã©ãä½ãå¿ è¦ãããã¾ããã入門パート3ã§ã¯ï¼ä¸ã§ä½ãèµ·ãã¦ããããè¦ããã¨ã«ãã¾ãã