class OakTree::Specification

Specifications for the blog, operates similar to Gem::Specification. URLs and paths are strings and should not end in a slash.

Attributes

author[RW]

The name of the blog’s author (currently assumes a single author)

blog_root[R]

The blog root, where files are stored locally. Beneath this directory, there should be /source and /public directories, where post sources and the blog output, respectively, are stored. If these don’t exist, they’ll be created when generating the blog. This cannot be changed.

date_path_format[RW]

The date format for post paths

description[RW]

A description of the blog

posts_per_page[RW]

The number of posts displayed per page

reversed[RW]

Whether the timeline is reversed

rss_length[RW]

The length of the RSS feed in number of posts. Defaults to 20-most-recent.

slug_separator[RW]

The separator for words in slugs. May not be whitespace if loaded from a blog_spec file.

title[RW]

The blog’s title

Public Class Methods

default_date_path_format() click to toggle source
# File lib/oaktree/specification.rb, line 12
def self.default_date_path_format
  @@DEFAULT_DATE_PATH_FORMAT
end
default_slug_separator() click to toggle source
# File lib/oaktree/specification.rb, line 16
def self.default_slug_separator
  @@DEFAULT_SLUG_SEPARATOR
end
from_file(path) click to toggle source

Loads a specification from a file.

# File lib/oaktree/specification.rb, line 86
def self.from_file(path)
  raise "Spec file does not exist" unless File.exists? path

  self.new { |spec|

    spec_contents = File.open(path, 'r') { |io| io.read }
    spec_hash = Psych.load(spec_contents)
    spec_hash.each {
      |key, value|
      setter_sym = :"#{key}="
      if spec.respond_to? setter_sym
        spec.send setter_sym, value
      else
        raise "Invalid key/value in spec: #{key} => #{value}"
      end
    }

    Dir.chdir(File.dirname(path))

  }
end
new() { |self| ... } click to toggle source

Initializes the Specification with its default values.

# File lib/oaktree/specification.rb, line 109
def initialize
  # initialize default values for most properties
  self.title = ''
  self.description = ''
  self.base_url = ''
  self.post_path = 'post/'
  self.author = ''
  self.posts_per_page = 10
  self.reversed = false
  self.date_path_format = self.class.default_date_path_format
  self.slug_separator = self.class.default_slug_separator
  self.rss_length = 20

  yield self if block_given?

  @blog_root = File.expand_path(Dir.getwd) + '/'
end

Public Instance Methods

base_url() click to toggle source

Gets the base URL of the blog (i.e., localhost/blog).

# File lib/oaktree/specification.rb, line 77
def base_url
  @base_url
end
base_url=(url) click to toggle source

Sets the base URL of the blog (i.e., localhost/blog) - should have a trailing slash.

# File lib/oaktree/specification.rb, line 70
def base_url= url
  url = String.new(url)
  url << '/'  unless url.end_with? '/'
  @base_url = url.freeze()
end
date_path_format=(format) click to toggle source
# File lib/oaktree/specification.rb, line 60
def date_path_format= format
  if format.empty?
    @date_path_format = self.class.default_date_path_format
  else
    @date_path_format = format
  end
end
export_string() click to toggle source
# File lib/oaktree/specification.rb, line 127
    def export_string
      <<-EOT
# metadata
title:  #{@title}
description: #{@description}
author: #{@author}
posts_per_page: 10

# public URL
base_url:  #{@base_url}

# public content paths
post_path: #{@post_path}
      EOT
    end
post_path() click to toggle source

Gets the post path (i.e., the subdirectory where posts are stored).

# File lib/oaktree/specification.rb, line 56
def post_path
  @post_path
end
post_path=(path) click to toggle source

Sets the post path (i.e., the subdirectory where posts are stored). Should not begin with a slash, but can have a trailing slash if you want. If there is no trailing slash, it will be part of the filename up to a a point.

# File lib/oaktree/specification.rb, line 48
def post_path= path
  raise "post_path provided is nil" if path.nil?
  raise "post_path provided is not a string" unless path.kind_of?(String)

  @post_path = path.clone().freeze()
end
sources_root() click to toggle source
# File lib/oaktree/specification.rb, line 81
def sources_root
  @sources_root ||= "#{@blog_root}source/"
end