Class: Usmu::Template::Page
- Inherits:
-
Layout
- Object
- StaticFile
- Layout
- Usmu::Template::Page
- Defined in:
- lib/usmu/template/page.rb
Overview
Represents a page in the source directory of the website.
Instance Attribute Summary collapse
-
#content_path ⇒ string
readonly
protected
Returns the base path to the files used by this class.
Attributes inherited from Layout
#helpers, #input_path, #metadata, #output_extension, #parent, #provider_name, #template_class, #type
Attributes inherited from StaticFile
Instance Method Summary collapse
- #date ⇒ void
-
#initialize(configuration, name, metadata, type = nil, content = nil) ⇒ Page
constructor
A new instance of Page.
- #output_filename ⇒ void
- #permalink ⇒ void protected
- #super_output_filename ⇒ void private
Methods inherited from Layout
#[]=, #add_template_defaults, find_layout, #get_variables, is_valid_file?, #render, #render_content, search_layout
Methods inherited from StaticFile
#==, #inspect, #metadata, #render
Methods included from Helpers::Indexer
Constructor Details
#initialize(configuration, name, metadata, type = nil, content = nil) ⇒ Page
Returns a new instance of Page.
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/usmu/template/page.rb', line 19 def initialize(configuration, name, , type = nil, content = nil) super(configuration, name, , type, content) current_parent = parent until current_parent.nil? @log.debug("Injecting page #{name} into #{current_parent.name}") current_parent['page'] = self current_parent = current_parent.parent end end |
Instance Attribute Details
#content_path ⇒ string (readonly, protected)
Returns the base path to the files used by this class.
This folder should be the parent folder for the file named by the name attribute.
61 62 63 |
# File 'lib/usmu/template/page.rb', line 61 def content_path @configuration.source_path end |
Instance Method Details
#date ⇒ void
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/usmu/template/page.rb', line 34 def date date = self['date'] if date.is_a? Time return date end if date date = Time.parse(date) rescue nil end unless date date = File.stat(input_path).mtime end date end |
#output_filename ⇒ void
30 31 32 |
# File 'lib/usmu/template/page.rb', line 30 def output_filename permalink || super_output_filename end |
#permalink ⇒ void (protected)
65 66 67 68 69 70 71 72 73 |
# File 'lib/usmu/template/page.rb', line 65 def permalink link = self['permalink'] return nil unless link date = self.date link_tr = link.gsub('%f', File.basename(@name[0..(@name.rindex('.') - 1)])) date.strftime(link_tr) end |
#super_output_filename ⇒ void (private)
10 |
# File 'lib/usmu/template/page.rb', line 10 alias :super_output_filename :output_filename |