Sha256: d3608bc040ee8e2fe64afaf5f67e802d78849e7fd92949baac770ec6859fe183

Contents?: true

Size: 1.02 KB

Versions: 95

Compression:

Stored size: 1.02 KB

Contents

class KuberKit::Preprocessing::FilePreprocessor
  include KuberKit::Import[
    "preprocessing.text_preprocessor",
    "shell.bash_commands"
  ]

  PreprocessingError = Class.new(KuberKit::Error)

  def compile(shell, source_path, destination_path: nil, context_helper: nil)
    destination_path ||= source_path

    prepare_destination_dir(shell, destination_path)

    template = shell.read(source_path)
    content = text_preprocessor.compile(template, context_helper: context_helper)

    is_content_changed = template != content
    if !is_content_changed && source_path == destination_path
      return false
    end

    shell.write(destination_path, content)

    return true
  rescue Exception => e
    message = "#{e.message}\r\n"
    message += e.backtrace.select{|l| l.include?("(erb)") }.join("\r\n")
    raise PreprocessingError, "Error while processing template #{source_path}.\r\n#{message}"
  end

  def prepare_destination_dir(shell, destination_path)
    bash_commands.mkdir_p(shell, File.dirname(destination_path))
  end
end

Version data entries

95 entries across 95 versions & 1 rubygems

Version Path
kuber_kit-1.3.8 lib/kuber_kit/preprocessing/file_preprocessor.rb
kuber_kit-1.3.7 lib/kuber_kit/preprocessing/file_preprocessor.rb
kuber_kit-1.1.8 lib/kuber_kit/preprocessing/file_preprocessor.rb
kuber_kit-1.3.6 lib/kuber_kit/preprocessing/file_preprocessor.rb
kuber_kit-1.1.7 lib/kuber_kit/preprocessing/file_preprocessor.rb
kuber_kit-1.3.5 lib/kuber_kit/preprocessing/file_preprocessor.rb
kuber_kit-1.3.4 lib/kuber_kit/preprocessing/file_preprocessor.rb
kuber_kit-1.1.6 lib/kuber_kit/preprocessing/file_preprocessor.rb
kuber_kit-1.3.3 lib/kuber_kit/preprocessing/file_preprocessor.rb
kuber_kit-1.3.2 lib/kuber_kit/preprocessing/file_preprocessor.rb
kuber_kit-1.1.5 lib/kuber_kit/preprocessing/file_preprocessor.rb
kuber_kit-1.3.1 lib/kuber_kit/preprocessing/file_preprocessor.rb
kuber_kit-1.3.0 lib/kuber_kit/preprocessing/file_preprocessor.rb
kuber_kit-1.1.4 lib/kuber_kit/preprocessing/file_preprocessor.rb
kuber_kit-1.2.7 lib/kuber_kit/preprocessing/file_preprocessor.rb
kuber_kit-1.2.6 lib/kuber_kit/preprocessing/file_preprocessor.rb
kuber_kit-1.2.5 lib/kuber_kit/preprocessing/file_preprocessor.rb
kuber_kit-1.2.4 lib/kuber_kit/preprocessing/file_preprocessor.rb
kuber_kit-1.2.2 lib/kuber_kit/preprocessing/file_preprocessor.rb
kuber_kit-1.1.2 lib/kuber_kit/preprocessing/file_preprocessor.rb