{"id":2786,"date":"2013-10-18T13:09:52","date_gmt":"2013-10-18T04:09:52","guid":{"rendered":"http:\/\/www.techscore.com\/blog\/?p=2786"},"modified":"2018-11-14T16:33:53","modified_gmt":"2018-11-14T07:33:53","slug":"yesod%e5%85%a5%e9%96%80-6-hamlet-%e5%88%b6%e5%be%a1%e6%a7%8b%e9%80%a0%e3%82%84widget%e3%81%ae%e5%9f%8b%e3%82%81%e8%be%bc%e3%81%bf%e3%81%aa%e3%81%a9","status":"publish","type":"post","link":"https:\/\/www.techscore.com\/blog\/2013\/10\/18\/yesod%e5%85%a5%e9%96%80-6-hamlet-%e5%88%b6%e5%be%a1%e6%a7%8b%e9%80%a0%e3%82%84widget%e3%81%ae%e5%9f%8b%e3%82%81%e8%be%bc%e3%81%bf%e3%81%aa%e3%81%a9\/","title":{"rendered":"Yesod\u5165\u9580 (6) Hamlet: \u5236\u5fa1\u69cb\u9020\u3084Widget\u306e\u57cb\u3081\u8fbc\u307f\u306a\u3069"},"content":{"rendered":"<p>\u3053\u3093\u306b\u3061\u306f\u3001\u9234\u6728\u3067\u3059\u3002<\/p>\n<p>\u4eca\u56de\u306f Yesod \u306e View \u5468\u308a\u3068\u3044\u3046\u3053\u3068\u3067\u3001Hamlet \u306b\u3064\u3044\u3066\u8abf\u3079\u307e\u3059\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>\u5236\u5fa1\u69cb\u9020\u306a\u3069<\/h2>\n<h3>$forall<\/h3>\n<p>\u7e70\u308a\u8fd4\u3057\u3092\u3059\u308b\u306b\u306f $forall \u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<\/p>\n<p>\u307e\u305a\u3001\u7e70\u308a\u8fd4\u3057\u306b\u4f7f\u7528\u3059\u308b\u305f\u3081\u306e\u5909\u6570 values \u3092 Handler \u3067\u5b9a\u7fa9\u3057\u307e\u3059\u3002\u5909\u6570 message \u306f\u5f8c\u3067\u4f7f\u7528\u3059\u308b\u306e\u3067\u3001\u3064\u3044\u3067\u306b\u5b9a\u7fa9\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"lang:haskell decode:true\">module Handler.Hello where\r\n\r\nimport Import\r\n\r\ngetHelloR :: Handler Html\r\ngetHelloR = do\r\n    let\r\n        message = \"Hello\"\r\n        values = [1..10] :: [Int]\r\n    defaultLayout $(widgetFile \"hello\")<\/pre>\n<p>View (templates\/hello.hamlet) \u3067\u3001\u5909\u6570 values \u306e\u5024\u3092\u4e00\u3064\u305a\u3064\u8868\u793a\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:haskell decode:true\">$forall i &lt;- values\r\n    #{i}<\/pre>\n<h3>$if, $elseif, $else<\/h3>\n<p>\u6761\u4ef6\u5206\u5c90\u3092\u3059\u308b\u306b\u306f $if, $elseif, $else \u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:haskell decode:true\">$if message == \"good morning!\"\r\n    &lt;p&gt;\u304a\u306f\u3088\u3046\uff01\r\n$elseif message == \"hello!\"\r\n    &lt;p&gt;\u3053\u3093\u306b\u3061\u306f\uff01\r\n$else\r\n    &lt;p&gt;\u3055\u3088\u3046\u306a\u3089\uff01<\/pre>\n<h3>$maybe, $nothing<\/h3>\n<p>Maybe \u578b\uff08Maybe Int \u3068\u304b Maybe String \u3068\u304b\uff09\u3092\u6271\u3046\u306b\u306f $maybe \u3068 $nothing \u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:haskell decode:true\">$maybe x &lt;- lucky\r\n    \u904b\u52e2\u306f #{x} \u3067\u3059\u3002\r\n$nothing\r\n    \u904b\u52e2\u3092\u6e2c\u5b9a\u3067\u304d\u307e\u305b\u3093\u3002<\/pre>\n<p>lucky \u304c \u300cJust 777 :: Maybe Int\u300d\u306a\u3069\u3067\u3042\u308c\u3070\u300c\u904b\u52e2\u306f 777 \u3067\u3059\u3002\u300d\u3068\u8868\u793a\u3055\u308c\u3001Nothing \u3067\u3042\u308c\u3070\u300c\u904b\u52e2\u3092\u6e2c\u5b9a\u3067\u304d\u307e\u305b\u3093\u3002\u300d\u3068\u8868\u793a\u3055\u308c\u307e\u3059\u3002<\/p>\n<h3>$case, $of<\/h3>\n<p>\u30d1\u30bf\u30fc\u30f3\u30de\u30c3\u30c1\u3092\u884c\u3046\u306b\u306f $case \u3068 $of \u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<\/p>\n<p>\u4e0a\u8a18\u306e $maybe, $nothing \u306e\u4f8b\u3092 $case, $of \u3092\u4f7f\u7528\u3059\u308b\u3088\u3046\u306b\u66f8\u304d\u63db\u3048\u308b\u3068\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"lang:haskell decode:true\">$case lucky\r\n    $of Just x\r\n        \u904b\u52e2\u306f #{x} \u3067\u3059\u3002\r\n    $of Nothing\r\n        \u904b\u304c\u8db3\u308a\u307e\u305b\u3093\u3002<\/pre>\n<h3>$with<\/h3>\n<p>$with \u3092\u4f7f\u7528\u3059\u308b\u3068\u5f0f\u306e\u5225\u540d\uff08\u30b7\u30ce\u30cb\u30e0\uff09\u3092\u4f5c\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u9577\u3044\u5f0f\u3092\u4f55\u5ea6\u3082\u4f7f\u3046\u5834\u5408\u306f $with \u3092\u4f7f\u7528\u3059\u308b\u3068\u826f\u3055\u305d\u3046\u3067\u3059\u3002<\/p>\n<pre class=\"lang:haskell decode:true\">$with longMessage = message ++ \"!!!!!\"<\/pre>\n<h3>$newline never<\/h3>\n<p>\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306b\u306f\u66f8\u304b\u308c\u3066\u3044\u306a\u3044\u3088\u3046\u306a\u306e\u3067\u3059\u304c\u3001\u300c$newline never\u300d\u3068\u66f8\u3044\u3066\u304a\u304f\u3068 HTML \u751f\u6210\u6642\u306b\u6539\u884c\u304c\u524a\u9664\u3055\u308c\u308b\u3088\u3046\u3067\u3059\u3002<\/p>\n<pre class=\"lang:haskell decode:true\">$newline never<\/pre>\n<p>&nbsp;<\/p>\n<h2>\u5909\u6570\u88dc\u9593: #{ ... }<\/h2>\n<p>\u5909\u6570\u306e\u5024\u3092\u57cb\u3081\u8fbc\u3080\u306b\u306f #{\u5909\u6570\u540d} \u3068\u8a18\u8ff0\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:haskell decode:true\">\u30e1\u30c3\u30bb\u30fc\u30b8\u306f #{message} \u3067\u3059\u3002<\/pre>\n<p>&nbsp;<\/p>\n<h2>Type-Safe URL: @{ ... }<\/h2>\n<p>URL \u3092\u751f\u6210\u3059\u308b\u306b\u306f @{\u30ea\u30bd\u30fc\u30b9\u540d} \u3068\u8a18\u8ff0\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:haskell decode:true\">\u30c8\u30c3\u30d7\u30da\u30fc\u30b8\u306e URL \u306f @{HomeR} \u3067\u3059\u3002\r\n\r\n&lt;a href=@{HomeR}&gt;\u30c8\u30c3\u30d7\u30da\u30fc\u30b8\u306f\u3053\u3061\u3089\uff01&lt;\/a&gt;<\/pre>\n<p>&nbsp;<\/p>\n<h2>Widget \u306e\u57cb\u3081\u8fbc\u307f: ^{ ... }<\/h2>\n<p>Yesod \u3067\u306f\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u306e\u4e2d\u306b\u4ed6\u306e\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3092\u57cb\u3081\u8fbc\u3080\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u57cb\u3081\u8fbc\u3080\u3053\u3068\u304c\u3067\u304d\u308b\u30d1\u30fc\u30c4\u306e\u3053\u3068\u3092 Widget \u3068\u547c\u3073\u307e\u3059\u3002<\/p>\n<p>\u307e\u305a\u306f Widget \u3092\u5b9a\u7fa9\u3057\u3066\u307f\u307e\u3059\u3002\uff08Handler\/Hello.hs\uff09<\/p>\n<pre class=\"lang:haskell decode:true\">sampleWidget :: Widget\r\nsampleWidget = $(widgetFile \"sample-widget\")<\/pre>\n<p>\u6b21\u306b sampleWidget \u7528\u306e\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8 templates\/sample-widget.hamlet \u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:haskell decode:true\">&lt;div&gt;\r\n    Widget \u3067\u3059\u3002<\/pre>\n<p>\u4f5c\u6210\u3057\u305f sampleWidget \u3092\u57cb\u3081\u8fbc\u3080\u306b\u306f\u3001\u6b21\u306e\u3088\u3046\u306b\u8a18\u8ff0\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:haskell decode:true\">^{sampleWidget}<\/pre>\n<p>&nbsp;<\/p>\n<h2>\u307e\u3068\u3081<\/h2>\n<p>\u5236\u5fa1\u69cb\u9020\u306a\u3069\u306f\u52d5\u7684\u306a\u30da\u30fc\u30b8\u3092\u751f\u6210\u3059\u308b\u5834\u5408\u306b\u306f\u5fc5\u9808\u306e\u6a5f\u80fd\u306a\u306e\u3067\u3001\u304d\u3061\u3093\u3068\u628a\u63e1\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u305d\u3046\u3067\u3059\u3002<\/p>\n<p>\u4ed6\u306b\u3082 $maybe \u3084 $case \u306e\u3088\u3046\u306a Haskell \u3060\u304b\u3089\u3053\u305d\u5fc5\u8981\u306a\u6a5f\u80fd\u3084\u3001Widget \u306e\u3088\u3046\u306a\u30d1\u30fc\u30c4\u3092\u7d44\u307f\u5408\u308f\u305b\u308b\u4ed5\u7d44\u307f\u304c\u3042\u308a\u307e\u3057\u305f\u3002<\/p>\n<p>\u3046\u307e\u304f\u4f7f\u3044\u3053\u306a\u305b\u3070 View \u307e\u308f\u308a\u306e\u5b9f\u88c5\u304c\u7dba\u9e97\u306b\u3067\u304d\u308b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3053\u3093\u306b\u3061\u306f\u3001\u9234\u6728\u3067\u3059\u3002<\/p>\n<p>\u4eca\u56de\u306f Yesod \u306e View \u5468\u308a\u3068\u3044\u3046\u3053\u3068\u3067\u3001Hamlet \u306b\u3064\u3044\u3066\u8abf\u3079\u307e\u3059\u3002<\/p>\n<p>&nbsp;<br \/>\n\u5236\u5fa1\u69cb\u9020\u306a\u3069<br \/>\n$forall<br \/>\n\u7e70\u308a\u8fd4\u3057\u3092\u3059\u308b\u306b\u306f $forall \u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<br \/><a href=\"https:\/\/www.techscore.com\/blog\/2013\/10\/18\/yesod%e5%85%a5%e9%96%80-6-hamlet-%e5%88%b6%e5%be%a1%e6%a7%8b%e9%80%a0%e3%82%84widget%e3%81%ae%e5%9f%8b%e3%82%81%e8%be%bc%e3%81%bf%e3%81%aa%e3%81%a9\/\">\u7d9a\u304d\u3092\u8aad\u3080...<\/a><\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[102,18,84],"tags":[99,100],"_links":{"self":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/2786"}],"collection":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/comments?post=2786"}],"version-history":[{"count":1,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/2786\/revisions"}],"predecessor-version":[{"id":17904,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/2786\/revisions\/17904"}],"wp:attachment":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/media?parent=2786"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/categories?post=2786"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/tags?post=2786"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}