Class: Nanoc::Int::ItemRep Private

Inherits:
Object
  • Object
show all
Includes:
ContractsSupport
Defined in:
lib/nanoc/base/entities/item_rep.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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ContractsSupport

included

Constructor Details

#initialize(item, name) ⇒ ItemRep

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 new instance of ItemRep.

Parameters:



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/nanoc/base/entities/item_rep.rb', line 36

def initialize(item, name)
  # Set primary attributes
  @item   = item
  @name   = name

  # Set default attributes
  @raw_paths  = {}
  @paths      = {}
  @snapshot_defs = []
  initialize_content

  # Reset flags
  @compiled = false
end

Instance Attribute Details

#compiledBoolean 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:

  • (Boolean)


10
11
12
# File 'lib/nanoc/base/entities/item_rep.rb', line 10

def compiled
  @compiled
end

#itemNanoc::Int::Item (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:



20
21
22
# File 'lib/nanoc/base/entities/item_rep.rb', line 20

def item
  @item
end

#modifiedBoolean Also known as: modified?

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:

  • (Boolean)


29
30
31
# File 'lib/nanoc/base/entities/item_rep.rb', line 29

def modified
  @modified
end

#nameSymbol (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:

  • (Symbol)


23
24
25
# File 'lib/nanoc/base/entities/item_rep.rb', line 23

def name
  @name
end

#pathsHash<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:



17
18
19
# File 'lib/nanoc/base/entities/item_rep.rb', line 17

def paths
  @paths
end

#raw_pathsHash<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:



14
15
16
# File 'lib/nanoc/base/entities/item_rep.rb', line 14

def raw_paths
  @raw_paths
end

#snapshot_contentsHash<Symbol,Nanoc::Int::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:



7
8
9
# File 'lib/nanoc/base/entities/item_rep.rb', line 7

def snapshot_contents
  @snapshot_contents
end

#snapshot_defsEnumerable<Nanoc::Int:SnapshotDef]

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 Enumerable<Nanoc::Int:SnapshotDef].

Returns:

  • (Enumerable<Nanoc::Int:SnapshotDef])

    Enumerable<Nanoc::Int:SnapshotDef]



26
27
28
# File 'lib/nanoc/base/entities/item_rep.rb', line 26

def snapshot_defs
  @snapshot_defs
end

Instance Method Details

#binary?Boolean

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:

  • (Boolean)


52
53
54
# File 'lib/nanoc/base/entities/item_rep.rb', line 52

def binary?
  @snapshot_contents[:last].binary?
end

#compiled_content(snapshot: nil) ⇒ 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 the compiled content from a given snapshot.

Parameters:

  • snapshot (Symbol) (defaults to: nil)

    The name of the snapshot from which to fetch the compiled content. By default, the returned compiled content will be the content compiled right before the first layout call (if any).

Returns:

  • (String)

    The compiled content at the given snapshot (or the default snapshot if no snapshot is specified)



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/nanoc/base/entities/item_rep.rb', line 66

def compiled_content(snapshot: nil)
  # Make sure we're not binary
  if binary?
    raise Nanoc::Int::Errors::CannotGetCompiledContentOfBinaryItem.new(self)
  end

  # Get name of last pre-layout snapshot
  snapshot_name = snapshot || (@snapshot_contents[:pre] ? :pre : :last)
  is_moving = [:pre, :post, :last].include?(snapshot_name)

  # Check existance of snapshot
  snapshot_def = snapshot_defs.reverse.find { |sd| sd.name == snapshot_name }
  if !is_moving && (snapshot_def.nil? || !snapshot_def.final?)
    raise Nanoc::Int::Errors::NoSuchSnapshot.new(self, snapshot_name)
  end

  # Verify snapshot is usable
  is_still_moving =
    case snapshot_name
    when :post, :last
      true
    when :pre
      snapshot_def.nil? || !snapshot_def.final?
    end
  is_usable_snapshot = @snapshot_contents[snapshot_name] && (compiled? || !is_still_moving)
  unless is_usable_snapshot
    raise Nanoc::Int::Errors::UnmetDependency.new(self)
  end

  @snapshot_contents[snapshot_name].string
end

#forget_progressvoid

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.



143
144
145
146
# File 'lib/nanoc/base/entities/item_rep.rb', line 143

def forget_progress
  initialize_content
  nil
end

#inspectObject

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.



157
158
159
# File 'lib/nanoc/base/entities/item_rep.rb', line 157

def inspect
  "<#{self.class} name=\"#{name}\" binary=#{binary?} raw_path=\"#{raw_path}\" item.identifier=\"#{item.identifier}\">"
end

#path(snapshot: :last) ⇒ 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 the item rep’s path, as used when being linked to. It starts with a slash and it is relative to the output directory. It does not include the path to the output directory. It will not include the filename if the filename is an index filename.

Parameters:

  • snapshot (Symbol) (defaults to: :last)

    The snapshot for which the path should be returned

Returns:

  • (String)

    The item rep’s path



132
133
134
# File 'lib/nanoc/base/entities/item_rep.rb', line 132

def path(snapshot: :last)
  @paths[snapshot]
end

#raw_path(snapshot: :last) ⇒ 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 the item rep’s raw path. It includes the path to the output directory and the full filename.

Parameters:

  • snapshot (Symbol) (defaults to: :last)

    The snapshot for which the path should be returned

Returns:

  • (String)

    The item rep’s path



118
119
120
# File 'lib/nanoc/base/entities/item_rep.rb', line 118

def raw_path(snapshot: :last)
  @raw_paths[snapshot]
end

#referenceObject

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 an object that can be used for uniquely identifying objects.

Returns:

  • (Object)

    An unique reference to this object



153
154
155
# File 'lib/nanoc/base/entities/item_rep.rb', line 153

def reference
  [:item_rep, item.identifier, name]
end

#snapshot?(snapshot_name) ⇒ Boolean Also known as: has_snapshot?

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.

Checks whether content exists at a given snapshot.

Returns:

  • (Boolean)

    True if content exists for the snapshot with the given name, false otherwise

Since:

  • 3.2.0



105
106
107
# File 'lib/nanoc/base/entities/item_rep.rb', line 105

def snapshot?(snapshot_name)
  !@snapshot_contents[snapshot_name].nil?
end