Class: Usmu::Template::Page

Inherits:
Layout show all
Defined in:
lib/usmu/template/page.rb

Overview

Represents a page in the source directory of the website.

Instance Attribute Summary collapse

Attributes inherited from Layout

#helpers, #input_path, #metadata, #output_extension, #parent, #provider_name, #template_class, #type

Attributes inherited from StaticFile

#input_path, #mtime, #name

Instance Method Summary collapse

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

included

Constructor Details

#initialize(configuration, name, metadata, type = nil, content = nil) ⇒ Page

Returns a new instance of Page.

Parameters:

  • configuration (Usmu::Configuration)

    The configuration for the website we're generating.

  • name (String)

    The name of the file in the source directory.

  • metadata (Hash)

    The metadata for the file.

  • type (String) (defaults to: nil)

    The type of template to use with the file. Used for testing purposes.

  • content (String) (defaults to: nil)

    The content of the file. Used for testing purposes.



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_pathstring (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.

Returns:

  • (string)

    the base path to the files used by this class.

See Also:



61
62
63
# File 'lib/usmu/template/page.rb', line 61

def content_path
  @configuration.source_path
end

Instance Method Details

#datevoid



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_filenamevoid



30
31
32
# File 'lib/usmu/template/page.rb', line 30

def output_filename
  permalink || super_output_filename
end


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_filenamevoid (private)



10
# File 'lib/usmu/template/page.rb', line 10

alias :super_output_filename :output_filename