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

#<=>, #==, #base_path, #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
13
14
15
16
17
18
19
20
# File 'lib/plate/static_page.rb', line 5

def file_path
  content_dir = File.join(self.site.source, 'content')
  assets_dir = File.join(self.site.source, 'assets')

  base = Pathname.new(content_dir)

  if self.file.to_s.start_with?(assets_dir)
    base = Pathname.new(assets_dir)
  end

  current = Pathname.new(self.file)

  dirs = current.relative_path_from(base)

  "/#{dirs}"
end

#layoutObject



22
23
24
# File 'lib/plate/static_page.rb', line 22

def layout
  nil
end

#rendered_contentObject

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



27
28
29
# File 'lib/plate/static_page.rb', line 27

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)


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

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



38
39
40
41
42
# File 'lib/plate/static_page.rb', line 38

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