Sha256: 335d93b41ab088b0902bc9003708ba79db2f23205f575b4f3a13a28c05a32b96

Contents?: true

Size: 1.26 KB

Versions: 3

Compression:

Stored size: 1.26 KB

Contents

module Plate
  # A static page is left unmodified and is transferred over to the published
  # site exactly as it is.
  class StaticPage < Page
    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

    def layout
      nil
    end

    # If we need for some reason, read this file's contents
    def rendered_content
      @rendered_content ||= File.read(self.file)
    end

    # Check a static page to see if it should be converted into a Page
    def upgrade?
      rendered_content.start_with?('---')
    end

    # Write this page to the destination. For static files this just results
    # in copying the file over to the destination
    def write!
      path = File.join(site.build_destination, file_path)
      FileUtils.mkdir_p(File.dirname(path))
      FileUtils.cp(self.file, path)
    end

    protected
      # Don't read any meta data for static files, leave them as-is.
      def read_metadata!
        self.meta = {}
      end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
plate-0.7.8 lib/plate/static_page.rb
plate-0.7.7 lib/plate/static_page.rb
plate-0.7.6 lib/plate/static_page.rb