Class: Plate::DynamicPage
Overview
Allows the creation of one-off pages generated entirely from a dynamic source. The root content for a ‘DynamicPage` instance is not read from the source directory, as opposed to normal files. Instead, dynamic pages are typically used to create pages with dynamic data and content.
Examples may include a blog archives page, list of tags, categories pages, etc.
Instance Attribute Summary collapse
-
#file_path ⇒ Object
The full file system path of where this file will be written to.
-
#locals ⇒ Object
Provides a hash to the page with variables that are accessible from with dynamic layouts or dynamic templates for this page.
Attributes inherited from Page
#body, #content, #file, #layout, #meta, #partials, #raw, #site
Instance Method Summary collapse
-
#initialize(site, destination_path, meta = {}) ⇒ DynamicPage
constructor
Set up a new instance of Dynamic Page.
-
#method_missing(sym, *args) ⇒ Object
Check to see if a method called is in your locals.
-
#name ⇒ Object
name for dynamic pages is the path.
-
#path=(destination_path) ⇒ Object
Set the destination path for this page.
-
#rendered_body ⇒ Object
Alias for the content that is provided.
Methods inherited from Page
#<=>, #==, #base_path, #basename, #directory, #downgrade?, #engines, #extension, #extensions, #file?, #file_name, #format_extension, #id, #inspect, #keywords, #load!, #loaded?, #path, #relative_file, #reload!, #rendered_content, #slug, #title_for_url, #to_s, #url, #write!
Methods included from Callbacks
Constructor Details
#initialize(site, destination_path, meta = {}) ⇒ DynamicPage
Set up a new instance of Dynamic Page
30 31 32 33 34 35 36 37 |
# File 'lib/plate/dynamic_page.rb', line 30 def initialize(site, destination_path, = {}) self.site = site self.path = destination_path self. = self.content = "" self.locals = {} self.partials = [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args) ⇒ Object
Check to see if a method called is in your locals. Allows the view to call variables in the locals hash directly without having to call ‘page.locals`.
For example, in a view you can call ‘page.locals` `locals` or just `local_key`. They all will return the same value (provided :local_key exists in the locals of course)
75 76 77 78 |
# File 'lib/plate/dynamic_page.rb', line 75 def method_missing(sym, *args) return locals[sym] if locals.has_key?(sym) super end |
Instance Attribute Details
#file_path ⇒ Object
The full file system path of where this file will be written to. Set from the destination path on initialize.
23 24 25 |
# File 'lib/plate/dynamic_page.rb', line 23 def file_path @file_path end |
#locals ⇒ Object
Provides a hash to the page with variables that are accessible from with dynamic layouts or dynamic templates for this page.
27 28 29 |
# File 'lib/plate/dynamic_page.rb', line 27 def locals @locals end |
Instance Method Details
#name ⇒ Object
name for dynamic pages is the path
40 41 42 |
# File 'lib/plate/dynamic_page.rb', line 40 def name self.file_path end |
#path=(destination_path) ⇒ Object
Set the destination path for this page.
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/plate/dynamic_page.rb', line 51 def path=(destination_path) # Remove leading and trailing slashes destination_path = destination_path.to_s.gsub(/^\//, '').gsub(/\/$/, '') # Unless file ends in an extension, add /index.html unless destination_path =~ /(.*?)\.[a-z0-0]{2,4}/i destination_path = "#{destination_path}/index.html" end destination_path = "/#{destination_path}" self.file_path = destination_path end |
#rendered_body ⇒ Object
Alias for the content that is provided
66 67 68 |
# File 'lib/plate/dynamic_page.rb', line 66 def rendered_body self.content end |