Class: Decant::Content
Class Attribute Summary collapse
-
.collection ⇒ Collection
readonly
When using define the returned Content subclass comes with its own Collection instance.
Attributes inherited from File
Class Method Summary collapse
-
.all ⇒ Array<Content>
Return all matching files within Content.collection.
-
.find(pattern) ⇒ Content
Find a file within the Content.collection by passing its relative path.
-
.frontmatter(*attrs) ⇒ Object
Define convenience frontmatter readers - see define.
Instance Method Summary collapse
-
#relative_path ⇒ String
The relative path of the file within its collection.
-
#slug ⇒ String
The extension-less relative path of the file within its collection.
Methods inherited from File
#content, #frontmatter, #frontmatter?, #initialize, #read
Constructor Details
This class inherits a constructor from Decant::File
Class Attribute Details
.collection ⇒ Collection (readonly)
When using Decant.define the returned Decant::Content subclass comes with its own Decant::Collection instance.
12 13 14 |
# File 'lib/decant/content.rb', line 12 def collection @collection end |
Class Method Details
.all ⇒ Array<Content>
Return all matching files within collection.
17 18 19 |
# File 'lib/decant/content.rb', line 17 def all collection.entries.map { |path| new(path) } end |
.find(pattern) ⇒ Content
Find a file within the collection by passing its relative path.
34 35 36 37 38 |
# File 'lib/decant/content.rb', line 34 def find(pattern) path = collection.find(pattern) raise FileNotFound, %(Couldn't find "#{pattern}" in "#{collection.dir}") unless path new(path) end |
.frontmatter(*attrs) ⇒ Object
Define convenience frontmatter readers - see Decant.define.
43 44 45 46 47 48 49 |
# File 'lib/decant/content.rb', line 43 def frontmatter(*attrs) attrs.each do |name| define_method name do frontmatter&.[](name.to_sym) end end end |
Instance Method Details
#relative_path ⇒ String
The relative path of the file within its collection.
62 63 64 |
# File 'lib/decant/content.rb', line 62 def relative_path self.class.collection.relative_path_for(path) end |
#slug ⇒ String
The extension-less relative path of the file within its collection.
76 77 78 |
# File 'lib/decant/content.rb', line 76 def slug self.class.collection.slug_for(path) end |