Skip to content

Commit

Permalink
copy all js/css/image files to static dir
Browse files Browse the repository at this point in the history
"showoff static" now produces a real, ready-to-run-everywhere
presentation.
I needed this for two presentations and it really bugged me to fix the
paths manually.
  • Loading branch information
badboy committed Dec 15, 2010
1 parent 2bb8155 commit 89d5994
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions lib/showoff.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def update_image_paths(path, slide, static=false)
paths.pop
path = paths.join('/')
replacement_prefix = static ?
%(img src="file://#{options.pres_dir}/#{path}) :
%(img src="./file/#{path}) :
%(img src="/image/#{path})
slide.gsub(/img src=\"(.*?)\"/) do |s|
img_path = File.join(path, $1)
Expand Down Expand Up @@ -237,7 +237,7 @@ def index(static=false)
if static
@title = ShowOffUtils.showoff_title
@slides = get_slides_html(static)
@asset_path = "."
@asset_path = "./"
end
erb :index
end
Expand Down Expand Up @@ -317,7 +317,7 @@ def self.do_static(what)
else
out = "#{path}/#{name}/static"
# First make a directory
FileUtils.makedirs("#{out}")
FileUtils.makedirs(out)
# Then write the html
file = File.new("#{out}/index.html", "w")
file.puts(data)
Expand All @@ -334,6 +334,23 @@ def self.do_static(what)
next unless File.directory?(subpath) || base.match(/\.(css|js)$/)
FileUtils.copy_entry(subpath, "#{out}/#{base}")
}

# Set up file dir
file_dir = File.join(out, 'file')
FileUtils.makedirs(file_dir)
pres_dir = showoff.options.pres_dir

# ..., copy all user-defined styles and javascript files
Dir.glob("#{pres_dir}/*.{css,js}").each { |path|
FileUtils.copy(path, File.join(file_dir, File.basename(path)))
}

# ... and copy all needed image files
data.scan(/img src=\".\/file\/(.*?)\"/).flatten.each do |path|
dir = File.dirname(path)
FileUtils.makedirs(File.join(file_dir, dir))
FileUtils.copy(File.join(pres_dir, path), File.join(file_dir, path))
end
end
end

Expand Down

0 comments on commit 89d5994

Please sign in to comment.