Module: Nanoc::ItemRep::Private
- Included in:
- Nanoc::ItemRep
- Defined in:
- lib/nanoc/base/result_data/item_rep.rb
Overview
Contains all private methods. Mixed into Nanoc::ItemRep.
Constant Summary
- TMP_TEXT_ITEMS_DIR =
'text_items'
Instance Attribute Summary (collapse)
-
- (Hash) assigns
A hash containing the assigns that will be used in the next filter or layout operation.
-
- (Boolean) compiled
(also: #compiled?)
private
True if this representation has already been compiled during the current or last compilation session; false otherwise.
-
- (Hash<Symbol,String>) content
private
A hash containing the content at all snapshots.
-
- (Hash<Symbol,String>) paths
private
A hash containing the paths for all snapshots.
-
- (Hash<Symbol,String>) raw_paths
private
A hash containing the raw paths (paths including the path to the output directory and the filename) for all snapshots.
-
- (Hash<Symbol,String>) temporary_filenames
readonly
private
A hash containing the paths to the temporary files that filters write binary content to.
Instance Method Summary (collapse)
-
- (void) forget_progress
private
Resets the compilation progress for this item representation.
-
- (Object) temp_filename
-
- (Symbol) type
private
Returns the type of this object.
-
- (void) write(snapshot = :last)
private
Writes the item rep’s compiled content to the rep’s output file.
Instance Attribute Details
- (Hash) assigns
Returns A hash containing the assigns that will be used in the next filter or layout operation. The keys (symbols) will be made available during the next operation.
62 63 64 |
# File 'lib/nanoc/base/result_data/item_rep.rb', line 62 def assigns @assigns end |
- (Boolean) compiled Also known as: compiled?
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.
Returns true if this representation has already been compiled during the current or last compilation session; false otherwise
69 70 71 |
# File 'lib/nanoc/base/result_data/item_rep.rb', line 69 def compiled @compiled end |
- (Hash<Symbol,String>) content
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.
Returns A hash containing the content at all snapshots. The keys correspond with the snapshot names, and the values with the content.
103 104 105 |
# File 'lib/nanoc/base/result_data/item_rep.rb', line 103 def content @content end |
- (Hash<Symbol,String>) paths
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.
Returns A hash containing the paths for all snapshots. The keys correspond with the snapshot names, and the values with the path.
85 86 87 |
# File 'lib/nanoc/base/result_data/item_rep.rb', line 85 def paths @paths end |
- (Hash<Symbol,String>) raw_paths
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.
Returns A hash containing the raw paths (paths including the path to the output directory and the filename) for all snapshots. The keys correspond with the snapshot names, and the values with the path.
78 79 80 |
# File 'lib/nanoc/base/result_data/item_rep.rb', line 78 def raw_paths @raw_paths end |
- (Hash<Symbol,String>) temporary_filenames (readonly)
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.
Returns A hash containing the paths to the
temporary files that filters write binary content to. This is only
used when the item representation is binary. The keys correspond
with the snapshot names, and the values with the filename. When
writing the item representation, the file corresponding with the
requested snapshot (usually :last
) will be copied from
filenames[snapshot]
to raw_paths[snapshot]
.
96 97 98 |
# File 'lib/nanoc/base/result_data/item_rep.rb', line 96 def temporary_filenames @temporary_filenames end |
Instance Method Details
- (void) forget_progress
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.
This method returns an undefined value.
Resets the compilation progress for this item representation. This is necessary when an unmet dependency is detected during compilation.
159 160 161 |
# File 'lib/nanoc/base/result_data/item_rep.rb', line 159 def forget_progress initialize_content end |
- (Object) temp_filename
149 150 151 |
# File 'lib/nanoc/base/result_data/item_rep.rb', line 149 def temp_filename Nanoc::TempFilenameFactory.instance.create(TMP_TEXT_ITEMS_DIR) end |
- (Symbol) type
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.
Returns the type of this object. Will always return :item_rep
,
because this is an item rep. For layouts, this method returns
:layout
.
170 171 172 |
# File 'lib/nanoc/base/result_data/item_rep.rb', line 170 def type :item_rep end |
- (void) write(snapshot = :last)
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.
This method returns an undefined value.
Writes the item rep’s compiled content to the rep’s output file.
This method will send two notifications: one before writing the item representation, and one after. These notifications can be used for generating diffs, for example.
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/nanoc/base/result_data/item_rep.rb', line 116 def write(snapshot = :last) # Get raw path raw_path = self.raw_path(snapshot: snapshot) return if raw_path.nil? # Create parent directory FileUtils.mkdir_p(File.dirname(raw_path)) # Check if file will be created is_created = !File.file?(raw_path) # Notify Nanoc::NotificationCenter.post(:will_write_rep, self, snapshot) if self.binary? temp_path = temporary_filenames[:last] else temp_path = temp_filename File.open(temp_path, 'w') { |io| io.write(@content[:last]) } 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 # Notify Nanoc::NotificationCenter.post(:rep_written, self, raw_path, is_created, is_modified) end |