lib/post.rb in runeblog-0.2.47 vs lib/post.rb in runeblog-0.2.48
- old
+ new
@@ -60,12 +60,12 @@
@blog = RuneBlog.blog || raise(NoBlogAccessor)
@meta = OpenStruct.new
end
def self.create(title:, teaser:, body:, pubdate: Time.now.strftime("%Y-%m-%d"),
- views:[])
- log!(enter: __method__, args: [title, teaser, body, pubdate, views])
+ 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
@@ -76,18 +76,22 @@
post.blog.make_slug(post.meta) # adds to meta
# create_draft
viewhome = post.blog.view.publisher.url
meta = post.meta
- 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)
+ 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
def edit
log!(enter: __method__)
@@ -123,9 +127,12 @@
# FIXME dumb hacks...
mdfile = postdir/"metadata.txt"
lines = File.readlines(mdfile)
@title = lines.grep(/title:/).first[7..-1].chomp
@date = lines.grep(/pubdate:/).first[9..-1].chomp
+# print "-- date = #{@date.inspect} "; gets
+ rescue => err
+ STDERR.puts "--- #{err}\n #{err.backtrace.join("\n ")}"
end
def get_dirs
log!(enter: __method__, args: [view, postdir], level: 3)
fname = File.basename(draft)