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
A Time
object indicating the creation date of the post
A Time
object indicating the last-modified date of the post
An Array
of String
of places where the post was written
An Array
of Clayoven::Claytext::Paragraph
objects
The permalink of the page of the form blog
or blog/1
An Array
of “subtopics” for the page, used to fill the IndexPage
with subtopic headings, and ContentPage
entries
A String
indicating the path to the HTML file on disk
The first line in the .clay or .index.clay file serves as the title of the page
An Array
of “topics” (String
) corresponding to IndexPage
entries
Public Class Methods
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
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