lib/runeblog.rb in runeblog-0.0.16 vs lib/runeblog.rb in runeblog-0.0.17
- old
+ new
@@ -1,8 +1,11 @@
+require 'find'
+require 'yaml'
+
class RuneBlog
- VERSION = "0.0.16"
+ VERSION = "0.0.17"
Path = File.expand_path(File.join(File.dirname(__FILE__)))
DefaultData = Path + "/../data"
BlogHeader = File.read(DefaultData + "/blog_header.html") rescue "not found"
@@ -28,12 +31,10 @@
end
# FIXME lots of structure changes
-require 'yaml'
-
=begin
Post
----
Create a blog post
@@ -79,11 +80,11 @@
### new_blog!
def new_blog!
unless File.exist?(".blog")
- yn = ask("No .blog found. Create new blog?")
+ yn = ask(red(" No .blog found. Create new blog?"))
if yn.upcase == "Y"
#-- what if data already exists?
system("cp -r #{RuneBlog::DefaultData} .")
File.open(".blog", "w") {|f| f.puts "data" }
end
@@ -268,11 +269,11 @@
end
### publish?
def publish?
- yn = ask("Publish? y/n ")
+ yn = ask(red(" Publish? y/n "))
yn.upcase == "Y"
end
### publish_post
@@ -291,11 +292,13 @@
end
### change_view
def change_view(arg = nil)
- if @config.views.include?(arg)
+ if arg.nil?
+ puts "\n #@view"
+ elsif @config.views.include?(arg)
@view = arg
else
puts "view #{arg.inspect} does not exist"
end
end
@@ -305,10 +308,11 @@
def new_view(arg = nil)
arg = nil if arg == ""
read_config unless @config
arg ||= ask("New view: ") # check validity later
raise "view #{arg} already exists" if @config.views.include?(arg)
+
dir = @config.root + "/views/" + arg
cmd = "mkdir -p #{dir}/custom"
system(cmd)
File.write("#{dir}/custom/blog_header.html", RuneBlog::BlogHeader)
File.write("#{dir}/custom/blog_trailer.html", RuneBlog::BlogTrailer)
@@ -352,10 +356,38 @@
link_post(@meta)
publish_post
end
end
+### remove_post
+
+#-- FIXME affects linking, building, deployment...
+
+def remove_post(arg)
+ id = Integer(arg) rescue raise("'#{arg}' is not an integer")
+ tag = "#{'%04d' % id}-"
+ files = Find.find("#{@config.root}").to_a
+ files = files.grep(/#{tag}/)
+ if files.empty?
+ puts "\n No such post found"
+ return
+ end
+ puts
+ files.each {|f| puts " #{f}" }
+ yn = ask red("\n Delete all these? ")
+ if yn.downcase == "y"
+ #-- maybe implement trash later?
+ system("rm -rf #{files.join(' ')}")
+ puts red("\n Deleted")
+ else
+ puts red("\n No action taken")
+ end
+rescue => err
+ puts err
+ puts
+end
+
### list_posts
def list_posts
dir = "#{@config.root}/views/#@view/"
Dir.chdir(dir) do
@@ -369,7 +401,26 @@
end
rescue
puts "Oops? cwd = #{Dir.pwd} dir = #{dir}"
exit
end
+
+### list_drafts
+
+def list_drafts
+ dir = "#{@config.root}/src"
+ Dir.chdir(dir) do
+ posts = Dir.entries(".").grep(/^0.*.lt3/)
+ puts
+ if posts.empty?
+ puts "No posts"
+ else
+ posts.each {|post| puts " #{post.sub(/.lt3$/, "")}" }
+ end
+ end
+rescue
+ puts "Oops? cwd = #{Dir.pwd} dir = #{dir}"
+ exit
+end
+