class RuneBlog::ViewPost

Attributes

aslug[RW]
blog[RW]
date[RW]
nslug[RW]
num[RW]
path[RW]
teaser_text[RW]
title[RW]
view[RW]

Public Class Methods

make(blog:, view:, nslug:) click to toggle source
# File lib/post.rb, line 89
def self.make(blog:, view:, nslug:)
  raise NoNumericPrefix(nslug) unless nslug =~ /^\d{4}-/
  raise NoExtensionExpected(nslug) if nslug.end_with?(".lt3") || nslug.end_with?(".html")
  view = view.to_s
  view.define_singleton_method :path do |subdir = ""|
    str = blog.root/:views/view
    str << "/#{subdir}" unless subdir.empty?
    str
  end
  view.define_singleton_method :standard do |subdir = ""|
    str = blog.root/:views/view/:themes/:standard
    str << "/#{subdir}" unless subdir.empty?
    str
  end
  view.define_singleton_method :postdir do |file = ""|
    file = file.to_s
    str = blog.root/:views/view/:posts/nslug
    str = str/file unless file.empty?
    str
  end 
  view.define_singleton_method :remote do |dir: "", file: ""|
    subdir = subdir.to_s
    file = file.to_s
    str = blog.root/:views/view/:remote
    str = str/subdir unless subdir.empty?
    str = str/file unless file.empty?
    str
  end
  obj = RuneBlog::ViewPost.new(view, nslug)
  obj.blog = blog
  obj.view = view
  obj.nslug = nslug
  obj.aslug = nslug[5..-1]
  obj.num = nslug[0..3]
  obj
end
new(view, postdir) click to toggle source

aslug this-is-a-post aslug_live this-is-a-post.lt3 aslug_html this-is-a-post.lt3 nslug 0001-this-is-a-post

slug(:num, ext = “”)

# File lib/post.rb, line 156
def initialize(view, postdir)
  log!(enter: __method__, args: [view, postdir], level: 3)
  # Assumes already parsed/processed
  @blog = RuneBlog.blog || raise(NoBlogAccessor)
  @path = postdir.dup
  @nslug = @path.split("/").last
  @aslug = @nslug[5..-1]
  fname = "#{postdir}/teaser.txt"            # ???
  @teaser_text = File.read(fname).chomp
  
  Dir.chdir(postdir) do 
    meta = @blog.read_metadata
    @title = meta.title
    @date  = meta.pubdate
  end
rescue => err
  STDERR.puts "--- #{err}"
  STDERR.puts "    #{err.backtrace.join("\n  ")}" if err.respond_to?(:backtrace)
end

Public Instance Methods

get_dirs() click to toggle source
# File lib/post.rb, line 176
def get_dirs
  log!(enter: __method__, args: [view, postdir], level: 3)
  fname = File.basename(draft)
  noext = fname.sub(/.lt3$/, "")
  vdir = @root/:views/view
  dir = vdir/:posts/noext + "/"
  Dir.mkdir(dir) unless Dir.exist?(dir)
  system!("cp #{draft} #{dir}")
  viewdir, slugdir, aslug = vdir, dir, noext[5..-1]
  theme = viewdir/:themes/:standard
  [noext, viewdir, slugdir, aslug, theme]
end
repo(subdir = "") click to toggle source
# File lib/post.rb, line 126
def repo(subdir = "")
  subdir = subdir.to_s
  unless subdir.empty?
    raise "Expected 'posts' or 'drafts'" unless %w[posts drafts].include?(subdir)
  end
  str = blog.root
  str = str/subdir unless subdir.empty?
  str
end
Also aliased as: root
root(subdir = "")
Alias for: repo
slug(num = true, ext = "") click to toggle source
# File lib/post.rb, line 138
def slug(num = true, ext = "")
  ext = ext.to_s
  str = ""
  str << @num << "-" if num
  str << @aslug 
  str << ext
  str
end