This post originated from an RSS feed registered with Java Buzz
by Brian McCallister.
Original Post: New Blog Tooling
Feed Title: Waste of Time
Feed URL: http://kasparov.skife.org/blog/index.rss
Feed Description: A simple waste of time and weblog experiment
To help out with the new blogging system I had fun hacking up some support scripts. I tried a new style this time, one base script and a bunch of plugins, so I do things now, as
$ blog create new_blog_tooling $ blog edit new_blog_tooling
Which is kind of shiny. I did it in ruby as I wanted to just get it done, but as I futzedI realized I really wanted a module system more like Lua or Erlang’s – I didn’t want to know the module name, but wanted to access stuff on it.
The closest I got was a pretty gross eval hack, which looks like
defload_commandcommand it=File.open(File.join(CommandDir,"#{command}.rb"))do|f| f.readlines.join("") end ms=<<-EOM Class.new do #{it} end EOM eval(ms).new end
Which creates an instance of an anonymous class and lets me call methods on it, the “plugins” then are just bare method definitions, like
defexecute draft_dir=File.join(BaseDir,"drafts") name=ARGV[1] exec"#{ENV['EDITOR']}#{File.join(draftdir,"#{name}.textile")}" end
defusage "<name>" end
defhelp "open <name> in $EDITOR" end
Which are usd to generate help and execute the actual commands,
$ blog -h
Usage: blog command[additional]
blog create <name>
creates a new draft with name <name>
blog drafts
list all drafts
blog edit <name>
open <name> in $EDITOR
blog kill <name>
destroy the draft <name>
$
Annoyed at having to use an eval hack, but hey, it works.