Class: Plate::StaticPage

Inherits:
Page
  • Object
show all
Defined in:
lib/plate/static_page.rb

Overview

A static page is left unmodified and is transferred over to the published site exactly as it is.

Instance Attribute Summary

Attributes inherited from Page

#body, #content, #file, #meta, #partials, #raw, #site

Instance Method Summary collapse

Methods inherited from Page

#<=>, #==, #basename, #directory, #downgrade?, #engines, #extension, #extensions, #file?, #file_name, #format_extension, #id, #initialize, #inspect, #keywords, #load!, #loaded?, #path, #relative_file, #reload!, #rendered_body, #slug, #title_for_url, #to_s, #url

Methods included from Callbacks

included

Constructor Details

This class inherits a constructor from Plate::Page

Instance Method Details

#file_pathObject



5
6
7
8
9
10
11
12
# File 'lib/plate/static_page.rb', line 5

def file_path
  base = Pathname.new(File.join(self.site.source, 'content'))
  current = Pathname.new(self.file)

  dirs = current.relative_path_from(base)

  "/#{dirs}"
end

#layoutObject



14
15
16
# File 'lib/plate/static_page.rb', line 14

def layout
  nil
end

#rendered_contentObject

If we need for some reason, read this file’s contents



19
20
21
# File 'lib/plate/static_page.rb', line 19

def rendered_content
  @rendered_content ||= File.read(self.file)
end

#upgrade?Boolean

Check a static page to see if it should be converted into a Page

Returns:

  • (Boolean)


24
25
26
# File 'lib/plate/static_page.rb', line 24

def upgrade?
  rendered_content.start_with?('---')
end

#write!Object

Write this page to the destination. For static files this just results in copying the file over to the destination



30
31
32
33
34
# File 'lib/plate/static_page.rb', line 30

def write!
  path = File.join(site.build_destination, file_path)
  FileUtils.mkdir_p(File.dirname(path))
  FileUtils.cp(self.file, path)
end