Skip to content
Browse files

Really fixing extensionless file support

Pieced together a fix using Regex and `File.extname` from http://github.com/vast/rocco

Closes GH-24.
  • Loading branch information...
1 parent 515966d commit ba93d23634b82b0084dcecb3d5d77ea1761a2df4 @vast vast committed with mikewest Oct 24, 2010
Showing with 6 additions and 5 deletions.
  1. +1 −1 bin/rocco
  2. +3 −3 lib/rocco/layout.rb
  3. +2 −1 lib/rocco/tasks.rb
View
2 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) }
View
6 lib/rocco/layout.rb
@@ -38,9 +38,9 @@ def sources?
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
View
3 lib/rocco/tasks.rb
@@ -70,7 +70,7 @@ def initialize(task_name, dest='docs/', sources='lib/**/*.rb', options={})
# 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 @@ def define_file_task(source_file, dest_file)
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

0 comments on commit ba93d23

Please sign in to comment.
Something went wrong with that request. Please try again.