forked from binford2k/showoff
-
Notifications
You must be signed in to change notification settings - Fork 1
/
import_images.rb
executable file
·46 lines (39 loc) · 1.01 KB
/
import_images.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#! /usr/bin/env ruby
# this script will take a directory full of images and make a showoff
# presentation section out of them
# usage: ./import_images.rb preso section_name /path/to/images
require 'fileutils'
require 'pp'
if ARGV.size < 3
puts 'usage: ./import_images.rb preso section_name /path/to/images'
exit
end
preso = ARGV[0]
section = ARGV[1]
path = ARGV[2]
# look for showoff file
if File.exists?(preso)
Dir.chdir(preso) do
# make the new directory
Dir.mkdir(section) rescue nil
Dir.chdir(section) do
Dir.mkdir('img') rescue nil
# copy all the images into img dir
FileUtils.cp_r(path, "img")
files = Dir.glob("img/**/*")
# create the slides file
filen = section.split('/').last
filenm = "#{filen}.md"
File.open(filenm, 'w+') do |f|
files.each do |img|
if File.file?(img)
f.puts "!SLIDE center"
f.puts "![#{img}](#{img})"
f.puts
end
end
end
pp files
end
end
end