Class: Perron::Resource
- Inherits:
-
Object
show all
- Includes:
- ActiveModel::Validations, Adjacency, Associations, ClassMethods, Configuration, Core, Previewable, Publishable, ReadingTime, Scopes, Searchable, Sourceable, Sweeper, TableOfContent
- Defined in:
- lib/perron/resource.rb,
lib/perron/resource/core.rb,
lib/perron/resource/slug.rb,
lib/perron/resource/scopes.rb,
lib/perron/resource/sweeper.rb,
lib/perron/resource/metadata.rb,
lib/perron/resource/renderer.rb,
lib/perron/resource/adjacency.rb,
lib/perron/resource/separator.rb,
lib/perron/resource/searchable.rb,
lib/perron/resource/sourceable.rb,
lib/perron/resource/previewable.rb,
lib/perron/resource/publishable.rb,
lib/perron/resource/associations.rb,
lib/perron/resource/reading_time.rb,
lib/perron/resource/class_methods.rb,
lib/perron/resource/configuration.rb,
lib/perron/resource/table_of_content.rb
Defined Under Namespace
Modules: Adjacency, Associations, ClassMethods, Configuration, Core, Previewable, Publishable, ReadingTime, Renderer, Scopes, Searchable, Sourceable, Sweeper, TableOfContent
Classes: Metadata, Separator, Slug
Instance Attribute Summary collapse
Instance Method Summary
collapse
#table_of_content
Methods included from Sweeper
#extracted_headings, #sweeped_content
Methods included from Sourceable
#source, #source_backed?, #source_template
#estimated_reading_time
Methods included from Core
#association_value, #model_name, #persisted?, #to_model, #to_partial_path
Constructor Details
#initialize(file_path) ⇒ Resource
Returns a new instance of Resource.
43
44
45
46
47
48
49
|
# File 'lib/perron/resource.rb', line 43
def initialize(file_path)
@errors = ActiveModel::Errors.new(self)
@file_path = file_path
@id = generate_id
raise Errors::FileNotFoundError, "No such file: #{file_path}" unless File.exist?(file_path)
end
|
Instance Attribute Details
#file_path ⇒ Object
Returns the value of attribute file_path.
41
42
43
|
# File 'lib/perron/resource.rb', line 41
def file_path
@file_path
end
|
#id ⇒ Object
Returns the value of attribute id.
41
42
43
|
# File 'lib/perron/resource.rb', line 41
def id
@id
end
|
Instance Method Details
#collection ⇒ Object
90
|
# File 'lib/perron/resource.rb', line 90
def collection = Collection.new(self.class.model_name.collection)
|
#filename ⇒ Object
61
|
# File 'lib/perron/resource.rb', line 61
def filename = File.basename(@file_path)
|
#inline(layout: "application", **options) ⇒ Object
86
87
88
|
# File 'lib/perron/resource.rb', line 86
def inline(layout: "application", **options)
{html: content, layout: layout}.merge(options)
end
|
67
68
69
70
71
72
73
|
# File 'lib/perron/resource.rb', line 67
def metadata
Perron::Resource::Metadata.new(
resource: self,
frontmatter: frontmatter,
collection: collection
).data
end
|
#pluck(*attributes) ⇒ Object
51
52
53
54
55
56
57
58
59
|
# File 'lib/perron/resource.rb', line 51
def pluck(*attributes)
raise ArgumentError, "wrong number of arguments (given 0, expected 1+)" if attributes.empty?
if attributes.size == 1
public_send(attributes.first)
else
attributes.map { |attr| public_send(attr) }
end
end
|
#raw_content ⇒ Object
Also known as:
raw
75
|
# File 'lib/perron/resource.rb', line 75
def raw_content = File.read(@file_path)
|
#root? ⇒ Boolean
95
96
97
|
# File 'lib/perron/resource.rb', line 95
def root?
slug == "/"
end
|
#slug ⇒ Object
Also known as:
path, to_param