class Kitchen::Oven
A class for baking documents according to the instructions in recipes
Public Class Methods
bake(input_file:, recipes:, output_file:, config_file: nil)
click to toggle source
Bakes an input file using a recipe to produce an output file
@param input_file [String] the path to the input file @param config_file [String] the path to the configuration file @param recipes [Array<Recipe>] an array of recipes with which to bake the document @param output_file [String] the path to the output file
# File lib/kitchen/oven.rb, line 15 def self.bake(input_file:, recipes:, output_file:, config_file: nil) profile = BakeProfile.new profile.started! nokogiri_doc = File.open(input_file) do |f| profile.opened! Nokogiri::XML(f).tap { profile.parsed! } end config = config_file.nil? ? nil : Config.new_from_file(File.open(config_file)) doc = Kitchen::Document.new( nokogiri_document: nokogiri_doc, config: config ) I18n.locale = doc.locale [recipes].flatten.each do |recipe| recipe.document = doc recipe.bake end profile.baked! File.open(output_file, 'w') do |f| f.write doc.to_xhtml(indent: 2, encoding: doc.encoding || 'utf-8') end profile.written! Nokogiri::XML.print_profile_data if ENV['PROFILE'] && !ENV['TESTING'] profile end