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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/nopoint/commands/build.rb', line 13
def self.build(options)
config = YAML.safe_load_file('config.yml')
template = config['template']
chapters = []
source = []
destination = 'public'
config['chapters'].each_with_index do |chapter, index|
name = File.join(Dir.pwd, "slides/#{chapter}")
chapters.push Nopoint::Chapter.new(index, name)
end
if File.directory? destination
FileUtils.rm_rf(Dir.glob("#{destination}/*"))
else
FileUtils.mkdir(destination)
end
FileUtils.mkdir destination + '/assets'
FileUtils.mkdir destination + '/slides'
FileUtils.mkdir destination + '/images'
FileUtils.cp 'vendor/index.html', destination
FileUtils.cp Dir.glob('vendor/*.js'), destination + '/assets'
FileUtils.cp_r Dir.glob('images/*'), destination + '/images' if File.directory? 'images'
FileUtils.cp Dir.glob("templates/#{template}/*.{css,js}"), destination + '/assets'
@slide_index = 0
@slide_max = chapters.inject(0) {|sum, ch| sum + ch.slides.count}
@chapter_max = chapters.count
chapters.each_with_index do |chapter, index|
@chapter_index = index
if chapter.data.has_key? 'title'
@title = chapter.data['title']
else
@title = ''
end
chapter.slides.each do |slide|
path = "public/slides/#{@slide_index}.html"
file = File.new(path, 'w')
@content = slide.content
erb = ERB.new(File.read("templates/#{template}/slide.erb"))
file.puts erb.result(binding)
file.close
@slide_index += 1
end
end
end
|