class RuneBlog
VERSION = "0.0.3"
Path = File.expand_path(File.join(File.dirname(__FILE__)))
end
# FIXME lots of structure changes
require 'yaml'
=begin
Post
----
Create a blog post
Process it
Link it
Upload to server
data
views
computing
compiled
custom
deployment
=end
require 'rubygems'
require 'ostruct'
require 'livetext'
### ask
def ask(prompt, meth = :to_s)
print prompt
STDOUT.flush
STDIN.gets.chomp.send(meth)
end
### new_blog!
def new_blog!
unless File.exist?(".blog")
yn = ask("No .blog found. Create new blog?")
if yn.upcase == "Y"
system("mkdir data")
File.open(".blog", "w") {|f| f.puts data }
File.open("data/sequence", "w") {|f| f.puts 0 }
end
end
end
### next_sequence
def next_sequence
@config.sequence += 1
File.open("data/sequence", "w") {|f| f.puts @config.sequence }
@config.sequence
end
### make_slug
def make_slug(title, seq=nil)
num = '%04d' % (seq || next_sequence) # FIXME can do better
slug = title.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')
"#{num}-#{slug}"
end
### read_config
def read_config
@config = OpenStruct.new
# What views are there? Deployment, etc.
# Crude - FIXME later
root = File.readlines(".blog").first.chomp rescue "myblog"
dirs = Dir.entries("#{root}/views/") - %w[. ..]
dirs.reject! {|x| ! File.directory?("#{root}/views/#{x}") }
@config.root = root
@config.views = dirs
@config.sequence = File.read(root + "/sequence").to_i
rescue
STDERR.puts "No config file found. Create a new blog?"
resp = gets.chomp
if resp.downcase == "y"
blog_new!
STDERR.puts "Created. Now run again."
end
exit
end
### create_empty_post
def create_empty_post
@template = <<-EOS
.mixin liveblog
.liveblog_version
.title #{@title}
.pubdate #{@date}
.categories elixir ruby
.views computing
Teaser goes here.
.readmore
Remainder of post goes here.
EOS
@slug = make_slug(@title)
@fname = @slug + ".lt3"
File.open("#{@config.root}/src/#{@fname}", "w") {|f| f.puts @template }
@fname
end
### edit_post
def edit_post(file)
system("vi #{@config.root}/src/#{file}")
end
### process_post
def process_post(file)
lt ||= Livetext.new
puts " Processing: #{file}"
lt.process_file(file)
@meta = lt.main.instance_eval { @meta }
@meta.slug = file.sub(/.lt3$/, "")
@meta
end
### reload_post
def reload_post(file)
@main ||= Livetext.new
@meta = process_post("#{@config.root}/src/#{file}")
@meta.slug = file.sub(/.lt3$/, "")
@meta
end
### posting
def posting(meta)
<<-HTML
#{meta.pubdate}
#{meta.title}
#{meta.teaser}
Read more...