slim記法を使ってtumblrのテーマを書こうと思うと、slimのシンタックスで書けなくて不便だったので、簡単なヘルパを書いて誤魔化します。
別な応用例として、ちょっと改変すればWordPressやMovableTypeのテーマを作る時にMiddlmanのようなruby界隈の仕組みの恩恵が受けられるでしょう。
middlemanでslim使ってる前提で書きます。
config.rb
# 適当な位置に以下の項目を追加します
require 'lib/tumblr_helper'
helpers TumblrHelper
lib/tumblr_helper.rb
module TumblrHelper
def tumblr_block(tag, &block)
content = capture_html(&block)
"{#{tag}}#{content}{/#{tag}}".html_safe
end
# capture_html というのを使っているが、Railsでは単にcaptureという名前が使われてる事もあるみたい。
# 詳しくは content_tagの実装を追って下さい。
end
使い方は以下の通り
tumblr.slim
body
.main.container
= tumblr_block "block:Posts" do
article
a href="{Permalink}" リンク