Created
January 24, 2016 16:46
-
-
Save KitaitiMakoto/6860aa88da18866f313f to your computer and use it in GitHub Desktop.
Middlemanで「変更なし」「作成」「削除」「変更」の状態を取る ref: http://qiita.com/KitaitiMakoto/items/ca3792f75270b533d37c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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