58 lines
1.2 KiB
Ruby
Executable File
58 lines
1.2 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 += '/' unless dn.end_with? '/'
|
|
|
|
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) }
|
|
text.sub!('$version') { `git log --pretty=format:'%as %h' -1` }
|
|
puts text
|
|
$index.push title
|
|
end
|
|
|
|
$index = []
|
|
|
|
re = Regexp.new '^%s' % dn
|
|
require 'find'
|
|
Find.find(dn) do |path|
|
|
next if test 'd', path
|
|
name = File.join(File.dirname(path), File.basename(path, '.*'))
|
|
name.sub! re, ''
|
|
out path, name
|
|
end
|
|
|
|
puts ':: index'
|
|
$index.sort.each { |name| puts '[[%s]]' % name }
|