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
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.
The date format for post paths
A description of the blog
The number of posts displayed per page
Whether the timeline is reversed
The length of the RSS feed in number of posts. Defaults to 20-most-recent.
The separator for words in slugs. May not be whitespace if loaded from a blog_spec file.
The blog’s title
Public Class Methods
# File lib/oaktree/specification.rb, line 12 def self.default_date_path_format @@DEFAULT_DATE_PATH_FORMAT end
# File lib/oaktree/specification.rb, line 16 def self.default_slug_separator @@DEFAULT_SLUG_SEPARATOR end
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
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
Gets the base URL of the blog (i.e., localhost/blog).
# File lib/oaktree/specification.rb, line 77 def base_url @base_url end
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
# 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
# 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
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
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
# File lib/oaktree/specification.rb, line 81 def sources_root @sources_root ||= "#{@blog_root}source/" end