Module: Nanoc3::ItemRep::Private
- Included in:
- Nanoc3::ItemRep
- Defined in:
- lib/nanoc3/base/result_data/item_rep.rb
Overview
Contains all private methods. Mixed into Nanoc3::ItemRep.
Instance Attribute Summary collapse
-
#assigns ⇒ Hash
A hash containing the assigns that will be used in the next filter or layout operation.
-
#compiled ⇒ Boolean
(also: #compiled?)
private
True if this representation has already been compiled during the current or last compilation session; false otherwise.
-
#content ⇒ Hash<Symbol,String>
private
A hash containing the content at all snapshots.
-
#paths ⇒ Hash<Symbol,String>
private
A hash containing the paths for all snapshots.
-
#raw_paths ⇒ Hash<Symbol,String>
private
A hash containing the raw paths (paths including the path to the output directory and the filename) for all snapshots.
-
#temporary_filenames ⇒ Hash<Symbol,String>
readonly
private
A hash containing the paths to the temporary files that filters write binary content to.
Instance Method Summary collapse
-
#forget_progress ⇒ void
private
Resets the compilation progress for this item representation.
-
#type ⇒ Symbol
private
Returns the type of this object.
-
#write(snapshot = :last) ⇒ void
private
Writes the item rep’s compiled content to the rep’s output file.
Instance Attribute Details
#assigns ⇒ Hash
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/nanoc3/base/result_data/item_rep.rb', line 67 def assigns @assigns end |
#compiled ⇒ Boolean 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/nanoc3/base/result_data/item_rep.rb', line 74 def compiled @compiled end |
#content ⇒ Hash<Symbol,String>
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/nanoc3/base/result_data/item_rep.rb', line 108 def content @content end |
#paths ⇒ Hash<Symbol,String>
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/nanoc3/base/result_data/item_rep.rb', line 90 def paths @paths end |
#raw_paths ⇒ Hash<Symbol,String>
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/nanoc3/base/result_data/item_rep.rb', line 83 def raw_paths @raw_paths end |
#temporary_filenames ⇒ Hash<Symbol,String> (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` to `raw_paths`.
101 102 103 |
# File 'lib/nanoc3/base/result_data/item_rep.rb', line 101 def temporary_filenames @temporary_filenames end |
Instance Method Details
#forget_progress ⇒ void
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.
174 175 176 |
# File 'lib/nanoc3/base/result_data/item_rep.rb', line 174 def forget_progress initialize_content end |
#type ⇒ Symbol
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`.
185 186 187 |
# File 'lib/nanoc3/base/result_data/item_rep.rb', line 185 def type :item_rep end |
#write(snapshot = :last) ⇒ void
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.
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 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/nanoc3/base/result_data/item_rep.rb', line 122 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) # Calculate characteristics of old content if File.file?(raw_path) hash_old = Pathname.new(raw_path).checksum size_old = File.size(raw_path) end # Notify Nanoc3::NotificationCenter.post(:will_write_rep, self, snapshot) if self.binary? # Calculate characteristics of new content size_new = File.size(temporary_filenames[:last]) hash_new = Pathname.new(temporary_filenames[:last]).checksum if size_old == size_new # Check whether content was modified is_modified = (size_old != size_new || hash_old != hash_new) # Copy if is_modified FileUtils.cp(temporary_filenames[:last], raw_path) end else # Check whether content was modified is_modified = (!File.file?(raw_path) || File.read(raw_path) != @content[:last]) # Write if is_modified File.open(raw_path, 'w') { |io| io.write(@content[:last]) } end end # Notify Nanoc3::NotificationCenter.post(:rep_written, self, raw_path, is_created, is_modified) end |