Sha256: 692ceebdbd26bfad6534e1d9fad2f22dfe2b2703aae6525f7e70f8ae6a0b45ec
Contents?: true
Size: 1.83 KB
Versions: 3
Compression:
Stored size: 1.83 KB
Contents
#!/usr/bin/env ruby # frozen_string_literal: true # # Copyright (c) 2018-present, Blue Marble Payroll, LLC # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. # require 'bundler/setup' require 'proforma' require 'fileutils' require 'yaml' require 'pry' def read_yaml(filename) YAML.safe_load(read(filename)) end def read(filename) File.open(filename, 'r:bom|utf-8').read end jobs_dir = File.join('tmp', 'jobs') output_dir = File.join('tmp', 'jobs_output') jobs = Dir[File.join(jobs_dir, '*.yml')] if jobs.empty? puts "No jobs detected in the path: #{jobs_dir}" puts '--------------------------------------------------------------' puts "To use, place YAML files into #{jobs_dir} directory." puts 'You can find example YAML files in: spec/fixtures/snapshots' puts '--------------------------------------------------------------' exit end jobs.each do |job| job_name = File.basename(job, File.extname(job)) puts "Rendering: #{job_name} (#{job})" contents = read_yaml(job) data = contents['data'] template = contents['template'] evaluator = contents['evaluator'] || Proforma::HashEvaluator.new renderer = contents['renderer'] || Proforma::PlainTextRenderer.new job_output_dir = File.join(output_dir, job_name) FileUtils.mkdir_p(job_output_dir) outputs = Proforma.render( data, template, evaluator: evaluator, renderer: renderer ) outputs.each_with_index do |output, index| name_without_extension = [ index.to_s, output.title.to_s ].reject(&:empty?).join('.') filename = "#{name_without_extension}#{output.extension}" IO.write(File.join(job_output_dir, filename), output.contents) end puts "Done Rendering: #{job} (output can be found in: #{job_output_dir})" end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
proforma-1.0.2 | bin/render |
proforma-1.0.1 | bin/render |
proforma-1.0.0 | bin/render |