Class: Provideous::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/provideous.rb

Instance Method Summary collapse

Instance Method Details

#cd_to_projectObject



34
35
36
# File 'lib/provideous.rb', line 34

def cd_to_project
  FileUtils.cd @options[:project]
end

#clean_up_old_videoObject



51
52
53
# File 'lib/provideous.rb', line 51

def clean_up_old_video
  FileUtils.rm @options[:vid_file]
end

#compile_erb_templatesObject



61
62
63
64
65
66
67
68
69
# File 'lib/provideous.rb', line 61

def compile_erb_templates
  title = @options[:project]
  video = @web
  poster = @poster
  template_file = File.join(File.dirname(File.expand_path(__FILE__)), "templates/index.html.erb")
  template = ""
  File.open( template_file, 'r') {|f| template = ERB.new(f.read()) }
  File.open( "index.html", 'w') {|f| f.write(template.result(binding) )}
end

#compress_videoObject



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/provideous.rb', line 38

def compress_video
  if @options[:skip] != true
    puts "Using 'videously' to compress and normalize file"
    file = @options[:vid_file]
    @web = File.basename( file, ".*")
    @web = "web_#{@web}.mp4"
    system "videously #{file} #{@web}"
    clean_up_old_video
  else 
    @web = @options[:vid_file]
  end
end

#copy_filesObject



71
72
73
74
# File 'lib/provideous.rb', line 71

def copy_files
  assets_dir = File.join(File.dirname(File.expand_path(__FILE__)), "assets")
  FileUtils.cp_r "#{assets_dir}/.", "." 
end

#copy_videoObject



26
27
28
29
30
31
32
# File 'lib/provideous.rb', line 26

def copy_video
  vid_file = File.new( @options[:vid_file] )
  if (File.file? vid_file)
    filename = File.basename @options[:vid_file]
    FileUtils.cp @options[:vid_file], "#{@options[:project]}/#{filename}"
  end
end

#create_posterObject



55
56
57
58
59
# File 'lib/provideous.rb', line 55

def create_poster
  @poster = File.basename( @web, ".*")
  @poster = "#{@poster}.jpg"
  `ffmpeg -ss 00:00:01.01 -i #{@web} -y -f image2 -vcodec mjpeg -vframes 1 -loglevel panic #{@poster}`
end

#create_project(options) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/provideous.rb', line 9

def create_project options
  @options = options
  puts "Creating project #{options[:project]}"
  make_dir
  copy_video
  cd_to_project
  compress_video
  create_poster
  compile_erb_templates
  copy_files
  open_file
end

#make_dirObject



22
23
24
# File 'lib/provideous.rb', line 22

def make_dir
  FileUtils.mkdir @options[:project]
end

#open_fileObject



76
77
78
# File 'lib/provideous.rb', line 76

def open_file
  `open index.html`
end


80
81
82
83
84
85
86
87
88
89
90
# File 'lib/provideous.rb', line 80

def print_usage
  puts "Usage:"
  puts "===================================="
  puts "** Create a new project **"
  puts "===================================="
  puts ""
  puts "    provideous project_name vid_file"
  puts ""
  puts ""
  
end