Class: Nanoc::Int::ItemRepWriter Private
- Inherits:
-
Object
- Object
- Nanoc::Int::ItemRepWriter
- Defined in:
- lib/nanoc/base/services/item_rep_writer.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Constant Summary collapse
- TMP_TEXT_ITEMS_DIR =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
'text_items'.freeze
Instance Method Summary collapse
- #temp_filename ⇒ Object private
- #write(item_rep, raw_path) ⇒ Object private
Instance Method Details
#temp_filename ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
40 41 42 |
# File 'lib/nanoc/base/services/item_rep_writer.rb', line 40 def temp_filename Nanoc::Int::TempFilenameFactory.instance.create(TMP_TEXT_ITEMS_DIR) end |
#write(item_rep, raw_path) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/nanoc/base/services/item_rep_writer.rb', line 6 def write(item_rep, raw_path) # Create parent directory FileUtils.mkdir_p(File.dirname(raw_path)) # Check if file will be created is_created = !File.file?(raw_path) # Notify Nanoc::Int::NotificationCenter.post( :will_write_rep, item_rep, raw_path ) content = item_rep.snapshot_contents[:last] if content.binary? temp_path = content.filename else temp_path = temp_filename File.write(temp_path, content.string) end # Check whether content was modified is_modified = is_created || !FileUtils.identical?(raw_path, temp_path) # Write FileUtils.cp(temp_path, raw_path) if is_modified item_rep.modified = is_modified # Notify Nanoc::Int::NotificationCenter.post( :rep_written, item_rep, raw_path, is_created, is_modified ) end |