Class: RuneBlog::Post

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/runeblog_version.rb,
lib/post.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#copy_data, #find_draft_slugs, #get_all_widgets, #get_repo_config, #get_widget, #new_sequence, #quit_RubyText, #read_features, #read_vars, #subdirs, #write_features, #write_repo_config

Constructor Details

#initializePost

Returns a new instance of Post.



30
31
32
33
34
# File 'lib/post.rb', line 30

def initialize
  log!(enter: __method__, level: 3)
  @blog = RuneBlog.blog || raise(NoBlogAccessor)
  @meta = OpenStruct.new
end

Instance Attribute Details

#blogObject

Returns the value of attribute blog.



7
8
9
# File 'lib/post.rb', line 7

def blog
  @blog
end

#dateObject (readonly)

Returns the value of attribute date.



6
7
8
# File 'lib/post.rb', line 6

def date
  @date
end

#draftObject

Returns the value of attribute draft.



7
8
9
# File 'lib/post.rb', line 7

def draft
  @draft
end

#metaObject

Returns the value of attribute meta.



7
8
9
# File 'lib/post.rb', line 7

def meta
  @meta
end

#numObject (readonly)

Returns the value of attribute num.



6
7
8
# File 'lib/post.rb', line 6

def num
  @num
end

#slugObject (readonly)

Returns the value of attribute slug.



6
7
8
# File 'lib/post.rb', line 6

def slug
  @slug
end

#titleObject (readonly)

Returns the value of attribute title.



6
7
8
# File 'lib/post.rb', line 6

def title
  @title
end

#viewsObject (readonly)

Returns the value of attribute views.



6
7
8
# File 'lib/post.rb', line 6

def views
  @views
end

Class Method Details

.create(title:, teaser:, body:, pubdate: Time.now.strftime("%Y-%m-%d"), views: [], file: nil) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/post.rb', line 36

def self.create(title:, teaser:, body:, pubdate: Time.now.strftime("%Y-%m-%d"),
                views:[], file: nil)
  log!(enter: __method__, args: [title, teaser, body, pubdate, views], stderr: true)
  post = self.new
  # NOTE: This is the ONLY place next_sequence is called!
  num = post.meta.num   = post.blog.next_sequence

  # new_metadata
  post.meta.title, post.meta.teaser, post.meta.body, post.meta.pubdate = 
    title, teaser, body, pubdate
  post.meta.views = [post.blog.view.to_s] + views
  post.meta.tags = []
  post.blog.make_slug(post.meta)  # adds to meta

  # create_draft
  viewhome = post.blog.view.publisher.url
  meta = post.meta
  if file.nil?
    text = RuneBlog.post_template(num: meta.num, title: meta.title, date: meta.pubdate, 
               view: meta.view, teaser: meta.teaser, body: meta.body,
               views: meta.views, tags: meta.tags, home: viewhome)
    srcdir = post.blog.root/:drafts + "/"
    vpdir = post.blog.root/:drafts + "/"
    fname  = meta.slug + ".lt3"
    post.draft = srcdir + fname
    dump(text, post.draft)
  else
    dump(File.read(file), post.draft)
  end
  return post
end

.load(post) ⇒ Object

Raises:

  • (NotImplemented)


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/post.rb', line 12

def self.load(post)
  log!(enter: __method__, args: [post], level: 3)
  raise NotImplemented
  raise NoBlogAccessor if RuneBlog.blog.nil?
  # "post" is a slug?
  pdir = RuneBlog.blog.root/:drafts/post
  meta = nil
  Dir.chdir(pdir) do
#     meta = read_config("metadata.txt")
#     meta.date = Date.parse(meta.date)
#     meta.views = meta.views.split
#     meta.tags = meta.tags.split
#     meta.teaser = File.read("teaser.txt")
#     meta.body = File.read("body.txt")
  end
  meta
end

Instance Method Details

#buildObject



76
77
78
79
80
81
82
# File 'lib/post.rb', line 76

def build
  log!(enter: __method__)
  post = self
  views = post.meta.views
  @blog.generate_post(@draft)
  @blog.generate_index(@blog.view)
end

#editObject



68
69
70
71
72
73
74
# File 'lib/post.rb', line 68

def edit
  log!(enter: __method__)
  edit_file(@draft, vim: "+8")
  build
rescue => err
  error(err)
end