lib/repl.rb in runeblog-0.0.33 vs lib/repl.rb in runeblog-0.0.34
- old
+ new
@@ -78,11 +78,11 @@
def read_config
# Crude - FIXME later
cfg_file = ".blog"
new_blog! unless File.exist?(cfg_file)
- @config = RuneBlog::Config.new(".blog")
+ @config = RuneBlog::Config.new(cfg_file)
@view = @config.view # current view
@sequence = @config.sequence
@root = @config.root
end
@@ -118,14 +118,12 @@
### open_remote
def open_remote
@deploy ||= {}
- unless @deploy[@view]
- puts red("\n Deploy first.")
- return
- end
+ return puts red("\n Deploy first.") unless @deploy[@view]
+
lines = @deploy[@view]
user, server, sroot, spath = *lines
system("open 'http://#{server}/#{spath}'")
end
@@ -224,12 +222,13 @@
def link_post_view(view)
# Create dir using slug (index.html, metadata?)
vdir = @config.viewdir(view)
dir = vdir + @meta.slug + "/"
- cmd = "mkdir -p #{dir}" #-- FIXME what if this exists??
- system(cmd)
+ cmd = "mkdir -p #{dir}"
+ system(cmd) unless File.exist?(dir) and File.directory?(dir)
+
File.write("#{dir}/metadata.yaml", @meta.to_yaml)
template = File.read(vdir + "custom/post_template.html")
post = interpolate(template)
File.write(dir + "index.html", post)
generate_index(view)
@@ -370,14 +369,12 @@
def remove_post(arg)
id = Integer(arg) rescue raise("'#{arg}' is not an integer")
tag = "#{'%04d' % id}-"
files = Find.find(@root).to_a
files = files.grep(/#{tag}/)
- if files.empty?
- puts red("\n No such post found")
- return
- end
+ return puts red("\n No such post found") if files.empty?
+
puts
files.each {|f| puts " #{f}" }
ques = files.size > 1 ? "\n Delete all these? " : "\n Delete? "
yn = ask red(ques)
if yn.downcase == "y" #-- maybe implement trash later?
@@ -399,18 +396,12 @@
id = Integer(arg) rescue raise("'#{arg}' is not an integer")
tag = "#{'%04d' % id}-"
files = Find.find(@root+"/src").to_a
files = files.grep(/#{tag}/)
files = files.map {|f| File.basename(f) }
- if files.size > 1
- puts red("Multiple files: #{files}")
- return
- end
- if files.empty?
- puts red("\n No such post found")
- return
- end
+ return puts red("Multiple files: #{files}") if files.size > 1
+ return puts red("\n No such post found") if files.empty?
file = files.first
system("vi #@root/src/#{file}")
rebuild_post(file)
rescue => err
@@ -422,14 +413,14 @@
def list_posts
dir = @config.viewdir(@view)
Dir.chdir(dir) do
posts = Dir.entries(".").grep(/^0.*/)
- puts
if posts.empty?
- puts " No posts"
+ puts "\n " + @view + ":" + red(" No posts")
else
+ puts "\n " + @view + ":\n "
posts.each {|post| puts " #{colored_slug(post)}" }
end
end
rescue
puts "Oops? cwd = #{Dir.pwd} dir = #{dir}"
@@ -442,10 +433,10 @@
dir = "#@root/src"
Dir.chdir(dir) do
posts = Dir.entries(".").grep(/^0.*.lt3/)
puts
if posts.empty?
- puts " No posts"
+ puts red(" No posts")
else
posts.each {|post| puts " #{colored_slug(post.sub(/.lt3$/, ""))}" }
end
end
rescue