Class: Deliver::HtmlGenerator

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

Instance Method Summary collapse

Instance Method Details

#render(options, screenshots, export_path = nil) ⇒ Object

Renders all data available to quickly see if everything was correctly generated.

Parameters:

  • export_path (String) (defaults to: nil)

    The path to a folder where the resulting HTML file should be stored.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/deliver/html_generator.rb', line 30

def render(options, screenshots, export_path = nil)
  lib_path = Helper.gem_path('deliver')

  @screenshots = screenshots || []
  @options = options

  @app_name = (options[:name]['en-US'] || options[:name].values.first) if options[:name]
  @app_name ||= options[:app].name

  @languages = options[:description].keys if options[:description]
  @languages ||= options[:app].latest_version.description.languages

  html_path = File.join(lib_path, "lib/assets/summary.html.erb")
  html = ERB.new(File.read(html_path)).result(binding) # http://www.rrn.dk/rubys-erb-templating-system

  export_path = File.join(export_path, "Preview.html")
  File.write(export_path, html)

  return export_path
end

#run(options, screenshots) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/deliver/html_generator.rb', line 3

def run(options, screenshots)
  begin
    html_path = self.render(options, screenshots, '.')
  rescue => ex
    Helper.log.error ex.inspect
    Helper.log.error ex.backtrace.join("\n")
    okay = agree("Could not render HTML preview. Do you still want to continue? (y/n)".red, true)
    return if okay
    raise "Could not render HTML page"
  end
  puts "----------------------------------------------------------------------------"
  puts "Verifying the upload via the HTML file can be disabled by either adding"
  puts "`force true` to your Deliverfile or using `deliver --force`"
  puts "----------------------------------------------------------------------------"

  system("open '#{html_path}'")
  okay = agree("Does the Preview on path '#{html_path}' look okay for you? (y/n)", true)

  if okay
    puts "HTML file confirmed...".green # print this to give feedback to the user immediately
  else
    raise "Did not upload the metadata, because the HTML file was rejected by the user".yellow
  end
end