Skip to content

Instantly share code, notes, and snippets.

@KitaitiMakoto
Created January 24, 2016 16:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KitaitiMakoto/6860aa88da18866f313f to your computer and use it in GitHub Desktop.
Save KitaitiMakoto/6860aa88da18866f313f to your computer and use it in GitHub Desktop.
Middlemanで「変更なし」「作成」「削除」「変更」の状態を取る ref: http://qiita.com/KitaitiMakoto/items/ca3792f75270b533d37c
class CatchChange < ::Middleman::Extension
def before_build(builder)
@mode = mode = Hash.new {|mode, event_type| mode[event_type] = []}
builder.on_build_event do |event_type, target, extra|
p event_type # => :identicalなど
p target # => #<Pathname:build/2015/11/06.amp.html>など、出力先のパス
p extra # => nil 「on_build_event」では常にnil
case event_type
when :identical
# 変更なし
when :created
# 新規作成
when :deleted
# 削除
when :updated
# 内容の変更
end
# こうしておくとafter_buildなんかで@modeを参照することでこの情報を使える
mode[event_type] << target
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment