{"id":14680,"date":"2014-03-10T16:50:59","date_gmt":"2014-03-10T07:50:59","guid":{"rendered":"http:\/\/www.mocchiblog.com\/?p=14680"},"modified":"2015-04-20T14:56:51","modified_gmt":"2015-04-20T05:56:51","slug":"rails%e3%81%aeviews%e3%83%87%e3%82%a3%e3%83%ac%e3%82%af%e3%83%88%e3%83%aa%e4%bb%a5%e4%b8%8b%e3%81%ae-erb%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e3%82%92slim%e3%81%ab%e4%b8%80%e6%8b%ac%e5%a4%89%e6%8f%9b","status":"publish","type":"post","link":"http:\/\/www.mocchiblog.com\/?p=14680","title":{"rendered":"Rails4\/views\u306eerb\u3092Slim\u306b\u4e00\u62ec\u5909\u63db\u3059\u308bRuby\u30ef\u30f3\u30e9\u30a4\u30ca\u30fc"},"content":{"rendered":"<div id=\"attachment_14683\" style=\"width: 610px\" class=\"wp-caption alignnone\"><img aria-describedby=\"caption-attachment-14683\" loading=\"lazy\" class=\"size-full wp-image-14683\" src=\"http:\/\/www.mocchiblog.com\/wp-content\/images\/2014\/03\/ss-2014-03-10-16.49.49.png\" alt=\"Github\u306b\u516c\u958b\u3055\u308c\u3066\u3044\u308bRuby gem 'html2slim'\" width=\"600\" height=\"353\" \/><p id=\"caption-attachment-14683\" class=\"wp-caption-text\">Github\u306b\u516c\u958b\u3055\u308c\u3066\u3044\u308bRuby gem &#8216;html2slim&#8217;<\/p><\/div>\n<p>slim\u3068Sass\u306b\u6163\u308c\u308b\u3068\u3001\u666e\u901a\u306eCSS\u3084HTML\u3092\u66f8\u304f\u30e2\u30c1\u30d9\u30fc\u30b7\u30e7\u30f3\u304c\u6e67\u3044\u3066\u304d\u307e\u305b\u3093\u3002\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u306e\u30b5\u30a4\u30ba\u306f40%\u7e2e\u5c0f\u3001\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\u6642\u9593\u30823\u5272\u304f\u3089\u3044\u65e9\u304f\u306a\u308b\u306e\u3067\u306f\u306a\u3044\u3067\u3057\u3087\u3046\u304b\u3002\u5b66\u7fd2\u30b3\u30b9\u30c8\u3082\u4f4e\u3044\u306e\u3067Rails\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3067\u983b\u7e41\u306b\u307f\u304b\u3051\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n<p>Github\u306b\u306f <a href=\"https:\/\/github.com\/slim-template\/html2slim\" target=\"_blank\" data-wpel-link=\"external\" rel=\"follow noopener noreferrer\" class=\"ext-link wpel-icon-right\">html2slim<span class=\"wpel-icon wpel-image wpel-icon-3\"><\/span><\/a>\u306e\u3088\u3046\u306a\u3001view\u30d5\u30a1\u30a4\u30eb\u306e\u8a18\u6cd5\u3092\u5909\u63db\u3057\u3066\u304f\u308c\u308bGem\u304c\u3044\u304f\u3064\u304b\u516c\u958b\u3055\u308c\u3066\u3044\u307e\u3059\u304c\u3001Usage\u3092\u898b\u3066\u3082\u30d5\u30a1\u30a4\u30eb\u3092\uff11\u3064\u305a\u3064\u6307\u5b9a\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u3001Rails\u306eapp\/views\/\u4ee5\u4e0b\u306e <strong>erb\u30d5\u30a1\u30a4\u30eb\u3092slim\u306b\u4e00\u62ec\u5909\u63db\u3059\u308b\u305f\u3081\u306e\u30ef\u30f3\u30e9\u30a4\u30ca\u30fc<\/strong> \u306b\u3064\u3044\u3066\u306f\u3001\u30cd\u30c3\u30c8\u4e0a\u3067\u306f\u307b\u3068\u3093\u3069\u8a18\u8ff0\u304c\u898b\u5f53\u305f\u308a\u307e\u305b\u3093\u3002<\/p>\n<p>haml\u306e\u5834\u5408\u306f\u3001<strong>erb2haml<\/strong>\u3092\u5165\u308c\u3066\u3001rake\u30b3\u30de\u30f3\u30c9<\/p>\n<pre># rake haml:convert_erbs<\/pre>\n<p>\u3067\u4e00\u62ec\u5909\u63db\u3067\u304d\u308b\u3063\u307d\u3044\u3093\u3067\u3059\u304c\u3001<strong>Slim<\/strong> \u3067\u306f\u307e\u3060\u60c5\u5831\u6e90\u304c\u5c11\u306a\u304b\u3063\u305f\u306e\u3067\u3001\u4f5c\u6210\u3057\u3066\u52d5\u4f5c\u3067\u304d\u305f\u3082\u306e\u3092\u4ee5\u4e0b\u306b\u30e1\u30e2\u3057\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n<h2>1. HTML\/erb\u3092slim\u306b\u5909\u63db\u3059\u308bGem\u300chtml2slim\u300d\u3092\u5165\u308c\u308b<\/h2>\n<p>slim-template\u3067\u516c\u958b\u3055\u308c\u3066\u3044\u308b\u00a0<a href=\"https:\/\/github.com\/slim-template\/html2slim\" data-wpel-link=\"external\" target=\"_blank\" rel=\"follow noopener noreferrer\" class=\"ext-link wpel-icon-right\">html2slim<span class=\"wpel-icon wpel-image wpel-icon-3\"><\/span><\/a>\u00a0\u306f\u3001html\u3084erb\u3092\u3001slim\u306b\u5909\u63db\u3057\u3066\u304f\u308c\u307e\u3059\u3002\u3042\u304f\u307e\u3067\u30b3\u30f3\u30d0\u30fc\u30bf\u30fc\u306a\u306e\u3067\u3001\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306eGemfile(development) \u306b\u8a18\u8ff0\u3059\u308b\u3088\u308a\u3001\u30ed\u30fc\u30ab\u30eb\u5185\u3067\u5165\u308c\u3066\u304a\u3044\u3066\u826f\u3044\u304b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<pre># gem install html2slim<\/pre>\n<p>Gem\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u3068\u3001<strong>html2slim \u3068 erb2slim \u306e\u30b3\u30de\u30f3\u30c9\u304c\u4f7f\u3048\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059<\/strong>\u3002<\/p>\n<h2>2. app\/views\/\u4ee5\u4e0b\u306e.erb\u3092slim\u306b\u4e00\u62ec\u5909\u63db\u3059\u308bRuby\u30ef\u30f3\u30e9\u30a4\u30ca\u30fc<\/h2>\n<p>Gem\u304c\u5165\u3063\u305f\u72b6\u614b\u3067\u4ee5\u4e0b\u306eRuby\u306e\u30ef\u30f3\u30e9\u30a4\u30ca\u30fc\u3092\u30b3\u30de\u30f3\u30c9\u30e9\u30a4\u30f3\u3067\u6253\u3064\u3068\u5909\u63db\u3057\u3066\u304f\u308c\u307e\u3059\u3002\u4e00\u62ec\u5909\u63db\u3055\u308c\u308b\u306e\u3067 \u5ff5\u306e\u305f\u3081\u76f4\u524d\u306e\u30b3\u30df\u30c3\u30c8\u306b\u623b\u308c\u308b\u3088\u3046\u306bGit\u63a8\u5968\u3002<\/p>\n<pre># for i in app\/views\/**\/*.erb; do erb2slim $i ${i%erb}slim && rm $i; done<\/pre>\n<p>\u3053\u308c\u3067\u30b9\u30ea\u30e0\u306b\u306a\u308a\u307e\u3059\u3002\u51e6\u7406\u7684\u306b\u306f\u30d5\u30a1\u30a4\u30eb\u306e\u66f8\u304d\u63db\u3048\u3067\u306f\u306a\u304f\u3001\u540c\u540d\u306e.slim\u30d5\u30a1\u30a4\u30eb\u3092\u65b0\u898f\u306b\u4f5c\u6210\u3057\u3001\u53e4\u3044.erb\u30d5\u30a1\u30a4\u30eb\u3092\u524a\u9664\u3057\u3066\u3044\u307e\u3059\u3002erb2slim \u306b\u3042\u308b -d option \u306f\u4f7f\u3063\u3066\u3044\u307e\u305b\u3093\u3002<\/p>\n<p>html2slim\u3092\u4f7f\u3046\u5834\u5408\u306f\u3001erb\u3092html\u306b\u7f6e\u304d\u63db\u3048\u3066\u304f\u3060\u3055\u3044\u3002Rails\u4ee5\u5916\u306e\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3067\u3082html\u3092slim\u306b\u3057\u305f\u308a\u3001haml2slim\u3068\u3044\u3046Gem\u3082\u3042\u308b\u3089\u3057\u3044\u306e\u3067\u3001\u3044\u308d\u3044\u308d\u4f7f\u3048\u305d\u3046\u3067\u3059\u3002<\/p>\n<p><a href=\"https:\/\/github.com\/slim-template\" data-wpel-link=\"external\" target=\"_blank\" rel=\"follow noopener noreferrer\" class=\"ext-link wpel-icon-right\">https:\/\/github.com\/slim-template<span class=\"wpel-icon wpel-image wpel-icon-3\"><\/span><\/a><\/p>\n<p>\u8ffd\u8a18\uff1aDevise\u3092\u4f7f\u3063\u3066\u3044\u3066views\/devise\u30d5\u30a9\u30eb\u30c0\u304c\u3042\u308b\u5834\u5408\u306f\u3001\u5408\u308f\u305b\u3066\u4ee5\u4e0b\u306e\u30ef\u30f3\u30e9\u30a4\u30ca\u30fc\u3082\u8a66\u3057\u3066\u4e0b\u3055\u3044\u3002<\/p>\n<pre># for file in app\/views\/devise\/**\/*.erb; do erb2slim $file ${file%erb}slim && rm $file; done<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>slim\u3068Sass\u306b\u6163\u308c\u308b\u3068\u3001\u666e\u901a\u306eCSS\u3084HTML\u3092\u66f8\u304f\u30e2\u30c1\u30d9\u30fc\u30b7\u30e7\u30f3\u304c\u6e67\u3044\u3066\u304d\u307e\u305b\u3093\u3002\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u306e\u30b5\u30a4\u30ba\u306f40%\u7e2e\u5c0f\u3001\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\u6642\u9593\u30823\u5272\u304f\u3089\u3044\u65e9\u304f\u306a\u308b\u306e\u3067\u306f\u306a\u3044\u3067\u3057\u3087\u3046\u304b\u3002\u5b66\u7fd2\u30b3\u30b9\u30c8\u3082\u4f4e\u3044\u306e\u3067Rails\u30d7\u30ed\u30b8\u30a7 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":14683,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[59,61,60],"_links":{"self":[{"href":"http:\/\/www.mocchiblog.com\/index.php?rest_route=\/wp\/v2\/posts\/14680"}],"collection":[{"href":"http:\/\/www.mocchiblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.mocchiblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.mocchiblog.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.mocchiblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=14680"}],"version-history":[{"count":0,"href":"http:\/\/www.mocchiblog.com\/index.php?rest_route=\/wp\/v2\/posts\/14680\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.mocchiblog.com\/index.php?rest_route=\/wp\/v2\/media\/14683"}],"wp:attachment":[{"href":"http:\/\/www.mocchiblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=14680"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.mocchiblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=14680"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.mocchiblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=14680"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}