Class: Yuzu::Core::WebsiteFile
Constant Summary
Constants included
from Yuzu::Core
BOLD, ENDC, WHITE
Instance Attribute Summary collapse
Attributes inherited from WebsiteBase
#kind
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Filters
catalog_for, get_kwds
Methods included from Yuzu::Core
get_paginated_path
Methods inherited from WebsiteBase
#==, #asset?, #blog_folder, #children, #config, #default_stash, #file?, #folder?, #generated?, #get_link_url, #get_remote_path, #hidden?, #image?, #in_blog?, #is_blog?, #is_processable?, #link_to_self, #link_url, #processable?, #remote_path, #resource?, #root, #root?, #stash
Constructor Details
#initialize(path, parent, page = 1) ⇒ WebsiteFile
Returns a new instance of WebsiteFile.
74
75
76
77
78
79
80
81
82
|
# File 'lib/yuzu/core/website_file.rb', line 74
def initialize(path, parent, page=1)
@path = path
raise "@path is nil for #{self}" if @path.nil?
@parent = parent
@page = page
@kind = :file
end
|
Instance Attribute Details
Returns the value of attribute page.
72
73
74
|
# File 'lib/yuzu/core/website_file.rb', line 72
def page
@page
end
|
Returns the value of attribute parent.
72
73
74
|
# File 'lib/yuzu/core/website_file.rb', line 72
def parent
@parent
end
|
Returns the value of attribute path.
72
73
74
|
# File 'lib/yuzu/core/website_file.rb', line 72
def path
@path
end
|
Instance Method Details
97
98
99
|
# File 'lib/yuzu/core/website_file.rb', line 97
def author
config.author
end
|
113
114
115
|
# File 'lib/yuzu/core/website_file.rb', line 113
def basename
@path.basename
end
|
The user-facing entry for post.contents in the Haml templates.
214
215
216
|
# File 'lib/yuzu/core/website_file.rb', line 214
def contents
rendered_contents
end
|
#created_at ⇒ Object
153
154
155
|
# File 'lib/yuzu/core/website_file.rb', line 153
def created_at
@created_at ||= @path.pathname.ctime
end
|
109
110
111
|
# File 'lib/yuzu/core/website_file.rb', line 109
def filename
@path.filename
end
|
223
224
225
|
# File 'lib/yuzu/core/website_file.rb', line 223
def filters
Filter.filters
end
|
#get_prefiltered_contents ⇒ Object
171
172
173
174
175
176
177
|
# File 'lib/yuzu/core/website_file.rb', line 171
def get_prefiltered_contents
tr = raw_contents
prefilters.each do |filter|
tr = filter.process(self, tr)
end
tr
end
|
#get_processed_contents ⇒ Object
186
187
188
189
190
191
192
|
# File 'lib/yuzu/core/website_file.rb', line 186
def get_processed_contents
tr = prefiltered_contents
(mainfilters + postfilters).each do |filter|
tr = filter.process(self, tr)
end
tr
end
|
#get_raw_contents ⇒ Object
146
147
148
149
150
151
|
# File 'lib/yuzu/core/website_file.rb', line 146
def get_raw_contents
f = File.open(@path.absolute, "r")
contents = f.read
f.close
contents
end
|
#home? ⇒ Boolean
101
102
103
|
# File 'lib/yuzu/core/website_file.rb', line 101
def home?
parent.root? and index?
end
|
#html_contents ⇒ Object
Renders the full, rendered HTML to write to disk.
219
220
221
|
# File 'lib/yuzu/core/website_file.rb', line 219
def html_contents
layout_contents
end
|
#index? ⇒ Boolean
105
106
107
|
# File 'lib/yuzu/core/website_file.rb', line 105
def index?
basename == "index" or basename.include?("index_")
end
|
202
203
204
|
# File 'lib/yuzu/core/website_file.rb', line 202
def layout
@layout ||= Yuzu::Core::Layout.new(template)
end
|
#layout_contents ⇒ Object
Presents the rendered_contents placed into its layout. The postprocessors act on this to produce the values needed for html_contents.
208
209
210
|
# File 'lib/yuzu/core/website_file.rb', line 208
def layout_contents
layout.render(self)
end
|
#link_root ⇒ Object
130
131
132
|
# File 'lib/yuzu/core/website_file.rb', line 130
def link_root
linkroot
end
|
#mainfilters ⇒ Object
231
232
233
|
# File 'lib/yuzu/core/website_file.rb', line 231
def mainfilters
@mainfilters ||= filters.values.select {|filt| filt.filter_type.include?(:filter)}
end
|
#markdown? ⇒ Boolean
121
122
123
|
# File 'lib/yuzu/core/website_file.rb', line 121
def markdown?
@path.markdown?
end
|
#modified_at ⇒ Object
157
158
159
|
# File 'lib/yuzu/core/website_file.rb', line 157
def modified_at
@modified_at ||= @path.pathname.mtime
end
|
93
94
95
|
# File 'lib/yuzu/core/website_file.rb', line 93
def name
post_title
end
|
#output_filename ⇒ Object
117
118
119
|
# File 'lib/yuzu/core/website_file.rb', line 117
def output_filename
processable? ? @path.with_extension(extension).filename : filename
end
|
#paginated? ⇒ Boolean
134
135
136
|
# File 'lib/yuzu/core/website_file.rb', line 134
def paginated?
false
end
|
#plaintext? ⇒ Boolean
125
126
127
|
# File 'lib/yuzu/core/website_file.rb', line 125
def plaintext?
@path.plaintext?
end
|
#postfilters ⇒ Object
235
236
237
|
# File 'lib/yuzu/core/website_file.rb', line 235
def postfilters
@postfilters ||= filters.values.select {|filt| filt.filter_type.include?(:postfilter)}
end
|
#prefiltered_contents ⇒ Object
167
168
169
|
# File 'lib/yuzu/core/website_file.rb', line 167
def prefiltered_contents
@prefiltered_contents ||= get_prefiltered_contents
end
|
#prefilters ⇒ Object
227
228
229
|
# File 'lib/yuzu/core/website_file.rb', line 227
def prefilters
@prefilters ||= filters.values.select {|filt| filt.filter_type.include?(:prefilter)}
end
|
#preprocess! ⇒ Object
161
162
163
164
165
|
# File 'lib/yuzu/core/website_file.rb', line 161
def preprocess!
PreProcessor.preprocessors.each do |name, preprocessor|
preprocessor.process(self, @raw_contents)
end
end
|
#processed_contents ⇒ String
Returns the contents passed through the filters.
182
183
184
|
# File 'lib/yuzu/core/website_file.rb', line 182
def processed_contents
@processed_contents ||= get_processed_contents
end
|
#properties ⇒ Object
Returns a Hash of the properties of this file, like the name, etc.
85
86
87
|
# File 'lib/yuzu/core/website_file.rb', line 85
def properties
@properties ||= FileProperties.new(self)
end
|
#raw_contents ⇒ Object
138
139
140
141
142
143
144
|
# File 'lib/yuzu/core/website_file.rb', line 138
def raw_contents
if @raw_contents.nil?
@raw_contents = get_raw_contents
preprocess!
end
@raw_contents
end
|
#rendered_contents ⇒ String
Return the results of running the processed_contents through the textual processors, e.g. markdown.
198
199
200
|
# File 'lib/yuzu/core/website_file.rb', line 198
def rendered_contents
@rendered_contents ||= Translator.translate(processed_contents, @path.extension)
end
|
89
90
91
|
# File 'lib/yuzu/core/website_file.rb', line 89
def to_s
"WebsiteFile(#{@path.relative})"
end
|