<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>test/generator_spec.rb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -21,6 +21,9 @@ parser = OptionParser.new do |opts|
 		&quot;#{' ' * 37}'images/icons'.&quot;) do |value|
 		options[:icons_dir] = value
 	end
+	opts.on(&quot;-o&quot;, &quot;--output FILE&quot;, String, &quot;Specify the output filename.&quot;) do |value|
+		options[:output] = value
+	end
 end
 begin
 	parser.parse!
@@ -34,9 +37,9 @@ end
 begin
 	if ARGV.empty?
 		puts parser
+		exit 1
 	else
-		Mizuho::Generator.new(ARGV[0], nil, options[:template],
-			options[:multi_page], options[:icons_dir]).start
+		Mizuho::Generator.new(ARGV[0], options).start
 	end
 rescue Mizuho::GenerationError
 	STDERR.puts &quot;*** ERROR&quot;</diff>
      <filename>bin/mizuho</filename>
    </modified>
    <modified>
      <diff>@@ -9,22 +9,19 @@ class GenerationError &lt; StandardError
 end
 
 class Generator
-	def initialize(input, output = nil, template_name = nil, multi_page = false, icons_dir = nil)
-		@input = input
-		if output
-			@output_name = output
-		else
-			@output_name = File.expand_path(input.sub(/(.*)\..*$/, '\1'))
-		end
-		@template = locate_template_file(template_name)
-		@multi_page = multi_page
-		@icons_dir = icons_dir
+	def initialize(input, options = {})
+		@input_file = input
+		@output_name = options[:output]
+		@template = locate_template_file(options[:template])
+		@multi_page = options[:multi_page]
+		@icons_dir = options[:icons_dir]
 	end
 	
 	def start
-		self.class.run_asciidoc(@input, &quot;#{@output_name}.html&quot;, @icons_dir)
+		output_filename = determine_output_filename(@input_file, @output_name)
+		self.class.run_asciidoc(@input_file, output_filename, @icons_dir)
 		if @template
-			apply_template(&quot;#{@output_name}.html&quot;, @template, @multi_page)
+			apply_template(output_filename, @input_file, @output_name, @template, @multi_page)
 		end
 	end
 	
@@ -55,11 +52,35 @@ private
 		end
 	end
 	
-	def apply_template(asciidoc_file, template_file, multi_page)
+	def determine_output_filename(input, output = nil, chapter_id = nil)
+		if chapter_id
+			if output
+				dirname = File.dirname(output)
+				extname = File.extname(output)
+				basename = File.basename(output, extname)
+				filename = File.join(dirname, &quot;#{basename}-#{chapter_id}#{extname}&quot;)
+			else
+				dirname = File.dirname(input)
+				basename = File.basename(input, File.extname(input))
+				filename = File.join(dirname, &quot;#{basename}-#{chapter_id}.html&quot;)
+			end
+		else
+			if output
+				filename = output
+			else
+				dirname = File.dirname(input)
+				basename = File.basename(input, File.extname(input))
+				filename = File.join(dirname, &quot;#{basename}.html&quot;)
+			end
+		end
+		return File.expand_path(filename)
+	end
+	
+	def apply_template(asciidoc_file, input_file, output_name, template_file, multi_page)
 		parser = Parser.new(asciidoc_file)
 		if multi_page
 			File.unlink(asciidoc_file)
-			assign_chapter_filenames_and_heading_basenames(parser.chapters)
+			assign_chapter_filenames_and_heading_basenames(parser.chapters, input_file, output_name)
 			parser.chapters.each_with_index do |chapter, i|
 				template = Template.new(template_file,
 					:multi_page? =&gt; true,
@@ -86,14 +107,14 @@ private
 		exit 1
 	end
 	
-	def assign_chapter_filenames_and_heading_basenames(chapters)
+	def assign_chapter_filenames_and_heading_basenames(chapters, input_file, output_name)
 		chapters.each_with_index do |chapter, i|
 			if chapter.is_preamble?
-				chapter.filename = &quot;#{@output_name}.html&quot;
+				chapter.filename = determine_output_filename(input_file, output_name)
 			else
 				title_sha1 = Digest::SHA1.hexdigest(chapter.title_without_numbers)
-				chapter.filename = sprintf(&quot;%s-%s.html&quot;, @output_name,
-					title_sha1.slice(0..7))
+				chapter.filename = determine_output_filename(input_file,
+					output_name, title_sha1.slice(0..7))
 				chapter.heading.basename = File.basename(chapter.filename)
 				chapter.heading.each_descendant do |h|
 					h.basename = File.basename(chapter.filename)</diff>
      <filename>lib/mizuho/generator.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,7 +1,6 @@
 Gem::Specification.new do |s|
   s.name = &quot;mizuho&quot;
-  s.version = &quot;0.9.1&quot;
-  s.date = &quot;2008-07-21&quot;
+  s.version = &quot;0.9.2&quot;
   s.summary = &quot;Mizuho documentation formatting tool&quot;
   s.email = &quot;hongli@phusion.nl&quot;
   s.homepage = &quot;http://github.com/FooBarWidget/mizuho/tree/master&quot;</diff>
      <filename>mizuho.gemspec</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>228acde673f2fa15e3b766ff17edaf20120c5749</id>
    </parent>
  </parents>
  <author>
    <name>Hongli Lai (Phusion)</name>
    <email>hongli@phusion.nl</email>
  </author>
  <url>http://github.com/FooBarWidget/mizuho/commit/f9a3150c4a5931caedb394dc5615413f58a43430</url>
  <id>f9a3150c4a5931caedb394dc5615413f58a43430</id>
  <committed-date>2008-11-04T06:10:21-08:00</committed-date>
  <authored-date>2008-11-04T06:10:21-08:00</authored-date>
  <message>Add a commandline option to Mizuho for specifying the output filename. Refactor Mizuho::Generator.new and make accept an options hash, so that it's future-proof.</message>
  <tree>358354be3fb6c3331bcdea133f58309e65c847ff</tree>
  <committer>
    <name>Hongli Lai (Phusion)</name>
    <email>hongli@phusion.nl</email>
  </committer>
</commit>
