require 'ostruct'
require 'yaml'
def init_liveblog
@teaser = ""
@body = ""
@dest = @teaser
@meta = ::OpenStruct.new
end
def _errout(*args)
::STDERR.puts *args
end
def _passthru(line)
@dest << "
" if line == "\n" and ! @_nopara
line = _formatting(line)
@dest << line
end
def title
@meta.title = @_data
@dest << "
#{@meta.title}
"
end
def pubdate
_debug "data = #@_data"
match = /(\d{4}).(\d{2}).(\d{2})/.match @_data
junk, y, m, d = match.to_a
y, m, d = y.to_i, m.to_i, d.to_i
@meta.date = ::Date.new(y, m, d)
@meta.pubdate = "%04d%02d%02d" % [y, m, d]
end
def categories
_debug "args = #{_args}"
@meta.categories = _args
end
def views
_debug "data = #{_args}"
@meta.views = _args # + ["main"]
end
def readmore
@meta.teaser = @dest
@dest = @dest + @body
end
def liveblog_version
end
def list
@dest << ""
_body {|line| @dest << "- #{line}
" }
@dest << "
"
end
def list!
@dest << ""
lines = _body.each # {|line| @dest << "- #{line}
" }
loop do
line = lines.next
line = _formatting(line)
if line[0] == " "
@dest << line
else
@dest << "- #{line}
"
end
end
@dest << "
"
end
def finalize
STDERR.puts "finalize: @meta = #{@meta.inspect}"
@meta.slug = make_slug(@meta.title, @config.sequence)
@meta.body = @dest
@meta
end
#####
def generate(view)
dir = "views/#{view}"
_errout("dir = #{dir}")
out = "#{dir}/compiled/#{@meta.slug}.html"
@post_header = ::File.read("#{dir}/post_header.html")
@post_trailer = ::File.read("#{dir}/post_trailer.html")
@template = ::File.read("#{dir}/template.html")
title = @meta.title
title.gsub!("'",''')
title.gsub!('"','_')
teaser = @meta.teaser
server, dir = @deployment[view]
url = "http://#{server}/#{server}/#{@meta.slug}.html"
tweet = ""#{title}"\n"
tweet.gsub!("'",''')
text = eval("< err
::STDERR.puts "#{err}\n#{err.backtrace.map {|x| " " + x }.join("\n") }"
end
def generate_index(view) # FIXME
dir = "views/#{view}"
cdir = "views/#{view}/compiled"
posts = ::Dir["#{cdir}/*.yaml"].sort {|a,b| b <=> a }
out = ::File.read("#{dir}/blogheader.html")
server, destdir = @deployment[view]
posts.each do |fname|
meta = ::YAML.load(::File.read(fname))
# name2 = fname.sub("compiled",) # FIXME
name2 = fname.sub("compiled",destdir)
html = name2.sub(/yaml/, "html")
out << <<-HTML
#{meta["pubdate"]}
#{meta["title"]}
#{meta["teaser"]}
Read more...
HTML
end
out << <<-HTML