lib/runeblog.rb in runeblog-0.2.70 vs lib/runeblog.rb in runeblog-0.2.71
- old
+ new
@@ -10,11 +10,11 @@
require 'default'
require 'view'
require 'publish'
require 'post'
-require 'pathmagic'
+# require 'pathmagic'
###
class RuneBlog
@@ -62,10 +62,11 @@
raise BlogRepoAlreadyExists if Dir.exist?(root)
create_dirs(root)
Dir.chdir(root) do
create_dirs(:data, :drafts, :views, :posts)
copy_data(:config, "./data/")
+ File.write("data/ROOT", Dir.pwd + "\n")
new_sequence
end
@blog = self.new(root)
@blog
rescue => err
@@ -88,14 +89,16 @@
# Crude - FIXME later - # What views are there? Publishing, etc.
self.class.blog = self # Weird. Like a singleton - dumbass circular dependency?
@root = root_dir
read_config
- md = Dir.pwd.match(%r[.*/views/(.*?)/])
- @view_name = md[1] if md
@views = get_views
- @view = str2view(@view_name)
+ md = Dir.pwd.match(%r[.*/views/(.*?)/])
+ if md
+ @view_name = md[1]
+ @view = str2view(@view_name)
+ end
@sequence = get_sequence
@post_views = []
@post_tags = []
end
@@ -371,11 +374,11 @@
entry = index_entry(postid)
entries << entry
text << entry
end
text << "</body></html>"
- File.write(@vdir/:remote/file, text)
+ File.write(@vdir/:remote/file, text + "\n")
return posts.size
rescue => err
_tmp_error(err)
end
@@ -383,14 +386,19 @@
pubdate: Time.now.strftime("%Y-%m-%d"), views: [])
log!(enter: __method__, args: [title, testing, teaser, body, views], level: 1, stderr: true)
meta = nil
views = views + [self.view.to_s]
views.uniq!
+p :cnp1
Dir.chdir(@root/"posts") do
+p :cnp2
post = Post.create(title: title, teaser: teaser, body: body, pubdate: pubdate, views: views)
+p :cnp3
post.edit unless testing
+p :cnp4
post.build
+p :cnp5
meta = post.meta
end
return meta.num
rescue => err
_tmp_error(err)
@@ -414,11 +422,11 @@
def change_view(view)
log!(enter: __method__, args: [view], level: 3)
raise ArgumentError unless view.is_a?(String) || view.is_a?(RuneBlog::View)
x = OpenStruct.new
- File.write(@root/"data/VIEW", view.to_s)
+ File.write(@root/"data/VIEW", view.to_s + "\n")
self.view = view # error checking?
end
def generate_index(view)
log!(enter: __method__, args: [view], pwd: true, dir: true)
@@ -477,20 +485,28 @@
end
def _post_metadata(draft, pdraft)
log!(enter: __method__, args: [draft, pdraft], level: 2)
# FIXME store this somewhere
+p :pm1
fname = File.basename(draft) # 0001-this-is-a-post.lt3
nslug = fname.sub(/.lt3$/, "") # 0001-this-is-a-post
aslug = nslug.sub(/\d\d\d\d-/, "") # this-is-a-post
pnum = nslug[0..3] # 0001
+p :pm2
Dir.chdir(pdraft) do
+p :pm3
excerpt = File.read("teaser.txt")
+p :pm4
date = _retrieve_metadata(:date)
+p :pm5
longdate = ::Date.parse(date).strftime("%B %e, %Y")
+p :pm6
title = _retrieve_metadata(:title)
+p :pm7
tags = _retrieve_metadata(:tags)
+p :pm8
# FIXME simplify
vars = <<~LIVE
.set post.num = #{pnum}
.heredoc post.aslug
#{aslug}
@@ -506,11 +522,13 @@
.end
.heredoc longdate
#{longdate}
.end
LIVE
+p :pm9
File.open(pdraft/"vars.lt3", "w") {|f| f.puts vars }
+p :pma
end
rescue => err
_tmp_error(err)
end
@@ -542,42 +560,57 @@
aslug = nslug.sub(/\d\d\d\d-/, "") # this-is-a-post
ahtml = aslug + ".html" # this-is-a-post.html
pdraft = @root/:posts/nslug
remote = @root/:views/view_name/:remote
@theme = @root/:views/view_name/:themes/:standard
+p :hp1
# Step 1...
create_dirs(pdraft)
+p :hp2
# FIXME dependencies?
xlate cwd: pdraft, src: draft, dst: "guts.html" # , debug: true
+p :hp3
_post_metadata(draft, pdraft)
+p :hp4
# Step 2...
vposts = @root/:views/view_name/:posts
copy!(pdraft, vposts) # ??
+p :hp5
# Step 3..
copy(pdraft/"guts.html", @theme/:post)
copy(pdraft/"vars.lt3", @theme/:post)
+p :hp5
# Step 4...
# FIXME dependencies?
xlate cwd: @theme/:post, src: "generate.lt3", force: true,
dst: remote/ahtml, copy: @theme/:post # , debug: true
+p :hp7
# FIXME dependencies?
xlate cwd: @theme/:post, src: "permalink.lt3",
dst: remote/:permalink/ahtml # , debug: true
+p :hp8
copy_widget_html(view_name)
+p :hp9
rescue => err
_tmp_error(err)
end
def generate_post(draft)
log!(enter: __method__, args: [draft], level: 1)
+p :gp1
views = _get_views(draft)
+p :gp2
views.each do |view|
+p :gp3
unless self.view?(view)
puts "Warning: '#{view}' is not a view"
next
end
+p :gp4
_handle_post(draft, view)
+p :gp5
end
+p :gp6
rescue => err
_tmp_error(err)
end
def rebuild_post(file)