lib/runeblog.rb in runeblog-0.2.43 vs lib/runeblog.rb in runeblog-0.2.44
- old
+ new
@@ -51,11 +51,11 @@
puts "Can't create blog repo: '#{dir}' - #{err}"
puts err.backtrace.join("\n")
end
def self.create(root = ".blogs")
- log!(enter: __method__, args: [root])
+ log!(enter: __method__, args: [root], level: 1)
# Crude - FIXME later - # What views are there? Publishing, etc.
self.blog = self # Weird. Like a singleton - dumbass circular dependency?
root = Dir.pwd/root
raise BlogRepoAlreadyExists if Dir.exist?(root)
create_dirs(root)
@@ -99,11 +99,11 @@
@post_views = []
@post_tags = []
end
def _deploy_local(dir)
- log!(enter: __method__, args: [dir])
+ log!(enter: __method__, args: [dir], level: 1)
Dir.chdir(dir) do
views = _retrieve_metadata(:views)
views.each {|v| system!("cp *html #@root/views/#{v}/remote") }
end
end
@@ -130,54 +130,54 @@
end
return result
end
def process_post(sourcefile)
- log!(enter: __method__, args: [dir])
+ log!(enter: __method__, args: [dir], level: 2)
nslug = sourcefile.sub(/.lt3/, "")
dir = @root/:posts/nslug
create_dir(dir)
xlate cwd: dir, src: sourcefile # , debug: true
_deploy_local(dir)
end
def inspect
- log!(enter: __method__)
+ log!(enter: __method__, level: 3)
str = "blog: "
ivars = ["@root", "@sequence"] # self.instance_variables
ivars.each do |iv|
val = self.instance_variable_get(iv)
str << "#{iv}: #{val} "
end
str
end
def view?(name)
- log!(enter: __method__, args: [name])
+ log!(enter: __method__, args: [name], level: 3)
raise ArgumentError unless name.is_a?(String) && ! name.empty?
views.any? {|x| x.name == name }
end
def view(name = nil)
- log!(enter: __method__, args: [name])
+ log!(enter: __method__, args: [name], level: 3)
raise ArgumentError unless name.nil? || (name.is_a?(String) && ! name.empty?)
name.nil? ? @view : str2view(name)
end
def str2view(str)
- log!(enter: __method__, args: [str])
+ log!(enter: __method__, args: [str], level: 3)
raise ArgumentError unless str.is_a?(String) && ! str.empty?
@views.find {|x| x.name == str }
end
def _set_publisher
- log!(enter: __method__)
+ log!(enter: __method__, level: 3)
@view.publisher = RuneBlog::Publishing.new(@view.to_s) # FIXME refactor
end
def view=(arg)
- log!(enter: __method__, args: [arg])
+ log!(enter: __method__, args: [arg], level: 2)
case arg
when RuneBlog::View
@view = arg
_set_publisher
when String
@@ -189,57 +189,57 @@
raise CantAssignView(arg.class.to_s)
end
end
def get_sequence
- log!(enter: __method__)
+ log!(enter: __method__, level: 3)
File.read(@root/:sequence).to_i
end
def next_sequence
- log!(enter: __method__)
+ log!(enter: __method__, level: 3)
@sequence += 1
dump(@sequence, @root/:sequence)
@sequence
end
def viewdir(v = nil) # delete?
- log!(enter: __method__, args: [v])
+ log!(enter: __method__, args: [v], level: 3)
v = str2view(v) if v.is_a?(String)
raise ArgumentError unless v.nil? || v.is_a?(RuneBlog::View)
v ||= @view
return @root/:views/v
end
def self.exist?
- log!(enter: __method__)
+ log!(enter: __method__, level: 3)
Dir.exist?(DotDir) && File.exist?(DotDir/ConfigFile)
end
def mark_last_published(str)
- log!(enter: __method__, args: [str])
+ log!(enter: __method__, args: [str], level: 2)
dump(str, "#{self.view.dir}/last_published")
end
def add_view(view_name)
- log!(enter: __method__, args: [view_name])
+ log!(enter: __method__, args: [view_name], level: 2)
view = RuneBlog::View.new(view_name)
@view = view # current view
@views << view # all views
view
end
def make_empty_view_tree(view_name)
- log!(enter: __method__, args: [view_name])
+ log!(enter: __method__, args: [view_name], level: 2)
Dir.chdir(@root) do
cmd = "cp -r #{RuneBlog::Path}/../empty_view views/#{view_name}"
system!(cmd)
end
end
def check_valid_new_view(view_name)
- log!(enter: __method__, args: [view_name])
+ log!(enter: __method__, args: [view_name], level: 3)
raise ArgumentError unless view_name.is_a?(String)
raise ArgumentError if view_name.empty?
names = self.views.map(&:to_s)
bad = names.include?(view_name)
raise ViewAlreadyExists(view_name) if bad
@@ -247,13 +247,15 @@
raise DirAlreadyExists(view_name) if Dir.exist?(vdir)
return true # hm?
end
def create_view(view_name)
- log!(enter: __method__, args: [view_name])
+ log!(enter: __method__, args: [view_name], level: 2)
check_valid_new_view(view_name)
make_empty_view_tree(view_name)
+# STDERR.puts "Made empty tree!"
+# system("bash")
add_view(view_name)
mark_last_published("Initial creation")
end
def delete_view(name, force = false)
@@ -265,19 +267,19 @@
@views -= [str2view(name)]
end
end
def view_files
- log!(enter: __method__)
+ log!(enter: __method__, level: 2)
vdir = self.view.dir
files = [vdir/"index.html"]
files += posts.map {|x| vdir/x }
files.reject! {|f| File.mtime(f) < File.mtime(vdir/:last_published) }
end
def post_lookup(postid) # side-effect?
- log!(enter: __method__, args: [postid])
+ log!(enter: __method__, args: [postid], level: 2)
slug = title = date = teaser_text = nil
dir_posts = @vdir/:posts
posts = Dir.entries(dir_posts).grep(/^\d\d\d\d/).map {|x| dir_posts/x }
posts.select! {|x| File.directory?(x) }
@@ -288,11 +290,11 @@
vp = RuneBlog::ViewPost.new(self.view, postdir)
vp
end
def index_entry(slug)
- log!(enter: __method__, args: [slug])
+ log!(enter: __method__, args: [slug], level: 2)
id = slug.to_i
text = nil
@theme = @view.dir/"themes/standard"
post_entry_name = @theme/"blog/post_entry.lt3"
xlate src: post_entry_name, dst: "/tmp/post_entry.html" # , debug: true
@@ -307,11 +309,11 @@
text = interpolate(@_post_entry, binding)
text
end
def collect_recent_posts(file)
- log!(enter: __method__, args: [file])
+ log!(enter: __method__, args: [file], level: 3)
posts = nil
dir_posts = @vdir/:posts
entries = Dir.entries(dir_posts)
posts = entries.grep(/^\d\d\d\d/).map {|x| dir_posts/x }
posts.select! {|x| File.directory?(x) }
@@ -333,11 +335,11 @@
text << "</body></html>"
File.write(@vdir/:remote/file, text)
end
def create_new_post(title, testing = false, teaser: nil, body: nil, views: [])
- log!(enter: __method__, args: [title, testing, teaser, body, views])
+ log!(enter: __method__, args: [title, testing, teaser, body, views], level: 1)
meta = nil
views = views + [self.view.to_s]
Dir.chdir(@root/:posts) do
post = Post.create(title: title, teaser: teaser, body: body, views: views)
post.edit unless testing
@@ -349,11 +351,11 @@
puts err
puts err.backtrace.join("\n")
end
def edit_initial_post(file, testing = false)
- log!(enter: __method__, args: [file, testing])
+ log!(enter: __method__, args: [file, testing], level: 3)
debug "=== edit_initial_post #{file.inspect} => #{sourcefile}"
sourcefile = @root/:drafts/file
result = system!("#@editor #{sourcefile} +8") unless testing
raise EditorProblem(sourcefile) unless result
process_post(sourcefile)
@@ -361,24 +363,24 @@
rescue => err
error(err)
end
def posts
- log!(enter: __method__)
+ log!(enter: __method__, level: 3)
dir = self.view.dir/:posts
posts = Dir.entries(dir).grep(/^\d{4}/)
posts
end
def drafts
- log!(enter: __method__)
+ log!(enter: __method__, level: 3)
dir = @root/:drafts
drafts = Dir.entries(dir).grep(/^\d{4}.*/)
end
def change_view(view)
- log!(enter: __method__, args: [view])
+ log!(enter: __method__, args: [view], level: 3)
raise ArgumentError unless view.is_a?(String) || view.is_a?(RuneBlog::View)
x = OpenStruct.new
x.root, x.current_view, x.editor = @root, view.to_s, @editor # dumb - FIXME later
write_config(x, @root/ConfigFile)
self.view = view # error checking?
@@ -398,33 +400,33 @@
@theme = @root/:views/view/:themes/:standard
xlate cwd: vdir/"themes/standard/etc",
src: "blog.css.lt3", copy: vdir/"remote/etc/blog.css" # , debug: true
xlate cwd: vdir/"themes/standard",
src: "blog/generate.lt3", dst: vdir/:remote/"index.html"
- generate_index(view) # recent posts (recent.html)
+# generate_index(view) # recent posts (recent.html)
# ^ HERE
copy("#{vdir}/assets/*", "#{vdir}/remote/assets/")
rescue => err
puts err
puts err.backtrace.join("\n")
print "Pause... "
gets
end
def _get_views(draft)
- log!(enter: __method__, args: [draft])
+ log!(enter: __method__, args: [draft], level: 2)
# FIXME dumb code
view_line = File.readlines(draft).grep(/^.views /)
raise "More than one .views call!" if view_line.size > 1
raise "No .views call!" if view_line.size < 1
view_line = view_line.first
views = view_line[7..-1].split
views
end
def _copy_get_dirs(draft, view)
- log!(enter: __method__, args: [draft, view])
+ log!(enter: __method__, args: [draft, view], level: 2)
fname = File.basename(draft)
noext = fname.sub(/.lt3$/, "")
vdir = @root/:views/view
dir = vdir/:posts/noext
Dir.mkdir(dir) unless Dir.exist?(dir)
@@ -433,16 +435,16 @@
theme = viewdir/:themes/:standard
[noext, viewdir, slugdir, aslug, theme]
end
def _post_metadata(draft, pdraft)
- log!(enter: __method__, args: [draft, pdraft])
+ log!(enter: __method__, args: [draft, pdraft], level: 2)
# FIXME store this somewhere
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
+ pnum = nslug[0..3] # 0001
Dir.chdir(pdraft) do
excerpt = File.read("teaser.txt")
date = _retrieve_metadata(:date)
longdate = ::Date.parse(date).strftime("%B %e, %Y")
title = _retrieve_metadata(:title)
@@ -468,27 +470,30 @@
File.open(pdraft/"vars.lt3", "w") {|f| f.puts vars }
end
end
def copy_widget_html(view)
- log!(enter: __method__)
+ log!(enter: __method__, level: 2)
vdir = @root/:views/view
remote = vdir/:remote
wdir = vdir/:themes/:standard/:widgets
widgets = Dir[wdir/"*"].select {|w| File.directory?(w) }
widgets.each do |w|
dir = File.basename(w)
rem = w.sub(/themes.standard/, "remote")
create_dirs(rem)
files = Dir[w/"*"]
files = files.select {|x| x =~ /(html|css)$/ }
- files.each {|file| system!("cp #{file} #{rem}") }
+# files.each {|f| STDERR.puts " #{f.inspect}" }
+ tag = File.basename(w)
+# STDERR.puts "--- tag: #{tag.inspect}"
+ files.each {|file| system!("cp #{file} #{rem}", show: (tag == "zzz")) }
end
end
def _handle_post(draft, view)
- log!(enter: __method__, args: [draft, view])
+ log!(enter: __method__, args: [draft, view], level: 2)
# break into separate methods?
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
@@ -513,11 +518,11 @@
dst: remote/:permalink/ahtml # , debug: true
copy_widget_html(view)
end
def generate_post(draft)
- log!(enter: __method__, args: [draft])
+ log!(enter: __method__, args: [draft], level: 1)
views = _get_views(draft)
views.each do |view|
_handle_post(draft, view)
# generate_view(view) # FIXME leads to inefficiency?
# ^ HERE
@@ -559,11 +564,11 @@
error(err)
getch
end
def remove_post(num)
- log!(enter: __method__, args: [num])
+ log!(enter: __method__, args: [num], level: 1)
raise ArgumentError unless num.is_a?(Integer)
# FIXME update original draft .views
tag = prefix(num)
files = Find.find(self.view.dir).to_a
list = files.select {|x| File.directory?(x) and x =~ /#{tag}/ }
@@ -576,11 +581,11 @@
# FIXME - update index/etc
true
end
def undelete_post(num)
- log!(enter: __method__, args: [num])
+ log!(enter: __method__, args: [num], level: 1)
raise ArgumentError unless num.is_a?(Integer)
files = Find.find(@root/:views).to_a
tag = prefix(num)
list = files.select {|x| File.directory?(x) and x =~ /_#{tag}/ }
return nil if list.empty?
@@ -592,17 +597,17 @@
# FIXME - update index/etc
true
end
def delete_draft(num)
- log!(enter: __method__, args: [num])
+ log!(enter: __method__, args: [num], level: 1)
raise ArgumentError unless num.is_a?(Integer)
tag = prefix(num)
system!("rm -rf #@root/drafts/#{tag}-*")
end
def make_slug(meta)
- log!(enter: __method__, args: [meta])
+ log!(enter: __method__, args: [meta], level: 3)
raise ArgumentError unless meta.title.is_a?(String)
label = '%04d' % meta.num # FIXME can do better
slug0 = meta.title.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')
str = "#{label}-#{slug0}"
meta.slug = str