Class: Krane::RenderTask

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

Overview

Render templates

Instance Method Summary collapse

Constructor Details

#initialize(logger: nil, current_sha:, filenames: [], bindings:, partials_dir: nil) ⇒ RenderTask

Initializes the render task



18
19
20
21
22
23
24
# File 'lib/krane/render_task.rb', line 18

def initialize(logger: nil, current_sha:, filenames: [], bindings:, partials_dir: nil)
  @logger = logger || Krane::FormattedLogger.build
  @filenames = filenames.map { |path| File.expand_path(path) }
  @bindings = bindings
  @current_sha = current_sha
  @partials_dir = partials_dir
end

Instance Method Details

#run(**args) ⇒ Boolean

Runs the task, returning a boolean representing success or failure



29
30
31
32
33
34
# File 'lib/krane/render_task.rb', line 29

def run(**args)
  run!(**args)
  true
rescue Krane::FatalDeploymentError
  false
end

#run!(stream:) ⇒ nil

Runs the task, raising exceptions in case of issues



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/krane/render_task.rb', line 41

def run!(stream:)
  @logger.reset
  @logger.phase_heading("Initializing render task")

  ts = TemplateSets.from_dirs_and_files(paths: @filenames, logger: @logger)

  validate_configuration(ts)
  count = render_templates(stream, ts)

  @logger.summary.add_action("Successfully rendered #{count} template(s)")
  @logger.print_summary(:success)
rescue Krane::FatalDeploymentError
  @logger.print_summary(:failure)
  raise
end