Class: Wytch::Site
- Inherits:
-
Object
- Object
- Wytch::Site
- 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.
Instance Attribute Summary collapse
-
#base_url ⇒ String?
Base URL for the site (used in sitemaps, feeds, etc.).
-
#content_dir ⇒ String
Directory containing content files (default: "content").
-
#inflections ⇒ Hash
readonly
Custom inflections for Zeitwerk autoloading.
-
#page_class ⇒ String
Fully qualified class name for pages (default: "Wytch::Page").
-
#pages ⇒ Hash{String => Page}
All loaded pages, keyed by path.
-
#site_code_path ⇒ String
Directory containing site Ruby code (default: "src").
Class Method Summary collapse
-
.load! ⇒ void
Loads the site configuration from config.rb in the current directory.
Instance Method Summary collapse
-
#content_loader ⇒ ContentLoader
Returns the content loader instance.
-
#inflect(inflections_hash) ⇒ void
Adds custom inflections for Zeitwerk autoloading.
-
#initialize ⇒ Site
constructor
Creates a new Site with default configuration.
-
#load_content ⇒ Hash{String => Page}
Loads all content files and populates the pages hash.
-
#site_code_loader ⇒ Zeitwerk::Loader
Returns the Zeitwerk loader for site code.
Constructor Details
#initialize ⇒ Site
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_url ⇒ String?
Returns 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_dir ⇒ String
Returns directory containing content files (default: "content").
53 54 55 |
# File 'lib/wytch/site.rb', line 53 def content_dir @content_dir end |
#inflections ⇒ Hash (readonly)
Returns custom inflections for Zeitwerk autoloading.
41 42 43 |
# File 'lib/wytch/site.rb', line 41 def inflections @inflections end |
#page_class ⇒ String
Returns 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 |
#pages ⇒ Hash{String => Page}
Returns 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_path ⇒ String
Returns 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_loader ⇒ ContentLoader
Returns the content loader instance.
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.
62 63 64 |
# File 'lib/wytch/site.rb', line 62 def inflect(inflections_hash) @inflections.merge!(inflections_hash) end |
#load_content ⇒ Hash{String => Page}
Loads all content files and populates the pages hash.
93 94 95 |
# File 'lib/wytch/site.rb', line 93 def load_content @pages = content_loader.load_content end |
#site_code_loader ⇒ Zeitwerk::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.
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 |