lib/hx.rb in hx-0.4.1 vs lib/hx.rb in hx-0.5.0

- old
+ new

@@ -476,16 +476,55 @@ def initialize(output_dir) @output_dir = Pathname.new(output_dir) end def build_file(path, entry) + build_file_helper(path, entry, false) + end + + def build_file_if_updated(path, entry) + build_file_helper(path, entry, true) + end + + def build_file_helper(path, entry, update_only) filename = @output_dir + path + return self if update_only and filename.exist? and \ + entry['updated'] and filename.mtime >= entry['updated'] dirname = filename.parent dirname.mkpath() filename.open("wb") do |stream| stream.write entry['content'].to_s end self + end + private :build_file_helper +end + +class LazyContent + def initialize(&block) + raise ArgumentError, "No block given" unless block + @content = nil + @block = block + end + + def to_s + if @block + @content = @block.call + @block = nil + end + @content + end + + def to_yaml(*args) + to_s.to_yaml(*args) + end + + def to_json(*args) + to_s.to_json(*args) + end + + def to_liquid(*args) + to_s.to_liquid(*args) end end end