Class: Wytch::Page
- Inherits:
-
Object
- Object
- Wytch::Page
- Defined in:
- lib/wytch/page.rb
Overview
Represents a single page in a Wytch site.
Pages are defined by Ruby content files in the content directory. Each content file is evaluated in the context of a Page instance, allowing it to set metadata and configure the view class.
Instance Attribute Summary collapse
-
#metadata ⇒ Hash
readonly
Arbitrary metadata set by the content file.
Instance Method Summary collapse
-
#add(helper_module) ⇒ void
Extends this page instance with a helper module.
-
#build_path ⇒ String
Returns the output file path for the built page.
-
#change_frequency ⇒ String?
The change frequency hint for sitemap generation.
-
#include_in_sitemap? ⇒ Boolean
Whether this page should be included in the sitemap.
-
#initialize(file_path:) ⇒ Page
constructor
Creates a new page by loading and evaluating a content file.
-
#last_modified ⇒ Date, ...
The last modification date for sitemap generation.
-
#path ⇒ String
Returns the URL path for this page.
-
#priority ⇒ Float?
The priority hint for sitemap generation.
-
#render ⇒ String
Renders the page using its configured view class.
-
#view(view_class) ⇒ void
Sets the view class for rendering this page.
-
#virtual_path ⇒ String
Returns the virtual path derived from the file path.
Constructor Details
#initialize(file_path:) ⇒ Page
Creates a new page by loading and evaluating a content file.
31 32 33 34 35 36 37 38 39 |
# File 'lib/wytch/page.rb', line 31 def initialize(file_path:) @file_path = file_path = {} @view_class = nil source_path = File.join(Wytch.site.content_dir, @file_path) instance_eval File.read(source_path), source_path end |
Instance Attribute Details
#metadata ⇒ Hash (readonly)
Returns arbitrary metadata set by the content file.
42 43 44 |
# File 'lib/wytch/page.rb', line 42 def end |
Instance Method Details
#add(helper_module) ⇒ void
This method returns an undefined value.
Extends this page instance with a helper module. Called from content files to add helper methods.
88 89 90 |
# File 'lib/wytch/page.rb', line 88 def add(helper_module) extend helper_module end |
#build_path ⇒ String
Returns the output file path for the built page.
72 73 74 75 76 77 78 |
# File 'lib/wytch/page.rb', line 72 def build_path if virtual_path == "index" "index.html" else "#{virtual_path}/index.html" end end |
#change_frequency ⇒ String?
The change frequency hint for sitemap generation. Override in subclasses to provide hints like "daily", "weekly", etc.
124 125 126 |
# File 'lib/wytch/page.rb', line 124 def change_frequency nil end |
#include_in_sitemap? ⇒ Boolean
Whether this page should be included in the sitemap. Override in subclasses to exclude pages.
108 109 110 |
# File 'lib/wytch/page.rb', line 108 def include_in_sitemap? true end |
#last_modified ⇒ Date, ...
The last modification date for sitemap generation. Override in subclasses to provide actual dates.
116 117 118 |
# File 'lib/wytch/page.rb', line 116 def last_modified nil end |
#path ⇒ String
Returns the URL path for this page.
54 55 56 57 58 59 60 |
# File 'lib/wytch/page.rb', line 54 def path if virtual_path == "index" "/" else "/#{virtual_path}" end end |
#priority ⇒ Float?
The priority hint for sitemap generation. Override in subclasses to provide a value between 0.0 and 1.0.
132 133 134 |
# File 'lib/wytch/page.rb', line 132 def priority nil end |
#render ⇒ String
Renders the page using its configured view class.
47 48 49 |
# File 'lib/wytch/page.rb', line 47 def render @view_class.new(self).call end |
#view(view_class) ⇒ void
This method returns an undefined value.
Sets the view class for rendering this page. Called from content files to specify which Phlex view to use.
100 101 102 |
# File 'lib/wytch/page.rb', line 100 def view(view_class) @view_class = view_class end |
#virtual_path ⇒ String
Returns the virtual path derived from the file path.
65 66 67 |
# File 'lib/wytch/page.rb', line 65 def virtual_path @file_path.delete_prefix("#{Wytch.site.content_dir}/").delete_suffix(".rb") end |