黙々とC#

"In a mad world of VBA, only the mad are sane" 『VBAという名の狂った世界で狂っているというのなら私の気は確かだ』

Nanoc4 でパンくずリストを生成する

f:id:d_ymkw:20170316234838j:plain

Nanoc::Helpers::Breadcrumbs使え、以上。という感じなのだけど、備忘録代わりに。

テンプレートファイル内でこんな感じのコードを書いたらOK。

eachメソッドの代わりに、each_with_indexメソッドを使うと先頭や最後尾の要素を手軽に区別できて便利。

<div id="breadcrumb"> 
 <ul><% breadcrumbs_trail.each_with_index do |crumb, i| -%> 
  <%- if i == 0 then -%>
  <%- elsif i == breadcrumbs_trail.size - 1 then -%>
    <li><%= crumb[:title] %> 
  <%- else -%>
    <li><%= link_to(crumb[:title], crumb.reps.find { |r| r.name == :default }) %> 
  <%- end -%>
 <%- end %></ul>
</div>