/
layout.rb
62 lines (49 loc) · 1.38 KB
/
layout.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# frozen_string_literal: true
module Jekyll
class Layout
include Convertible
# Gets the Site object.
attr_reader :site
# Gets the name of this layout.
attr_reader :name
# Gets the path to this layout.
attr_reader :path
# Gets the path to this layout relative to its base
attr_reader :relative_path
# Gets/Sets the extension of this layout.
attr_accessor :ext
# Gets/Sets the Hash that holds the metadata for this layout.
attr_accessor :data
# Gets/Sets the content of this layout.
attr_accessor :content
# Initialize a new Layout.
#
# site - The Site.
# base - The String path to the source.
# name - The String filename of the post file.
def initialize(site, base, name)
@site = site
@base = base
@name = name
if site.theme && site.theme.layouts_path.eql?(base)
@base_dir = site.theme.root
@path = site.in_theme_dir(base, name)
else
@base_dir = site.source
@path = site.in_source_dir(base, name)
end
@relative_path = @path.sub(@base_dir, "")
self.data = {}
process(name)
read_yaml(base, name)
end
# Extract information from the layout filename.
#
# name - The String filename of the layout file.
#
# Returns nothing.
def process(name)
self.ext = File.extname(name)
end
end
end