Class: SemiStatic::Page

Inherits:
Base
  • Object
show all
Includes:
Convertable
Defined in:
lib/semi-static/page.rb

Overview

Page represents a static page in the site. Page itself only represents a single source file, but can have a Layout and any number of Snippets, each of which has its own source file. Page’s modification time is the most recent of itself, its layout, and any Snippets used.

Instance Attribute Summary collapse

Attributes inherited from Base

#full_source_path, #site, #source_content, #source_ext, #source_metadata, #source_path

Instance Method Summary collapse

Methods included from Convertable

#content, #layout, #layout_name, #load, #object_ref, #render, #snippet, #source_mtime, #underscore

Methods inherited from Base

#source_mtime

Constructor Details

#initialize(site, path) ⇒ Page

Initializes a new Page

site

The Site object we belong to

path

The relative path to the source file



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/semi-static/page.rb', line 30

def initialize(site, path)
    super
    @metadata = [ :title, :layout ]
    
    src_base = File.basename(source_path, source_ext)
    output_ext = File.extname(src_base)
    if output_ext.nil? || output_ext.empty?
        output_ext = '.html'
    else
        src_base = File.basename(src_base, output_ext)
    end
    @output_dir, src_file = File.split(source_path)
    
    if output_dir == '.'
        prefix = ''
    else
        prefix = "#{output_dir}/"
    end
    @name = "/#{prefix}#{src_base}"
    @output_path = "#{prefix}#{src_base}#{output_ext}"
    
    if src_base == 'index'
        @uri = "/#{output_dir}/"
    else
        @uri = "/#{output_path}"
    end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class SemiStatic::Base

Instance Attribute Details

#nameObject (readonly)

The Page’s name



19
20
21
# File 'lib/semi-static/page.rb', line 19

def name
  @name
end

#output_dirObject (readonly)

The Page’s output directory



11
12
13
# File 'lib/semi-static/page.rb', line 11

def output_dir
  @output_dir
end

#output_pathObject (readonly)

The Page’s output path



15
16
17
# File 'lib/semi-static/page.rb', line 15

def output_path
  @output_path
end

#uriObject (readonly)

The Page’s URI



23
24
25
# File 'lib/semi-static/page.rb', line 23

def uri
  @uri
end