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.
67 68 69 |
# File 'lib/nanoc/base/result_data/item_rep.rb', line 67 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
74 75 76 |
# File 'lib/nanoc/base/result_data/item_rep.rb', line 74 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.
108 109 110 |
# File 'lib/nanoc/base/result_data/item_rep.rb', line 108 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.
90 91 92 |
# File 'lib/nanoc/base/result_data/item_rep.rb', line 90 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.
83 84 85 |
# File 'lib/nanoc/base/result_data/item_rep.rb', line 83 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]
.
101 102 103 |
# File 'lib/nanoc/base/result_data/item_rep.rb', line 101 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.
164 165 166 |
# File 'lib/nanoc/base/result_data/item_rep.rb', line 164 def forget_progress initialize_content end |
- (Object) temp_filename
154 155 156 |
# File 'lib/nanoc/base/result_data/item_rep.rb', line 154 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
.
175 176 177 |
# File 'lib/nanoc/base/result_data/item_rep.rb', line 175 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.
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 146 147 148 149 150 |
# File 'lib/nanoc/base/result_data/item_rep.rb', line 121 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 |