Module: Dimples::Writeable
Overview
A mixin class that neatly handles writing out a file.
Instance Method Summary collapse
Instance Method Details
#write(path, context = {}) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/dimples/writeable.rb', line 6 def write(path, context = {}) output = context ? render(context) : contents parent_path = File.dirname(path) FileUtils.mkdir_p(parent_path) unless Dir.exist?(parent_path) File.open(path, 'w+') do |file| file.write(output) end rescue SystemCallError => e = "Failed to write #{path} (#{e.message})" raise Errors::PublishingError, end |