11
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

slimでTumblrのテーマを書く

Posted at

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}" リンク
11
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?