Class: Dimples::Document
- Inherits:
-
Object
show all
- Defined in:
- lib/dimples/document.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(path = nil, metadata = {}) ⇒ Document
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/dimples/document.rb', line 9
def initialize(path = nil, metadata = {})
@path = path
if @path
@metadata, @contents = Dimples::FrontMatter.parse(File.read(path))
else
@metadata = {}
@contents = ""
end
@metadata.merge!(metadata)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *_args) ⇒ Object
61
62
63
|
# File 'lib/dimples/document.rb', line 61
def method_missing(method_name, *_args)
@metadata[method_name] if @metadata.key?(method_name)
end
|
Instance Attribute Details
#contents ⇒ Object
Returns the value of attribute contents.
7
8
9
|
# File 'lib/dimples/document.rb', line 7
def contents
@contents
end
|
Returns the value of attribute metadata.
7
8
9
|
# File 'lib/dimples/document.rb', line 7
def metadata
@metadata
end
|
#path ⇒ Object
Returns the value of attribute path.
7
8
9
|
# File 'lib/dimples/document.rb', line 7
def path
@path
end
|
#rendered_contents ⇒ Object
Returns the value of attribute rendered_contents.
7
8
9
|
# File 'lib/dimples/document.rb', line 7
def rendered_contents
@rendered_contents
end
|
Instance Method Details
#basename ⇒ Object
26
27
28
|
# File 'lib/dimples/document.rb', line 26
def basename
@metadata.fetch(:filename, "index")
end
|
#extension ⇒ Object
30
31
32
|
# File 'lib/dimples/document.rb', line 30
def extension
@metadata.fetch(:extension, "html")
end
|
#filename ⇒ Object
22
23
24
|
# File 'lib/dimples/document.rb', line 22
def filename
"#{basename}.#{extension}"
end
|
#layout ⇒ Object
34
35
36
|
# File 'lib/dimples/document.rb', line 34
def layout
@metadata.fetch(:layout, nil)
end
|
#render(context = {}, content = "") ⇒ Object
38
39
40
41
42
43
44
45
|
# File 'lib/dimples/document.rb', line 38
def render(context = {}, content = "")
context_obj = Object.new
context.each do |key, value|
context_obj.instance_variable_set("@#{key}", value)
end
@rendered_contents = renderer.render(context_obj) { content }
end
|