Class: Wytch::Site

Inherits:
Object
  • Object
show all
Defined in:
lib/wytch/site.rb

Overview

Holds the configuration and state for a Wytch site.

The Site class is the central configuration point for Wytch. It manages the content directory, site code loading, page class, and the collection of all pages.

Examples:

Configuring a site in config.rb

Wytch.configure do |site|
  site.page_class = "MySite::Page"
  site.base_url = "https://example.com"
  site.content_dir = "pages"  # default is "content"
end

See Also:

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSite

Creates a new Site with default configuration.



31
32
33
34
35
36
37
38
# File 'lib/wytch/site.rb', line 31

def initialize
  @inflections = {}
  @content_dir = "content"
  @site_code_path = "src"
  @page_class = "Wytch::Page"
  @pages = {}
  @base_url = nil
end

Instance Attribute Details

#base_urlString?

Returns base URL for the site (used in sitemaps, feeds, etc.).

Returns:

  • (String, nil)

    base URL for the site (used in sitemaps, feeds, etc.)



53
# File 'lib/wytch/site.rb', line 53

attr_accessor :content_dir, :site_code_path, :page_class, :pages, :base_url

#content_dirString

Returns directory containing content files (default: "content").

Returns:

  • (String)

    directory containing content files (default: "content")



53
54
55
# File 'lib/wytch/site.rb', line 53

def content_dir
  @content_dir
end

#inflectionsHash (readonly)

Returns custom inflections for Zeitwerk autoloading.

Returns:

  • (Hash)

    custom inflections for Zeitwerk autoloading



41
42
43
# File 'lib/wytch/site.rb', line 41

def inflections
  @inflections
end

#page_classString

Returns fully qualified class name for pages (default: "Wytch::Page").

Returns:

  • (String)

    fully qualified class name for pages (default: "Wytch::Page")



53
# File 'lib/wytch/site.rb', line 53

attr_accessor :content_dir, :site_code_path, :page_class, :pages, :base_url

#pagesHash{String => Page}

Returns all loaded pages, keyed by path.

Returns:

  • (Hash{String => Page})

    all loaded pages, keyed by path



53
# File 'lib/wytch/site.rb', line 53

attr_accessor :content_dir, :site_code_path, :page_class, :pages, :base_url

#site_code_pathString

Returns directory containing site Ruby code (default: "src").

Returns:

  • (String)

    directory containing site Ruby code (default: "src")



53
# File 'lib/wytch/site.rb', line 53

attr_accessor :content_dir, :site_code_path, :page_class, :pages, :base_url

Class Method Details

.load!void

This method returns an undefined value.

Loads the site configuration from config.rb in the current directory.



22
23
24
25
26
27
28
# File 'lib/wytch/site.rb', line 22

def self.load!
  if File.exist?(config_file = File.join(Dir.pwd, "config.rb"))
    load config_file
  else
    puts "Warning: config.rb not found in current directory"
  end
end

Instance Method Details

#content_loaderContentLoader

Returns the content loader instance.

Returns:



86
87
88
# File 'lib/wytch/site.rb', line 86

def content_loader
  @content_loader ||= ContentLoader.new
end

#inflect(inflections_hash) ⇒ void

This method returns an undefined value.

Adds custom inflections for Zeitwerk autoloading.

Examples:

site.inflect("api" => "API", "html_parser" => "HTMLParser")

Parameters:

  • inflections_hash (Hash{String => String})

    mapping of file names to class names



62
63
64
# File 'lib/wytch/site.rb', line 62

def inflect(inflections_hash)
  @inflections.merge!(inflections_hash)
end

#load_contentHash{String => Page}

Loads all content files and populates the pages hash.

Returns:

  • (Hash{String => Page})

    all loaded pages



93
94
95
# File 'lib/wytch/site.rb', line 93

def load_content
  @pages = content_loader.load_content
end

#site_code_loaderZeitwerk::Loader

Returns the Zeitwerk loader for site code.

The loader is configured to watch the site_code_path directory and supports hot reloading during development.

Returns:

  • (Zeitwerk::Loader)

    the configured loader



72
73
74
75
76
77
78
79
80
81
# File 'lib/wytch/site.rb', line 72

def site_code_loader
  @site_code_loader ||= begin
    loader = Zeitwerk::Loader.new
    loader.push_dir @site_code_path if Dir.exist?(@site_code_path)
    loader.enable_reloading
    loader.inflector.inflect(@inflections) if @inflections.any?
    loader.setup
    loader
  end
end