class Clayoven::Toplevel::Page

An abstract page class

IndexPage and ContentPage inherit from this class. Exposes accessors to various fields to be used in design/template.slim.

Be careful when creating Page objects, because new is expensive.

Attributes

crdate[RW]

A Time object indicating the creation date of the post

lastmod[RW]

A Time object indicating the last-modified date of the post

locations[RW]

An Array of String of places where the post was written

paragraphs[RW]

An Array of Clayoven::Claytext::Paragraph objects

subtopics[RW]

An Array of “subtopics” for the page, used to fill the IndexPage with subtopic headings, and ContentPage entries

target[RW]

A String indicating the path to the HTML file on disk

title[RW]

The first line in the .clay or .index.clay file serves as the title of the page

topics[RW]

An Array of “topics” (String) corresponding to IndexPage entries

Public Class Methods

new(filename, git) click to toggle source

Initialize with filename and data from Clayoven::Git#metadata

Expensive due to log --follow; avoid creating Page objects when not necessary.

# File lib/clayoven/toplevel.rb, line 55
def initialize(filename, git)
  @filename = filename
  # If a file is in the git index, use `Time.now`; otherwise, log --follow it.
  @lastmod, @crdate, @locations = git.metadata @filename
  @title, @body = File.read(@filename).split "\n\n", 2
end

Public Instance Methods

render(topics, template) click to toggle source

Writes out HTML pages rendered by Clayoven::Claytext::process and Slim::Template Initializes Page#topics, and accepts a template.

# File lib/clayoven/toplevel.rb, line 64
def render(topics, template)
  @topics = topics
  @paragraphs = @body ? (Clayoven::Claytext.process @body) : []
  Slim::Engine.set_options pretty: true, sort_attrs: false
  rendered = Slim::Template.new { template }.render self
  File.open(@target, _ = "w") { |targetio| targetio.write rendered }
end