Class: Yuzu::Core::WebsiteFile

Inherits:
WebsiteBase show all
Includes:
Filters, PostProcessors, PreProcessors, Renderers, Translators
Defined in:
lib/yuzu/core/website_file.rb

Direct Known Subclasses

PaginatedWebsiteFile

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

#pageObject (readonly)

Returns the value of attribute page.



72
73
74
# File 'lib/yuzu/core/website_file.rb', line 72

def page
  @page
end

#parentObject (readonly)

Returns the value of attribute parent.



72
73
74
# File 'lib/yuzu/core/website_file.rb', line 72

def parent
  @parent
end

#pathObject (readonly)

Returns the value of attribute path.



72
73
74
# File 'lib/yuzu/core/website_file.rb', line 72

def path
  @path
end

Class Method Details

.processorsObject



27
28
29
# File 'lib/yuzu/core/website_file.rb', line 27

def self.processors
  tr = Filter.filters.merge(Renderer.renderers)
end

.translatorsObject



23
24
25
# File 'lib/yuzu/core/website_file.rb', line 23

def self.translators
  Translator.translators
end

Instance Method Details

#authorObject



97
98
99
# File 'lib/yuzu/core/website_file.rb', line 97

def author
  config.author
end

#basenameObject



113
114
115
# File 'lib/yuzu/core/website_file.rb', line 113

def basename
  @path.basename
end

#contentsObject

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_atObject



153
154
155
# File 'lib/yuzu/core/website_file.rb', line 153

def created_at
  @created_at ||= @path.pathname.ctime
end

#filenameObject



109
110
111
# File 'lib/yuzu/core/website_file.rb', line 109

def filename
  @path.filename
end

#filtersObject



223
224
225
# File 'lib/yuzu/core/website_file.rb', line 223

def filters
  Filter.filters
end

#get_prefiltered_contentsObject



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_contentsObject



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_contentsObject



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

Returns:

  • (Boolean)


101
102
103
# File 'lib/yuzu/core/website_file.rb', line 101

def home?
  parent.root? and index?
end

#html_contentsObject

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

Returns:

  • (Boolean)


105
106
107
# File 'lib/yuzu/core/website_file.rb', line 105

def index?
  basename == "index" or basename.include?("index_")
end

#layoutObject



202
203
204
# File 'lib/yuzu/core/website_file.rb', line 202

def layout
  @layout ||= Yuzu::Core::Layout.new(template)
end

#layout_contentsObject

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

Alias



130
131
132
# File 'lib/yuzu/core/website_file.rb', line 130

def link_root
  linkroot
end

#mainfiltersObject



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

Returns:

  • (Boolean)


121
122
123
# File 'lib/yuzu/core/website_file.rb', line 121

def markdown?
  @path.markdown?
end

#modified_atObject



157
158
159
# File 'lib/yuzu/core/website_file.rb', line 157

def modified_at
  @modified_at ||= @path.pathname.mtime
end

#nameObject



93
94
95
# File 'lib/yuzu/core/website_file.rb', line 93

def name
  post_title
end

#output_filenameObject



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

Returns:

  • (Boolean)


134
135
136
# File 'lib/yuzu/core/website_file.rb', line 134

def paginated?
  false
end

#plaintext?Boolean

Returns:

  • (Boolean)


125
126
127
# File 'lib/yuzu/core/website_file.rb', line 125

def plaintext?
  @path.plaintext?
end

#postfiltersObject



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_contentsObject



167
168
169
# File 'lib/yuzu/core/website_file.rb', line 167

def prefiltered_contents
  @prefiltered_contents ||= get_prefiltered_contents
end

#prefiltersObject



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_contentsString

Returns the contents passed through the filters.

Returns:

  • (String)

    the processed contents



182
183
184
# File 'lib/yuzu/core/website_file.rb', line 182

def processed_contents
  @processed_contents ||= get_processed_contents
end

#propertiesObject

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_contentsObject



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_contentsString

Return the results of running the processed_contents through the textual processors, e.g. markdown.

Returns:

  • (String)

    the file’s html-rendered contents



198
199
200
# File 'lib/yuzu/core/website_file.rb', line 198

def rendered_contents
  @rendered_contents ||= Translator.translate(processed_contents, @path.extension)
end

#to_sObject



89
90
91
# File 'lib/yuzu/core/website_file.rb', line 89

def to_s
  "WebsiteFile(#{@path.relative})"
end