lib/runeblog.rb in runeblog-0.0.21 vs lib/runeblog.rb in runeblog-0.0.22
- old
+ new
@@ -1,8 +1,8 @@
class RuneBlog
- VERSION = "0.0.21"
+ VERSION = "0.0.22"
Path = File.expand_path(File.join(File.dirname(__FILE__)))
DefaultData = Path + "/../data"
BlogHeader = File.read(DefaultData + "/blog_header.html") rescue "not found"
@@ -31,10 +31,14 @@
def bold(str)
"\e[1m#{str}\e[22m"
end
+def interpolate(str)
+ wrap = "<<-EOS\n#{str}EOS"
+ eval wrap
+end
### ask
def ask(prompt, meth = :to_s)
@@ -66,11 +70,11 @@
system("cp -r #{RuneBlog::DefaultData} .")
File.open(".blog", "w") do |f|
f.puts "data"
f.puts "no_default"
end
- system("echo Created #{Time.now} >>data/VERSION")
+ File.open("data/VERSION", "a") {|f| f.puts "\nBlog created: " + Time.now.to_s }
end
end
end
### next_sequence
@@ -183,36 +187,33 @@
vdir = "#{@config.root}/views/#{view}"
posts = Dir.entries(vdir).grep /^\d\d\d\d/
posts = posts.sort.reverse
# Add view header/trailer
- @bloghead = File.read("#{vdir}/custom/blogheader.html") rescue ""
- @blogtail = File.read("#{vdir}/custom/blogtrailer.html") rescue ""
+ @bloghead = interpolate(BlogHeader)
+ @blogtail = interpolate(BlogTrailer)
# Output view
posts.map! {|post| YAML.load(File.read("#{vdir}/#{post}/metadata.yaml")) }
- out = @bloghead.dup
+ out = @bloghead
posts.each {|post| out << posting(view, post) }
out << @blogtail
File.open("#{vdir}/index.html", "w") {|f| f.puts out }
end
### link_post_view
def link_post_view(view)
# Create dir using slug (index.html, metadata?)
vdir = "#{@config.root}/views/#{view}"
-p "vdir = #{vdir}"
dir = "#{vdir}/#{@meta.slug}"
-p "dir = #{dir}"
-p "cwd = #{Dir.pwd}"
cmd = "mkdir -p #{dir}" #-- FIXME what if this exists??
puts " Running: #{cmd}"
system(cmd)
File.write("#{dir}/metadata.yaml", @meta.to_yaml)
# Add header/trailer to post index
- @posthead ||= File.read("#{vdir}/postheader.html") rescue ""
- @posttail ||= File.read("#{vdir}/posttrailer.html") rescue ""
+ @posthead = interpolate(PostHeader)
+ @posttail = interpolate(PostTrailer)
File.open("#{dir}/index.html", "w") do |f|
f.puts @posthead
f.puts @meta.body
f.puts @posttail
end