class Clayoven::Config

Clayoven Configuration

Clayoven can be configured using files .clayoven/{sitename, hidden, tz, subtopics} at the toplevel directory.

If a certain configuration file doesn’t exist, we automatically create a default one.

Constants

SLIM_DEFAULT

Format: The contents of a valid template file A more full-featured one is generated by clayoven init

SUBTOPIC_DEFAULT

Format: [Subdirectory name without spaces] [Subdirectory title]

TZ_DEFAULT

Format: [(+|-)d{4}] [String]

Attributes

hidden[RW]

A list of Clayoven::Toplevel::ContentPage#permalink entries, not to be displayed when generating the corresponding Clayoven::Toplevel::IndexPage

sitename[RW]

The public URL of the website excluding the ‘https://’ prefix

stmap[RW]

A subtopic mapper of the form {‘inf’ => ‘∞-categories’} Exposed as Clayoven::Toplevel::IndexPage#subtopics

template[RW]

A .slim file read out from disk; hard-coded to the contents of design/template.slim

tzmap[RW]

A timezone mapper of the form {‘+0100’ => [‘Paris’, ‘London’]} Exposed as Clayoven::Toplevel::Page#locations

Public Class Methods

new() click to toggle source

Initialize our config strings and hashtables based on some sane defaults

# File lib/clayoven/config.rb, line 72
def initialize
  @sitename = create_template(".clayoven/sitename", "clayoven.io").first
  @hidden = create_template ".clayoven/hidden", %w[404 scratch].join("\n")
  @tzmap =
    (create_template ".clayoven/tz", TZ_DEFAULT)
      .map { |l| l.split(" ", 2) }
      .map { |k, v| [k, v.split(" ")] }
      .to_h
  @stmap =
    (create_template ".clayoven/subtopic", SUBTOPIC_DEFAULT)
      .map { |l| l.split(" ", 2) }
      .to_h
  @stmap.default_proc = proc { |h, k| h[k] = k }
  @template = (create_template "design/template.slim", SLIM_DEFAULT).join "\n"
end

Public Instance Methods

create_template(path, default) click to toggle source

Creates file at path, if it doesn’t exist, initializes with default

# File lib/clayoven/config.rb, line 58
def create_template(path, default)
  components = path.split "/"
  if components.length == (2) && !(Dir.exist? components[0])
    Dir.mkdir components[0]
  end
  if File.exist?(path)
    File.read(path).split "\n"
  else
    File.open(path, "w") { |io| io.write default }
    [default]
  end
end