diff --git a/bin/rocco b/bin/rocco index 8684804..a0d99ca 100755 --- a/bin/rocco +++ b/bin/rocco @@ -90,7 +90,7 @@ end # Run each file through Rocco and write output. sources.each do |filename| rocco = Rocco.new(filename, sources, options) - dest = File.join(output_dir, (filename.split('.')[0..-2].empty? ? filename : filename.split('.')[0..-2].join('.')) + '.html') + dest = File.join(output_dir, filename.sub(Regexp.new("#{File.extname(filename)}$"),".html")) puts "rocco: #{filename} -> #{dest}" FileUtils.mkdir_p File.dirname(dest) File.open(dest, 'wb') { |fd| fd.write(rocco.to_html) } diff --git a/lib/rocco/layout.rb b/lib/rocco/layout.rb index 7b790f0..9f0f102 100644 --- a/lib/rocco/layout.rb +++ b/lib/rocco/layout.rb @@ -38,9 +38,9 @@ class Rocco::Layout < Mustache def sources @doc.sources.sort.map do |source| { - :path => source, - :basename => File.basename(source), - :url => File.basename(source).split('.')[0..-2].join('.') + '.html' + :path => source, + :basename => File.basename(source), + :url => source.sub( Regexp.new( "#{File.extname(source)}$"), ".html" ) } end end diff --git a/lib/rocco/tasks.rb b/lib/rocco/tasks.rb index 7c0ac6c..b6ed28d 100644 --- a/lib/rocco/tasks.rb +++ b/lib/rocco/tasks.rb @@ -70,7 +70,7 @@ class Rocco # Run over the source file list, constructing destination filenames # and defining file tasks. @sources.each do |source_file| - dest_file = File.basename(source_file).split('.')[0..-2].join('.') + '.html' + dest_file = source_file.sub(Regexp.new("#{File.extname(source_file)}$"), ".html") define_file_task source_file, "#{@dest}#{dest_file}" # If `rake/clean` was required, add the generated files to the list. @@ -103,6 +103,7 @@ class Rocco file dest_file => prerequisites do |f| verbose { puts "rocco: #{source_file} -> #{dest_file}" } rocco = Rocco.new(source_file, @sources.to_a, @options) + FileUtils.mkdir_p(File.dirname(dest_file)) File.open(dest_file, 'wb') { |fd| fd.write(rocco.to_html) } end task @name => dest_file