made filename munging more idiomatic, rake tasks work properly again

This commit is contained in:
jdp 2010-03-17 02:35:06 -04:00
parent 3af16f3afe
commit 1978a5fe98
3 changed files with 5 additions and 7 deletions

View File

@ -83,8 +83,7 @@ Dir.mkdir output_dir if !File.directory?(output_dir)
# Run each file through Rocco and write output.
sources.each do |filename|
rocco = Rocco.new(filename, sources, options)
fnparts = filename.split('.')
dest = fnparts.slice(0, fnparts.length - 1).join('.') + '.html'
dest = filename.split('.')[0..-2].join('.') + '.html'
puts "rocco: #{filename} -> #{dest}"
File.open(dest, 'wb') { |fd| fd.write(rocco.to_html) }
end

View File

@ -28,11 +28,10 @@ class Rocco::Layout < Mustache
def sources
@doc.sources.sort.map do |source|
srcparts = File.basename(source).split('.')
{
:path => source,
:basename => File.basename(source),
:url => srcparts.slice(0, srcparts.length - 1).join('.') + '.html'
:url => File.basename(source).split('.')[0..-2].join('.') + '.html'
}
end
end

View File

@ -51,8 +51,8 @@ require 'rocco'
# of sugar over `Rocco::Task.new`. If you want your Rake task to be named
# something other than `:rocco`, you can use `Rocco::Task` directly.
class Rocco
def self.make(dest='docs/', source_files='lib/**/*.rb')
Task.new(:rocco, dest, source_files)
def self.make(dest='docs/', source_files='lib/**/*.rb', options={})
Task.new(:rocco, dest, source_files, options)
end
# `Rocco::Task.new` takes a task name, the destination directory docs
@ -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, '.rb') + '.html'
dest_file = File.basename(source_file).split('.')[0..-2].join('.') + '.html'
define_file_task source_file, "#{@dest}#{dest_file}"
# If `rake/clean` was required, add the generated files to the list.