wtssts/bin/mktwee

56 lines
1.1 KiB
Ruby
Executable File

#!/usr/bin/env ruby
dn = ARGV.first
raise 'Usage: mktwee DIR' if dn.nil?
raise '%p is not a dir' % dn unless test 'd', dn
dn.end_with?('/') || dn += '/'
def out_special path
case File.extname path
when '.css' then
puts ':: Story Stylesheet [stylesheet]'
puts File.read path
when '.js' then
puts ':: Story JavaScript [script]'
puts File.read path
when '.data' then
puts ':: StoryData'
puts File.read path
when '.title' then
puts ':: StoryTitle'
puts File.read path
else raise 'Unknown extension for %s' % path
end
end
def inc name
pref = name.split('_')
num = Integer(pref.pop, 10)
pref.push '%02i' % (num + 1)
pref.join '_'
end
def out path, name
return out_special path if 'story' == name
title = name.gsub '/', '_'
puts ':: %s' % title
text = File.read(path)
text.sub!('|next]]') { '|%s]]' % inc(title) }
puts text
$index.push title
end
$index = []
require 'find'
Find.find(dn) do |path|
next if test('d', path)
name = File.join(File.dirname(path), File.basename(path, '.*'))
name.sub! Regexp.new('^%s' % dn), ''
out path, name
end
puts ':: index'
$index.sort.each { |name| puts '[[%s]]' % name }