Sha256: 273b4738d3e5226f8ef5f53344ed042aa38fb26552d0978f894f7a55b7ad422d

Contents?: true

Size: 1.85 KB

Versions: 6

Compression:

Stored size: 1.85 KB

Contents

module Deliver
  class HtmlGenerator
    def run(options, screenshots)
      begin
        html_path = self.render(options, screenshots, '.')
      rescue => ex
        UI.error(ex.inspect)
        UI.error(ex.backtrace.join("\n"))
        okay = UI.input("Could not render HTML preview. Do you still want to continue?")
        return if okay
        UI.crash!("Could not render HTML page")
      end
      UI.important("Verifying the upload via the HTML file can be disabled by either adding")
      UI.important("`force true` to your Deliverfile or using `deliver --force`")

      system("open '#{html_path}'")
      okay = UI.confirm("Does the Preview on path '#{html_path}' look okay for you?")

      if okay
        UI.success("HTML file confirmed...") # print this to give feedback to the user immediately
      else
        UI.user_error!("Did not upload the metadata, because the HTML file was rejected by the user")
      end
    end

    # Renders all data available to quickly see if everything was correctly generated.
    # @param export_path (String) The path to a folder where the resulting HTML file should be stored.
    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
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
deliver-1.10.5 lib/deliver/html_generator.rb
deliver-1.10.4 lib/deliver/html_generator.rb
deliver-1.10.3 lib/deliver/html_generator.rb
deliver-1.10.2 lib/deliver/html_generator.rb
deliver-1.10.1 lib/deliver/html_generator.rb
deliver-1.10.0 lib/deliver/html_generator.rb