Middleman Ruby Haml 2018年 8月 27日
せっかくなので、Scrapbox に書いた記事を Middleman でコンバートしてみることにした。 そこで問題になるのが、プログラムソースの記載と画像であった。 それぞれ、簡易的なメソッドを書くことで簡単に描画できるようになったので、ここに示しておく。 なお、基本的に画像はスクリーンショットになるので、Scrapbox と同様 Gyazo を利用することにした。require 'lib/custom_helpers.rb'
helpers CustomHelpers
module CustomHelpers
def include_source(source, lang = :bash)
partial 'include_source', locals: {source: source, lang: lang}
end
def include_gyazo(fname, alt)
partial 'include_gyazo', locals: {fname: fname, alt: alt}
end
%pre
%code{class: lang}
= preserve { html_escape source }
.card.border-info.mb-3{style: 'width: 100%;'}
.card-body
%img{src: "https://i.gyazo.com/#{fname}", alt: alt, style: 'width: 100%;'}
.card-footer
= alt
= include_source 'be middleman b'
= include_source current_page.data.include_source, :ruby
include_source: |
%pre
%code{class: lang}
= preserve { html_escape source }
- if current_article
- current_article.tags.each do |key|
= link_to key, tag_path(key), class: 'badge badge-pill badge-info'
- d = current_article.date
= link_to "#{d.year}年", blog_year_path(d.year), class: 'badge badge-pill badge-warning'
= link_to "#{d.month}月", blog_month_path(d.year, d.month), class: 'badge badge-pill badge-warning'
= link_to "#{d.day}日", blog_day_path(d.year, d.month, d.day), class: 'badge badge-pill badge-warning'