Class: SemiStatic::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/semi-static/base.rb

Overview

Base is a single source file and its associated metadata. Base loads itself from the source file and strips off and parses the metadata in the file’s header.

Direct Known Subclasses

Index, Layout, Page, Post, Snippet, Stylesheet

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(site, path) ⇒ Base

Initializes a new Base

site

The Site object we belong to

path

The relative path to the source file



35
36
37
38
39
40
41
42
43
# File 'lib/semi-static/base.rb', line 35

def initialize(site, path)
    @site = site
    @source_path = path
    @source_ext = File.extname(source_path)
    @full_source_path = File.expand_path(source_path)
    @metadata = []
    
    load
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object (protected)

:nodoc:



64
65
66
67
68
69
70
71
# File 'lib/semi-static/base.rb', line 64

def method_missing(method, *args) #:nodoc:
    name = method.to_sym
    if @metadata.include?(name)
        return [name]
    else
        super
    end
end

Instance Attribute Details

#full_source_pathObject (readonly)

The absolute path to the source file



28
29
30
# File 'lib/semi-static/base.rb', line 28

def full_source_path
  @full_source_path
end

#siteObject (readonly)

The associated Site object



8
9
10
# File 'lib/semi-static/base.rb', line 8

def site
  @site
end

#source_contentObject (readonly)

The source file’s contents



20
21
22
# File 'lib/semi-static/base.rb', line 20

def source_content
  @source_content
end

#source_extObject (readonly)

The source file’s extension



16
17
18
# File 'lib/semi-static/base.rb', line 16

def source_ext
  @source_ext
end

#source_metadataObject (readonly)

The metadata found in the file’s header



24
25
26
# File 'lib/semi-static/base.rb', line 24

def 
  @source_metadata
end

#source_pathObject (readonly)

The relative path to the source file



12
13
14
# File 'lib/semi-static/base.rb', line 12

def source_path
  @source_path
end

Instance Method Details

#source_mtimeObject

Get the modification time of the source file.



47
48
49
# File 'lib/semi-static/base.rb', line 47

def source_mtime
    File.mtime(@full_source_path)
end