Slimã§ã»ã¬ã¯ã¿ã追å ããã¨ãã®æ¸ãæ¹ãåã³ Middleman ã®ç´ æ´ãããã
ãããè¦ç´ ã«ã¤ããidãclassãåçã«ãããæã¨ãã«ãHamlã ã¨ãããªæãã®æ¸ãæ¹ããã
ãã®æ¸ãæ¹ãSlimã ã¨ãã¡ã£ã½ãã¦ã¤ã¾ãããã
%li{class: "item #{item.name}"}
Slimã ã¨ãããªæãã®æ¸ãæ¹ã«ãªãããã
ããããã®ããããã£ã½ããå²ã¨ç´ ã®HTMLã«è¿ãæãã§æ¸ããã®ã§ããã
li[class="item #{item.name}"]
ããã¦æ¡ä»¶ã¤ããã¨ãããªãã£ã½ã
li class="item #{item.name}"
classãè¤æ°ä»ãããã¤1ã¤ã®classã«ã®ã¿æ¡ä»¶ãä»å ããå ´åã¯ãã®ããã«å ¥ãåã«ããã°ããã¿ããã
li class=(if item.present? ? "#{item.name}" : 'no-item')
li class=("#{item.name}" if item.present?)
li class="item #{if item.present? ? "#{item.name}" : 'no-item'}"
li class="item #{"#{item.name}" if item.present?}"
Slim + Middleman ã§éçãµã¤ãä½ã£ã¦ã¿ãã®ãã©ãMiddlemanã¯コンテンツをYamlに置いて外部化して、簡易CMSっぽいものを作るã®ãã¨ã¦ãç°¡åã§é©ãã¦ãããããã«ãããã³ã³ãã³ãã¨ãã³ãã¬ã¼ãããã¬ã¤ã«åé¢ã§ãããéçãµã¤ããªã®ã«ã工夫次第ã§ä¸åé¡ä¼¼è¦ç´ ãã³ããããã«DRYã«ä½ããã®ãã¨ã¦ãç´ æ´ããããRailsã®ActionView::Helpersï¼ã«ä¼¼ããããªã® â»è¿½è¨åç
§ï¼ã使ããããSassãHamlãCompassãCoffeeScriptãããã«ä½¿ãããmiddleman build
ã£ã¦ã³ãã³ãæã¤ã ãã§htmlã®éçãµã¤ãä¸å¼ãã¬ã¬ã¼ã£ã¨ä¸ç¬ã§åãåºãã¦ãããããæ¸ãã ããµã¤ãã®ãªã³ã¯ãç»åãªã©ã®ã¢ã»ãããç¸å¯¾ãã¹ãªã®ã絶対ãã¹ãªã®ããè¨å®ã§ç¨æããã¦ã¦ãconfigã«ä¸è¡æ¸ãã ãã§å¤ãããããå¿
è¦ã«å¿ãã¦zipç´åå¯è½ãªãµã¤ãä¸å¼ãbuildã§ããã«åãåºããããã°ãHerokuã¨ãã«ãããã¤ãã§ããã®ã ã
Middlemanã¯ã¾ããã常æ¥é ããããããã®æ¬²ãããªã¼ã¨æã£ã¦ããã®ãã®ã ã£ããæ ãããWebãã¶ã¤ãã¼ã«ã¨ã£ã¦ã®ã©ã¤ããã§ã³ã¸ã³ã°ã ã
Slim ãåãã¦æ¸ãããã©ããããã·ã³ãã«ã§è¦ãç®ãã¬ã¤ã§è¯ãã§ãããHamlã¨å¯¾ãã¦éããªãã®ã§ãHamlãJadeã«æ
£ãã人ãªãã 群馬の Middleman + Slim エヴァンジェリストである @yterajima さんのこれã¨ãèªãã°5åã§æ¸ããããã«ãªãã|ï¼ãã¤ãï¼ã使ã£ã表è¨ã«ã ãæåå°ãæ
£ããªãã£ããã©ããããããåºæ¥ã¦ãã¦ãè¦è¦çã«ã縦æ£ãå
¥ããã¨ã«ãã£ã¦é層æ§é ããããããããªãã®ãã«ãã³ã¤ã¤ã
ããããMiddlemanãããã§ããã©ãSassããã®å¨è¾ºã¨ãããHamlãSlimã¨ãããRubyå¨ãã¯ãå
¨é¨ã³ãã³ãã©ã¤ã³ãå¿
è¦ã§ããã¨ããå
¥ãå£ã®éå£ä»¥å¤ã¯ãã¨ãã¨ããã¶ã¤ãã¼ã«ã¨ã£ã¦åªããæãããã®ããç°å¢ãªã®ã§ã¯ãªããï¼â¦ã¨æã£ããã©ãããããããå¥ã«ãã¶ã¤ãã¼ã®ããã«ã£ã¦ããã§ããªãã¦ãHTMLã¨ãCSSã¨ãã触ãã¯ãã«ãªã£ãããã°ã©ãéãããã¾ãã®å¹çã®æªãã¸ã®è¦çããããªãã¨ããããã¢ã¬ãã¦ãããã¨ã¢ã¬ããçµæãªã®ã ããã¨æã£ããå½¼ãã®ã³ããã«å¯¾ããæãã¿ãä¸çãè¯ãããå ´æã¸ã¨å¤ãã¦ããã®ã ãæåçã§ããã大å¤ãããããã
ããããã¾ã§ãããããç´ ã®HTMLã¨ãããæ¸ããªãã§ãçãã¦ããããããªæ°ããã¦ããã®ã§ãã¨ã¦ããããããã¨ã¦ãããããã§ãã
#追è¨
ãææããã ãã¾ãããããããActionView::Helpers ãã®ãã®ã§ã¯ãªãã¦ãããã«ä¼¼ãã¦ä½ããããã«ãã¼ã使ããã¨ãããã¨ã§ãããè¨ããã¦ã¿ãã°ããã ããªããã
ä»ã¯ padrino-helpers 㨠sprockets-helpers ã®ä½µç¨ãããããããã¨ããããã¾ããï¼
ä¸ç¹ãactionpackï¼ã¨è¨ãåã¾ãããã¤ï¼ã«ä¾åãã¦ããªãã¯ããªã®ã§ãActionView::Helpersã使ããã®ã§ã¯ãªãã¦MiddlemanãSprocketsãç¨æãããã«ãã¼ã使ããã¨ãããã¨ãªã®ããªãã¨æãã¾ããã⦠http://t.co/97oV0iqTN1
— Uchio KONDO (@udzura) August 5, 2013
@ken_c_lo ã¨è¨ãããå½¹å²ãéã£ã¦ãã¦ãSprocketsã®ãã¤ã¯javascriptãstylesheetçAssetç³»ã§ã link_toãcontent_forãå©ç¨ãããå ´åã¯æ示çã«padrino-helpersã使ãããã«ãªã£ã㨠@yterajima
— Uchio KONDO (@udzura) August 5, 2013
# 追è¨ãã®2
ã¡ã¢ç¨åº¦ã«æ¸ãããã®ãæã£ãããã人ã«èªã¾ãã¦ãã¾ãç
§ãã¦ãããããã®ãæ¸ãã®ããããªã«è¾ãã®ã«ã©ããã¦ã¡ã¢ç¨åº¦ã®ãã®ãªãæ¸ãããã ãããâ¦ããã¦ãããããã®ã»ã©ãã¾ã«èªã¾ãããããã®ãªããªãã ããï¼ããããããã©ï¼ã
ãããããMiddlemanä»ã«ãããæããããã¦æ¸ããããªãã®ã ãã©ãèªåã®ãããªããã°ã©ãã³ã°ç´ 人ããRailsã»ã©é£ãããªããæ®æ®µã®ä»äºã®éçãµã¤ãä½ãã¨ãã®ä¸ã§ãæ¯è¼çæ°è»½ã«ããã°ã©ãã³ã°ã£ã½ãæ°åã®æçãå³ãããã®ãããããè¯ãã¨ããã®ä¸ã¤ã ã¨æããç§ã¯ã»ãã®ã¡ãã£ã¨ãããã£ããã¨ããªãã®ã§ããããªãã®ã ãã©ãMiddleman ã®ãã¼ã¹ã§ãã Sinatra ãããããããããæããªã®ãããããªãã
å
æ¥ã®åå¿è
ã¯Railsããå
¥ãã¹ãã§ãªãã¨ããçãä¸ãã£ã話é¡ãæãåºããèªåãç´ äººRailsãã£ã¦ã¦ç¢ºãã«ãããããããã¨å¤ãã¦é£ãããï¼ã§ãåå趣å³ã ããã£ã¦ã¦ããããããã¾ãããã®ã§ã¯ã¨ãæã£ã¦ãããè¾ãã¯ããªããRails好ãã ããï¼ãããã°ã©ãã³ã°è¦ããããã¶ã¤ãã¼ããã¼ã¯ã¢ããã¼ã«ããæåã®ä¸æ©ã¨ãã¦ä½ãå§ãããªã ä»ã¯ Middleman ãããªã¼ã£ã¦æã£ããæ®éã«èªåã®ä»äºã®ç¯å²å
ã§ãç¡çãå±éºããã¾ããªãããã°ã©ãã³ã°ã®ã¨ãã»ã³ã¹ãå³ãããããçµæçã«æ®æ®µã®ä»äºã楽ã«ãªããã ããä¸ç³äºé³¥ã§ç´ æ´ããããããããã®æ¬²ããã£ãï¼ã£ã¦ãã£ã¨æããã¨æãããã¼ã¿ã¨ãã¥ã¼ãåå²ãããã¨ã®æ義ã身è¿ãªæã§å®æã§ãããã ãViewã ããªãããªãRailsã«è¿ãè¦ç´ ããããMiddlemanãçµã¦Railsã£ã¦ããã®ã¯è¯ããããç´å¾ã ã日本語ドキュメントã @yterajima ããã®å°½åã®ãããã§ããªãå
å®ãã¦ããããããªã«å°ããã¨ããªãã£ãã
ãªãããã®ãã¡ããã¶ã¤ãã¼ï¼ã£ã¦ãããèªåï¼ãéçãµã¤ãã®ã¯ã¼ã¯ããã¼ãããã«æ¥½ã«ããªãããã® Middleman ã®ã«ã¹ã¿ã ãã¬ã¼ã ã¯ã¼ã¯ çãªãã®ã¨ããä½ã£ã¦ã¿ããæ°ããã¦ããããã®ãã¡ããã®ãã¡ãã