Class: Mill::Resource
- Inherits:
-
Object
show all
- Defined in:
- lib/mill/resource.rb,
lib/mill/resources/dir.rb,
lib/mill/resources/blob.rb,
lib/mill/resources/feed.rb,
lib/mill/resources/text.rb,
lib/mill/resources/image.rb,
lib/mill/resources/robots.rb,
lib/mill/resources/sitemap.rb,
lib/mill/resources/redirect.rb,
lib/mill/resources/stylesheet.rb,
lib/mill/resources/google_site_verification.rb
Defined Under Namespace
Classes: Blob, Feed, GoogleSiteVerification, Image, Index, Redirect, Robots, Sitemap, Stylesheet, Text
Constant Summary
collapse
- FileTypes =
[]
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(input_file: nil, output_file: nil, date: nil, public: false, content: nil, site: nil) ⇒ Resource
Returns a new instance of Resource.
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/mill/resource.rb', line 16
def initialize(input_file: nil,
output_file: nil,
date: nil,
public: false,
content: nil,
site: nil)
if input_file
@input_file = Path.new(input_file)
@date = input_file.mtime.to_datetime
else
@date = DateTime.now
end
if output_file
@output_file = Path.new(output_file)
@path = '/' + @output_file.relative_to(site.output_dir).to_s
end
self.date = date if date
self.public = public
@content = content
@site = site
end
|
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
12
13
14
|
# File 'lib/mill/resource.rb', line 12
def content
@content
end
|
#date ⇒ Object
Returns the value of attribute date.
10
11
12
|
# File 'lib/mill/resource.rb', line 10
def date
@date
end
|
Returns the value of attribute input_file.
7
8
9
|
# File 'lib/mill/resource.rb', line 7
def input_file
@input_file
end
|
#node ⇒ Object
Returns the value of attribute node.
14
15
16
|
# File 'lib/mill/resource.rb', line 14
def node
@node
end
|
#output_file ⇒ Object
Returns the value of attribute output_file.
8
9
10
|
# File 'lib/mill/resource.rb', line 8
def output_file
@output_file
end
|
#path ⇒ Object
Returns the value of attribute path.
9
10
11
|
# File 'lib/mill/resource.rb', line 9
def path
@path
end
|
#public ⇒ Object
Returns the value of attribute public.
11
12
13
|
# File 'lib/mill/resource.rb', line 11
def public
@public
end
|
#site ⇒ Object
Returns the value of attribute site.
13
14
15
|
# File 'lib/mill/resource.rb', line 13
def site
@site
end
|
Instance Method Details
#absolute_uri ⇒ Object
108
109
110
|
# File 'lib/mill/resource.rb', line 108
def absolute_uri
@site.site_uri + uri
end
|
#build ⇒ Object
128
129
130
|
# File 'lib/mill/resource.rb', line 128
def build
end
|
#change_frequency ⇒ Object
116
117
118
|
# File 'lib/mill/resource.rb', line 116
def change_frequency
:weekly
end
|
#children ⇒ Object
99
100
101
|
# File 'lib/mill/resource.rb', line 99
def children
@node.children.map(&:content).compact
end
|
#final_content ⇒ Object
120
121
122
|
# File 'lib/mill/resource.rb', line 120
def final_content
@content
end
|
#inspect ⇒ Object
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/mill/resource.rb', line 76
def inspect
"<%p> input_file: %p, output_file: %p, path: %s, date: %s, public: %p, content: <%p>, parent: %p, siblings: %p, children: %p" % [
self.class,
@input_file ? @input_file.relative_to(@site.input_dir).to_s : nil,
@output_file ? @output_file.relative_to(@site.output_dir).to_s : nil,
@path,
@date.to_s,
@public,
@content&.class,
parent&.path,
siblings.map(&:path),
children.map(&:path),
]
end
|
#load ⇒ Object
124
125
126
|
# File 'lib/mill/resource.rb', line 124
def load
end
|
#parent ⇒ Object
91
92
93
|
# File 'lib/mill/resource.rb', line 91
def parent
@node.parent&.content
end
|
#public? ⇒ Boolean
64
65
66
|
# File 'lib/mill/resource.rb', line 64
def public?
@public == true
end
|
#redirect? ⇒ Boolean
72
73
74
|
# File 'lib/mill/resource.rb', line 72
def redirect?
kind_of?(Resource::Redirect)
end
|
#save ⇒ Object
132
133
134
135
136
137
138
139
140
141
142
143
144
|
# File 'lib/mill/resource.rb', line 132
def save
@output_file.dirname.mkpath
if (content = final_content)
@output_file.write(content.to_s)
@output_file.utime(@date.to_time, @date.to_time)
elsif @input_file
@input_file.copy(@output_file)
else
raise Error, "Can't build resource without content or input file: #{path}"
end
end
|
#siblings ⇒ Object
95
96
97
|
# File 'lib/mill/resource.rb', line 95
def siblings
@node.siblings.map(&:content).compact
end
|
#tag_uri ⇒ Object
112
113
114
|
# File 'lib/mill/resource.rb', line 112
def tag_uri
@site.tag_uri + uri
end
|
#text? ⇒ Boolean
68
69
70
|
# File 'lib/mill/resource.rb', line 68
def text?
kind_of?(Resource::Text) && public?
end
|
#uri ⇒ Object
103
104
105
106
|
# File 'lib/mill/resource.rb', line 103
def uri
raise Error, "#{@input_file}: No path defined for #{self.class}" unless @path
Addressable::URI.encode(@path, Addressable::URI)
end
|